Bonjour,
Voici du code :
Model cible :
Code Python : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 class SchoolYears(models.Model): _name = "ecole.partner.school.years" _rec_name = "school_years" # POUR ASSIGNER PAR DEFAUT UN AUTRE CHAMP AUTRE QUE NAME _order = 'id desc' school_years = fields.Char(string='School year', required=True, copy=False) year_begin_date = fields.Date(string='Start date', required=True, copy=False) year_end_date = fields.Date(string='End date', required=True, copy=False) default_school_year = fields.Boolean(string='Current school year', copy=False) period_school_year = fields.Boolean(string='Registration period', copy=False) active = fields.Boolean(default=True)
Champs ciblé : -> year_begin_date = fields.Date(string='Start date', required=True, copy=False)
Modèle où je souhaite accéder aux champs :
Code Python : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 class ResPartnerSchool(models.Model): _name = 'ecole.partner.school' _order = 'id desc' @api.multi def _get_begin_date(self): domain = [('period_school_year', '=', False), ('default_school_year', '=', True)] begin_date_id = self.env['ecole.partner.school.years'].search(domain, limit=1).year_begin_date begin_date = fields.Date.from_string(begin_date_id) date_j = datetime.date.today() if begin_date_id: if begin_date > date_j: return begin_date_id else: return date_j ... school_year_id = fields.Many2one(string='Period', ondelete='SET NULL', comodel_name="ecole.partner.school.years", default=_get_period_year) school_registration = fields.Date(string='Beginning', copy=False, default=_get_begin_date) ...
Voici la vue :
Je souhaite récupérer la bonne date de début d'année scolaire liée à school_years qui est de type char et qui est un Many2one dans le modèle ecole.partner.school.
Je sais qu'il y a plusieurs façon de faire, notamment avec un related. Sauf que j'ai une fonction qui me permet de récupérer la date du jour en date de début d'année scolaire lorsqu'on est en plein dans une période scolaire.
Actuellement ma fonction est écrit en "dure" -> c'est ce qu'on voie dans la variable "domain". Et je ne souhaite pas utiliser related dans mon champs school_registration.
Avez vous une idée pour récupérer la bonne date de début quand on choisi une année scolaire ?
Merci
Partager