From c8c10a2f72ea99f3d0df1d592473c8b1a2f256fd Mon Sep 17 00:00:00 2001
From: jordan <jordan@le-filament.com>
Date: Tue, 2 Mar 2021 18:57:39 +0100
Subject: [PATCH] [update] add journal and account in config cotiz cg

---
 models/scop_cotisation.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/models/scop_cotisation.py b/models/scop_cotisation.py
index a3ca278..d1b34e6 100644
--- a/models/scop_cotisation.py
+++ b/models/scop_cotisation.py
@@ -70,7 +70,8 @@ class ScopCotisation(models.AbstractModel):
     # Global functions
     # ------------------------------------------------------
     def create_contribution(self, product, partner, type_contribution,
-                            liasse=None, amount=0, date=False):
+                            liasse=None, amount=0, date=False,
+                            journal_id=False, account_id=False):
         Invoice = self.env['account.invoice']
         InvoiceLine = self.env['account.invoice.line']
 
@@ -79,8 +80,12 @@ class ScopCotisation(models.AbstractModel):
             ('year', '=', self.year),
             ('type_contribution_id', '=', type_contribution)
         ])
-        date_invoice = date if date else self.date_cotisation
         if not exisiting_invoice:
+            date_invoice = date if date else self.date_cotisation
+            journal_id = self.company_id.contribution_journal_id \
+                if not journal_id else journal_id
+            account_id = partner.property_account_receivable_id \
+                if not account_id else account_id
             member_invoice = Invoice.create({
                 'partner_id': partner.id,
                 'liasse_fiscale_id': liasse.id,
@@ -88,9 +93,9 @@ class ScopCotisation(models.AbstractModel):
                 'year': self.year,
                 'is_contribution': True,
                 'type_contribution_id': type_contribution,
-                'journal_id': self.company_id.contribution_journal_id.id,
+                'journal_id': journal_id.id,
                 'state': 'draft',
-                'account_id': partner.property_account_receivable_id.id,
+                'account_id': account_id.id,
                 'payment_term_id': self.payment_term_id.id,
                 'payment_mode_id': partner.customer_payment_mode_id.id,
                 'date_invoice': date_invoice,
-- 
GitLab