diff --git a/models/scop_cotisation_cg_exo.py b/models/scop_cotisation_cg_exo.py index 73b9b8bdd2104fa006149d719e0a90f591fc85a8..da3e60f4567f25b7b6fdf0cc94eee4c0de8458a7 100644 --- a/models/scop_cotisation_cg_exo.py +++ b/models/scop_cotisation_cg_exo.py @@ -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() @@ -499,7 +502,7 @@ class ScopCotisationExo(models.Model): and i.move_type == "out_invoice" )[0].invoice_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,