From 39ebf3f87c3a9bd6e0d0cbcc729419b78773fb45 Mon Sep 17 00:00:00 2001
From: benjamin <benjamin@le-filament.com>
Date: Thu, 23 Jun 2022 15:21:45 +0200
Subject: [PATCH] [fix] error refund creation

---
 wizard/scop_bordereau_refund_wizard.py | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/wizard/scop_bordereau_refund_wizard.py b/wizard/scop_bordereau_refund_wizard.py
index 9c7a518..1fbd0fb 100644
--- a/wizard/scop_bordereau_refund_wizard.py
+++ b/wizard/scop_bordereau_refund_wizard.py
@@ -177,7 +177,7 @@ class ScopBordereauRefundWizard(models.TransientModel):
         for quarter_id in self.quarter_ids:
             date_due = self.bordereau_id.invoice_ids.filtered(
                 lambda i: i.cotiz_quarter == str(quarter_id.quarter) and i.move_type == "out_invoice")[0].invoice_date_due
-            refund = self.env["account.move"].create(
+            self.env["account.move"].create(
                 {
                     "partner_id": partner_id.id,
                     "journal_id": cotiz_type.get(int(self.type_cotiz))[1].id,
@@ -194,17 +194,19 @@ class ScopBordereauRefundWizard(models.TransientModel):
                     "type_contribution_id": self.type_cotiz,
                     "payment_mode_id": bordereau_id.payment_mode_id.id,
                     "invoice_date_due": date_due,
-                }
-            )
-            self.env["account.move.line"].create(
-                {
-                    "name": self.comment,
-                    "move_id": refund.id,
-                    "product_id": product.id,
-                    "account_id": product.property_account_income_id.id,
-                    "quantity": 1,
-                    "price_unit": self.amount_refund,
-                    "price_subtotal": self.amount_refund,
+                    "invoice_line_ids": [
+                        (
+                            0,
+                            None,
+                            {
+                                "product_id": product.id,
+                                "account_id": product.property_account_income_id.id,
+                                "name": self.comment,
+                                "price_unit": self.amount_refund,
+                                "price_subtotal": self.amount_refund,
+                            },
+                        ),
+                    ],
                 }
             )
 
-- 
GitLab