diff --git a/wizard/scop_cotisation_cg_regul.py b/wizard/scop_cotisation_cg_regul.py index de2a36e1ed4e5949e9e3967f9bec22ef3a46ac09..3ccf0aed98a070d044a952e019710b122039cdbe 100644 --- a/wizard/scop_cotisation_cg_regul.py +++ b/wizard/scop_cotisation_cg_regul.py @@ -74,7 +74,7 @@ class ScopCotisationRegul(models.TransientModel): # ------------------------------------------------------ @api.constrains("date_regul") def _check_date_regul(self): - last_date = max(self.bordereau_id.invoice_ids.mapped("date_invoice")) + last_date = max(self.bordereau_id.invoice_ids.mapped("invoice_date")) if self.date_regul > fields.Date.today() or self.date_regul < last_date: raise ValidationError( _( @@ -111,7 +111,7 @@ class ScopCotisationRegul(models.TransientModel): detail += "</table>" payments = list( map( - lambda i: True if i.payment_move_line_ids else False, + lambda i: True if i.move_line_payment_ids else False, bordereau_id.invoice_ids, ) ) @@ -227,7 +227,7 @@ class ScopCotisationRegul(models.TransientModel): refund_amount_total *= -1 elif refund_amount_total > 0: type_invoice = "out_refund" - refund_amount = refund_amount_total / bordereau_id.nb_quarter + refund_amount = refund_amount_total / int(bordereau_id.nb_quarter) if type_invoice: for i in range(0, int(bordereau_id.nb_quarter)): @@ -237,38 +237,42 @@ class ScopCotisationRegul(models.TransientModel): else: date_due = self.date_regul - refund = self.env["account.invoice"].create( + self.env["account.move"].create( { "partner_id": partner_id.id, "journal_id": cotiz_type.get(type_cotiz)[2].id, - "type": type_invoice, - "date_invoice": self.date_regul, + "move_type": type_invoice, + "invoice_date": self.date_regul, "date": self.date_regul, "state": "draft", - "number": False, - "origin": bordereau_id.name, - "name": self.comment, + "invoice_origin": bordereau_id.name, + "ref": self.comment, "bordereau_id": bordereau_id.id, "is_contribution": True, "year": bordereau_id.year, "liasse_fiscale_id": bordereau_id.liasse_fiscale_id.id, "type_contribution_id": type_cotiz, "payment_mode_id": bordereau_id.payment_mode_id.id, - "date_due": date_due, - "cotiz_quarter": i + 1, - } - ) - self.env["account.invoice.line"].create( - { - "name": self.comment - + " - " - + str(i + 1) - + "/" - + bordereau_id.nb_quarter, - "invoice_id": refund.id, - "product_id": product.id, - "account_id": product.property_account_income_id.id, - "price_unit": refund_amount, + "invoice_date_due": date_due, + "cotiz_quarter": str(i + 1), + "invoice_line_ids": [ + ( + 0, + None, + { + "product_id": product.id, + "account_id": product.property_account_income_id.id, + "tax_ids": [(6, 0, product.taxes_id.ids)], + "name": self.comment + + " - " + + str(i + 1) + + "/" + + bordereau_id.nb_quarter, + "price_unit": refund_amount, + "price_subtotal": refund_amount, + }, + ), + ], } ) bordereau_id.update({"liasse_fiscale_id": self.liasse_fiscale_new_id.id})