diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c6434bfc2274c73d98dbf62b6de9baccdc353ce..6994ef32623bffec84fa06e1bd08ab9fb36dbc91 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,6 +49,7 @@ repos: rev: 20.8b1 hooks: - id: black + additional_dependencies: ["click==8.0.4"] - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.1.2 hooks: diff --git a/models/scop_partner_staff.py b/models/scop_partner_staff.py index 92aa528f63c47a9dd626a7602018f7ee69d8933f..b00bc8a7dfaa4bbef7ed8c8b742e7240012095bf 100644 --- a/models/scop_partner_staff.py +++ b/models/scop_partner_staff.py @@ -139,47 +139,67 @@ class ScopPartnerStaff(models.Model): # ------------------------------------------------------ # Contrains # ------------------------------------------------------ - @api.constrains("staff_count", "staff_shareholder_count", "staff_average") + @api.constrains( + "cooperative_form_id", + "type_entry", + "staff_count", + "staff_shareholder_count", + "staff_average", + ) def _check_staff(self): """ - Interdit de créer une ligne à 0 sauf lorsque - cette ligne vient de la liste ministère - ou si ligne associés / ETP pour les SCIC - ou si ligne ETP pour les 'tracked naf' + Règles spécifiques pour les effectifs """ - if self.type_entry not in ( - "questionnaire", - "questionnaire_inscription", - ): - if ( - self.cooperative_form_id.id - == self.env.ref("cgscop_partner.form_scic").id - ): - if self.staff_count == 0: + scic = self.env.ref("cgscop_partner.form_scic").id + scop = self.env.ref("cgscop_partner.form_scop").id + + def check_staff_shareholder(): + # Effectif total >= effectif sociétaires + if self.staff_shareholder_count > 0: + if not self.staff_count >= self.staff_shareholder_count: raise ValidationError( _( - "La colonne Effectif (EF) doit être renseignée" - " et supérieurs à 0." + "L'effectif total doit être supérieur ou égal au " + "nombre de sociétaires salariés" ) ) - elif self.is_partner_in_tracked_naf: - if self.staff_count == 0 or self.staff_shareholder_count == 0: + + def check_staff_average(): + if self.staff_average > 0: + if not self.staff_count >= self.staff_average: raise ValidationError( _( - "Les colonnes Effectif (EF) et Nb Sociétaires Salarié" - " doivent être renseignés et supérieurs à 0." + "L'effectif total doit être supérieur ou égal au " + "nombre d'équivalent temps plein" ) ) - else: - if ( - self.staff_shareholder_count == 0 - or self.cooperative_form_id == 0 - or self.staff_average == 0 - ): + + # Les règles ne s'appliquent pas pour les entrées LM / Questionnaire + if self.type_entry not in ("questionnaire", "questionnaire_inscription"): + # Règles pour les SCIC + if self.cooperative_form_id.id == scic: + check_staff_shareholder() + check_staff_average() + # Règles pour les SCOP + elif self.cooperative_form_id.id == scop: + # Effectif total non nul + if self.staff_count == 0: + raise ValidationError( + _( + "L'effectif total doit être supérieur ou égal à 0 " + "pour cette copérative de type SCOP" + ) + ) + check_staff_shareholder() + check_staff_average() + + # Règles sprécifiques pour les NAF suivis + if self.is_partner_in_tracked_naf: + if self.staff_average == 0: raise ValidationError( _( - "Tous les effectifs doivent" - " être renseignés et supérieurs à 0." + "Le nombre d'équivalent temps plein doit être " + "renseigné pour cette coopérative" ) ) diff --git a/views/res_partner.xml b/views/res_partner.xml index ff3b19dcfad42bb4d2d557bb73137ca456596d35..253e567fc2405130ac3a4b6ec3f555ff20941f67 100644 --- a/views/res_partner.xml +++ b/views/res_partner.xml @@ -1555,7 +1555,7 @@ /> <field name="staff_shareholder_count" - attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription'))], 'required':[('cooperative_form_id', '!=', %(cgscop_partner.form_scic)d)]}" + attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription'))]}" /> <field name="staff_shareholder_total" @@ -1563,7 +1563,7 @@ /> <field name="staff_average" - attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription'))], 'required':[('is_partner_in_tracked_naf', '!=', True), ('cooperative_form_id', '!=', %(cgscop_partner.form_scic)d)]}" + attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription'))], 'required':[('is_partner_in_tracked_naf', '=', True)]}" /> <field name="comment" /> <field name="user_id" readonly="1" /> diff --git a/views/scop_partner_staff.xml b/views/scop_partner_staff.xml index 2b4b6fea10f6adc00102aa5cdcb91be5c5535f0e..1c2afd3acf297ede573b3e887b04a3d8b8831621 100644 --- a/views/scop_partner_staff.xml +++ b/views/scop_partner_staff.xml @@ -37,7 +37,7 @@ /> <field name="staff_shareholder_count" - attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription'))], 'required':[('cooperative_form_id', '!=', %(cgscop_partner.form_scic)d)]}" + attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription'))]}" /> <field name="staff_shareholder_total" @@ -45,7 +45,7 @@ /> <field name="staff_average" - attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription'))], 'required':[('is_partner_in_tracked_naf', '!=', True)]}" + attrs="{'readonly':[('type_entry','in',('questionnaire', 'questionnaire_inscription'))], 'required':[('is_partner_in_tracked_naf', '=', True)]}" /> </group> <group name="staff_stats">