From 690cc1ef6d1abce09b84bd6e157037c479aaa402 Mon Sep 17 00:00:00 2001
From: jordan <jordan@le-filament.com>
Date: Tue, 25 Jan 2022 15:32:28 +0100
Subject: [PATCH] [fix] date due depends of quarter when create regul invoices

---
 wizard/scop_cotisation_cg_regul.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/wizard/scop_cotisation_cg_regul.py b/wizard/scop_cotisation_cg_regul.py
index 614aff5..5f0d6d7 100644
--- a/wizard/scop_cotisation_cg_regul.py
+++ b/wizard/scop_cotisation_cg_regul.py
@@ -207,6 +207,12 @@ class ScopCotisationRegul(models.TransientModel):
 
             if type_invoice:
                 for i in range(0, bordereau_id.nb_quarter):
+
+                    if self.date_regul < quarters[i]:
+                        date_due = quarters[i]
+                    else:
+                        date_due = self.date_regul
+
                     refund = self.env['account.invoice'].create({
                         'partner_id': partner_id.id,
                         'journal_id': cotiz_type.get(type_cotiz)[2].id,
@@ -224,7 +230,7 @@ class ScopCotisationRegul(models.TransientModel):
                         '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': quarters[bordereau_id.nb_quarter-1],
+                        'date_due': date_due,
                         'cotiz_quarter': i+1,
                     })
                     self.env['account.invoice.line'].create({
-- 
GitLab