From e56e190a56dc35b513e6f548393c33958e0b5616 Mon Sep 17 00:00:00 2001
From: jordan <jordan@le-filament.com>
Date: Mon, 3 May 2021 16:11:20 +0200
Subject: [PATCH] =?UTF-8?q?[fix]=20Montant=20rejet=C3=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 models/scop_cotisations_idf.py    |  6 +---
 models/scop_invoice_idf.py        |  1 +
 views/scop_cotisations_idf.xml    |  2 ++
 views/scop_invoice_idf.xml        |  2 ++
 wizard/scop_invoice_idf_wizard.py | 54 +++++++++++++++++--------------
 5 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/models/scop_cotisations_idf.py b/models/scop_cotisations_idf.py
index 699379f..b790ac6 100644
--- a/models/scop_cotisations_idf.py
+++ b/models/scop_cotisations_idf.py
@@ -28,6 +28,7 @@ class ScopCotisationsIDF(models.Model):
     type = fields.Selection([
         ('inv', 'Cotisation'),
         ('refund', 'Avoir'),
+        ('reject', 'Rejet'),
         ('pay', 'Paiment')],
         string='Type', )
     lettrage = fields.Char('Lettrage')
@@ -70,11 +71,6 @@ class ScopCotisationsIDF(models.Model):
     # ------------------------------------------------------
     # Computed fields
     # ------------------------------------------------------
-    # @api.multi
-    # def _compute_currency(self):
-    #     for r in self:
-    #         r.currency_id = r.env
-
     @api.depends('payment_or_refund_ids', 'debit',
                  'payment_or_refund_ids.debit', 'payment_or_refund_ids.debit')
     @api.multi
diff --git a/models/scop_invoice_idf.py b/models/scop_invoice_idf.py
index f48a732..87e3207 100644
--- a/models/scop_invoice_idf.py
+++ b/models/scop_invoice_idf.py
@@ -28,6 +28,7 @@ class ScopinvoiceIDF(models.Model):
     type = fields.Selection([
         ('inv', 'Facture'),
         ('refund', 'Avoir'),
+        ('reject', 'Rejet'),
         ('pay', 'Paiment')],
         string='Type',)
     lettrage = fields.Char('Lettrage')
diff --git a/views/scop_cotisations_idf.xml b/views/scop_cotisations_idf.xml
index e1d8c32..0c6b83a 100644
--- a/views/scop_cotisations_idf.xml
+++ b/views/scop_cotisations_idf.xml
@@ -73,6 +73,7 @@
                                 <field name="currency_id" invisible="1"/>
                                 <field name="credit" widget="monetary" string="Montant" attrs="{'invisible': [('type', '=', 'inv')]}"/>
                                 <field name="debit" widget="monetary" string="Montant" attrs="{'invisible': [('type', '!=', 'inv')]}"/>
+                                <field name="debit" widget="monetary" string="Montant rejeté" attrs="{'invisible': [('type', '!=', 'reject')]}"/>
                                 <field name="amount_residual" widget="monetary"
                                        attrs="{'invisible': [('type', '!=', 'inv')]}"/>
                                 <field name="invoice_id"
@@ -157,6 +158,7 @@
                         <filter name="group_by_partner_id" string="Adhérent" context="{'group_by':'partner_id'}"/>
                         <separator/>
                         <filter string="Date écriture" name="groupby_writing_date" context="{'group_by':'writing_date'}"/>
+                        <filter string="Type" name="groupby_type" context="{'group_by':'type'}"/>
                     </group>
                 </search>
             </field>
diff --git a/views/scop_invoice_idf.xml b/views/scop_invoice_idf.xml
index 2074f36..7418025 100644
--- a/views/scop_invoice_idf.xml
+++ b/views/scop_invoice_idf.xml
@@ -69,6 +69,7 @@
                                 <field name="currency_id" invisible="1"/>
                                 <field name="credit" widget="monetary" string="Montant" attrs="{'invisible': [('type', '=', 'inv')]}"/>
                                 <field name="debit" widget="monetary" string="Montant" attrs="{'invisible': [('type', '!=', 'inv')]}"/>
+                                <field name="debit" widget="monetary" string="Montant rejeté" attrs="{'invisible': [('type', '!=', 'reject')]}"/>
                                 <field name="amount_residual" widget="monetary"
                                        attrs="{'invisible': [('type', '!=', 'inv')]}"/>
                                 <field name="invoice_id"
@@ -149,6 +150,7 @@
                         <filter name="group_by_partner_id" string="Adhérent" context="{'group_by':'partner_id'}"/>
                         <separator/>
                         <filter string="Date écriture" name="groupby_writing_date" context="{'group_by':'writing_date'}"/>
+                        <filter string="Type" name="groupby_type" context="{'group_by':'type'}"/>
                     </group>
                 </search>
             </field>
diff --git a/wizard/scop_invoice_idf_wizard.py b/wizard/scop_invoice_idf_wizard.py
index 07a6e0c..f1b4b66 100644
--- a/wizard/scop_invoice_idf_wizard.py
+++ b/wizard/scop_invoice_idf_wizard.py
@@ -126,31 +126,37 @@ class ScopImportIDFWizard(models.TransientModel):
                     else:
                         debit = int(row['Débit euro'])
                         credit = int(row['Crédit euro'])
-                        if journal == "VE" and debit > 0:
-                            line_type = "inv"
-                        elif journal == "BFC" and debit == 0:
-                            line_type = "pay"
+                        if debit > 0 and credit > 0:
+                            logs += "<li> Ligne " + str(
+                                line) + ": Montants incorrects</li>"
                         else:
-                            line_type = "refund"
-
-                        lettrage = row['Lettrage N']
-                        year = int(row['Année'])
-
-                        values = {
-                            'company_id': company_id.id,
-                            'partner_id': partner_id.id,
-                            'journal': journal,
-                            'writing_date': writing_date,
-                            'name': libelle,
-                            'year': year,
-                            'type': line_type,
-                            'lettrage': lettrage,
-                            'debit': debit,
-                            'credit': credit,
-                        }
-                        new_line = self.env[model].create(values)
-                        success += 1
-                        new_lines_years.add(new_line.year)
+                            if journal == "VE" and debit > 0:
+                                line_type = "inv"
+                            elif journal == "BFC" and credit > 0:
+                                line_type = "pay"
+                            elif journal == "BFC" and debit > 0:
+                                line_type = "reject"
+                            else:
+                                line_type = "refund"
+
+                            lettrage = row['Lettrage N']
+                            year = int(row['Année'])
+
+                            values = {
+                                'company_id': company_id.id,
+                                'partner_id': partner_id.id,
+                                'journal': journal,
+                                'writing_date': writing_date,
+                                'name': libelle,
+                                'year': year,
+                                'type': line_type,
+                                'lettrage': lettrage,
+                                'debit': debit,
+                                'credit': credit,
+                            }
+                            new_line = self.env[model].create(values)
+                            success += 1
+                            new_lines_years.add(new_line.year)
             logs += "</ul>"
 
         new_log.write({
-- 
GitLab