diff --git a/models/res_partner.py b/models/res_partner.py index 6b61de63402d8643ecf39fee6615cbee3c328ffc..8ea0851ca25931ca6719cf48375e3e505a355aa2 100644 --- a/models/res_partner.py +++ b/models/res_partner.py @@ -10,6 +10,5 @@ class ResPartner(models.Model): exo_ids = fields.One2many( comodel_name="scop.cotisation.cg.exo", inverse_name="partner_id", - domain=[("state", "=", "done")], string="Exonérations", ) diff --git a/models/scop_cotisation_cg_exo.py b/models/scop_cotisation_cg_exo.py index 73b9b8bdd2104fa006149d719e0a90f591fc85a8..f6cd070282ae0aac379349aa47099bf4fd4301f9 100644 --- a/models/scop_cotisation_cg_exo.py +++ b/models/scop_cotisation_cg_exo.py @@ -109,7 +109,7 @@ class ScopCotisationExo(models.Model): amount_quarter = fields.Float("Montant souhaité pour les échéances") percent_quarter = fields.Integer("Réduction appliquée aux échéances") date_exo_ok = fields.Date("Date Acceptation Exo") - head_office_comment = fields.Text("Commentaire du bureau") + head_office_comment = fields.Text("Commentaire") note = fields.Text("Notes internes") instance_id = fields.Many2one(comodel_name="scop.instance", string="Instance") bordereau_ids = fields.Many2many( @@ -265,7 +265,19 @@ class ScopCotisationExo(models.Model): def create_lines(self): self.exo_line_ids.unlink() - contrib_type = self.partner_id.get_partner_contribution_type() + # Get last bdx for prorate calculation + last_bdx = self.env["scop.bordereau"].search( + [ + ("state", "in", ["validated", "paid"]), + ("partner_id", "=", self.partner_id.id), + ], + order="date_cotisation desc", + limit=1, + ) + if last_bdx: + contrib_type = last_bdx.mapped("invoice_ids.type_contribution_id") + else: + contrib_type = self.partner_id.get_partner_contribution_type() # if exo is percent => affects percent to each line if self.type_exo == "percent": @@ -282,15 +294,6 @@ class ScopCotisationExo(models.Model): if self.type_exo == "amount": # if various contribution type => affects prorate amount to each line if len(contrib_type) > 1: - # Get last bdx for prorate calculation - last_bdx = self.env["scop.bordereau"].search( - [ - ("state", "in", ["validated", "paid"]), - ("partner_id", "=", self.partner_id.id), - ], - order="date_cotisation desc", - limit=1, - ) if last_bdx: last_amount = last_bdx.amount_total_cotiz amount_by_type = last_bdx.get_contribution_type() @@ -489,17 +492,21 @@ class ScopCotisationExo(models.Model): ) if exo_amount != 0: - date_refund = ( - bordereau_id.date_cotisation - if bordereau_id.state == "draft" - else self.date_exo_ok - ) - date_due = bordereau_id.invoice_ids.filtered( + if self.date_exo_ok > bordereau_id.date_cotisation: + date_refund = self.date_exo_ok + else: + date_refund = bordereau_id.date_cotisation + + quarter_date_due = bordereau_id.invoice_ids.filtered( lambda i: i.cotiz_quarter == str(quarter) and i.move_type == "out_invoice" )[0].invoice_date_due + if quarter_date_due < self.date_exo_ok: + date_due = self.date_exo_ok + else: + date_due = quarter_date_due # Create refund - refund = bordereau_id.invoice_ids.create( + bordereau_id.invoice_ids.create( { "partner_id": bordereau_id.partner_id.id, "liasse_fiscale_id": bordereau_id.liasse_fiscale_id.id, diff --git a/views/res_partner.xml b/views/res_partner.xml index 38547085a867fc1aa12aa065a3292758b25cff57..18864fb733610a6127af516ee3800a19bb286d90 100644 --- a/views/res_partner.xml +++ b/views/res_partner.xml @@ -18,17 +18,20 @@ <field name="exo_ids" mode="tree,form" readonly="1"> <tree create="false" edit="false" delete="false"> <field name="date_request" /> + <field name="number" /> <field name="source" /> <field name="date_exo_start" /> <field name="date_exo_end" /> <field name="ur_notice" /> <field name="final_notice" /> <field name="date_exo_ok" /> + <field name="head_office_comment" optional="show" /> </tree> <form> <group string="Demande initiale"> <group name="request"> <field name="date_request" /> + <field name="number" /> <field name="source" /> <field name="ur_notice" @@ -53,7 +56,7 @@ <strong><label for="head_office_comment" /></strong> <field name="head_office_comment" - placeholder="Commentaire du bureau" + placeholder="Commentaire" /> </form> </field> diff --git a/views/scop_cotisation_cg_exo.xml b/views/scop_cotisation_cg_exo.xml index 341572402b621f2cf0ed85694472a2b351e8a24e..96919e54652ccaabb2c6db3769c4e88e33ebc24e 100644 --- a/views/scop_cotisation_cg_exo.xml +++ b/views/scop_cotisation_cg_exo.xml @@ -12,6 +12,7 @@ <search string="Exonerations"> <field name="partner_id" options="{'no_create': 1}" /> <field name="name" /> + <field name="number" /> <field name="date_request" /> <separator /> <filter @@ -64,6 +65,7 @@ <tree string="Exonerations"> <field name="date_request" /> <field name="partner_id" /> + <field name="number" optional="show" /> <field name="state" /> <field name="date_exo_start" /> <field name="date_exo_end" />