diff --git a/models/cgscop_form_coop_demande.py b/models/cgscop_form_coop_demande.py index af976a43d67cd61c8638127f9b398916cb3f1ee2..207de99cc3fb4b9d6237fd895bed4df192019e75 100644 --- a/models/cgscop_form_coop_demande.py +++ b/models/cgscop_form_coop_demande.py @@ -104,13 +104,17 @@ class CgscopFormCoopDemande(models.Model): formation_desc = fields.Text( string="Description de la formation", ) - formation_date = fields.Date( - string="Date de la formation", + string="Date formation (1er jour)", default=fields.Date.today(), index=True, tracking=1, ) + formation_date_end = fields.Date( + string="Date formation (dernier jour)", + index=True, + tracking=1, + ) formation_nb_jours = fields.Integer( string="Nombre de jours de formation", ) @@ -216,6 +220,22 @@ class CgscopFormCoopDemande(models.Model): ) ) + @api.constrains("formation_date", "formation_date_end") + def _check_formation_date(self): + """ + Montant accpted <= montant formation + """ + for rec in self: + if rec.formation_date and \ + rec.formation_date_end and \ + rec.formation_date > rec.formation_date_end: + raise exceptions.ValidationError( + _( + "La date de fin de formation doit être supérieure ou égale" + " à la date de début de formation" + ) + ) + # adresse mail valide @api.constrains("contact_mail") def _check_contact_mail(self): diff --git a/models/cgscop_form_coop_demande_collective.py b/models/cgscop_form_coop_demande_collective.py index 4ae6c84b8eda3dbb5fce110bd61cbd9d26d57e30..e8100bb3e1c0a2b69069776e628b2c0b6ee34a68 100644 --- a/models/cgscop_form_coop_demande_collective.py +++ b/models/cgscop_form_coop_demande_collective.py @@ -81,11 +81,16 @@ class CgscopFormCoopDemandeCollective(models.Model): string="Description de la formation", ) formation_date = fields.Date( - string="Date de la formation", + string="Date formation (1er jour)", default=fields.Date.today(), index=True, tracking=1, ) + formation_date_end = fields.Date( + string="Date formation (dernier jour)", + index=True, + tracking=1, + ) formation_nb_jours = fields.Integer( string="Nombre de jours de formation", ) @@ -160,6 +165,25 @@ class CgscopFormCoopDemandeCollective(models.Model): motif_refus = fields.Text(string="Motif du refus", tracking=1) commentaires = fields.Text(string="Commentaires", tracking=1) + # ------------------------------------------------------ + # Constrains + # ------------------------------------------------------ + @api.constrains("formation_date", "formation_date_end") + def _check_formation_date(self): + """ + Montant accpted <= montant formation + """ + for rec in self: + if rec.formation_date and \ + rec.formation_date_end and \ + rec.formation_date > rec.formation_date_end: + raise exceptions.ValidationError( + _( + "La date de fin de formation doit être supérieure ou égale" + " à la date de début de formation" + ) + ) + # ------------------------------------------------------ # Computed fields # ------------------------------------------------------ diff --git a/views/cgscop_form_coop_demande_collective_views.xml b/views/cgscop_form_coop_demande_collective_views.xml index c750006c7cd854eedcf44a6f3d10fd399ac84f5d..4025b8d7a85e7e074aec0289749eaf35dc152683 100644 --- a/views/cgscop_form_coop_demande_collective_views.xml +++ b/views/cgscop_form_coop_demande_collective_views.xml @@ -168,6 +168,10 @@ required="1" attrs="{'readonly': [('etat', 'not in', ('created'))]}" /> + <field + name="formation_date_end" + attrs="{'readonly': [('etat', 'not in', ('created'))]}" + /> <field name="formation_id" options="{'no_open': True, 'no_create': True}" diff --git a/views/cgscop_form_coop_demande_views.xml b/views/cgscop_form_coop_demande_views.xml index 9f73d599f93f55189a994a3c4e513c35586d3066..b9ad48a05317e106e638d2a0a08088e223ac5cfa 100644 --- a/views/cgscop_form_coop_demande_views.xml +++ b/views/cgscop_form_coop_demande_views.xml @@ -213,6 +213,10 @@ required="1" attrs="{'readonly': ['|',('demande_type', 'not in', ('I')),('etat', 'not in', ('created'))]}" /> + <field + name="formation_date_end" + attrs="{'readonly': ['|',('demande_type', 'not in', ('I')),('etat', 'not in', ('created'))]}" + /> <field name="formation_id" options="{'no_open': True, 'no_create': True}"