From d5db3cc98fb2767d4efae3248621809d442014ac Mon Sep 17 00:00:00 2001
From: Benjamin <benjamin@le-filament.com>
Date: Fri, 5 Mar 2021 18:01:01 +0100
Subject: [PATCH] [fix] schedule error

---
 models/scop_bordereau_cg.py      | 24 +++++++++++++-----------
 report/report_scop_bordereau.xml |  1 -
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/models/scop_bordereau_cg.py b/models/scop_bordereau_cg.py
index c09b115..d6d7611 100644
--- a/models/scop_bordereau_cg.py
+++ b/models/scop_bordereau_cg.py
@@ -383,20 +383,22 @@ class Bordereau(models.Model):
         MoveLine = self.env['account.move.line']
         for bordereau in self:
             inv_ids = bordereau.invoice_ids.ids
-            print(inv_ids)
-            schedule = MoveLine.read_group([
+            move_lines = MoveLine.search([
                 ('invoice_id', 'in', inv_ids),
                 ('account_id.internal_type', '=', 'receivable')],
-                ['date_maturity', 'credit', 'debit'],
-                groupby=['date_maturity:day'],
-                orderby='date_maturity',
+                order='date_maturity',
             )
-            schedule_plan = [
-                {
-                    'date': datetime.strptime(
-                        l['date_maturity:day'], '%d %b %Y').strftime('%d/%m/%Y'),
-                    'amount': l['debit'] - l['credit']
-                } for l in schedule]
+            schedule = list(dict.fromkeys(move_lines.mapped('date_maturity')))
+            schedule_plan = []
+            for date in schedule:
+                amount = 0
+                for item in move_lines:
+                    if item.date_maturity == date:
+                        amount += item.debit - item.credit
+                schedule_plan.append({
+                    'date': date.strftime('%d/%m/%Y'),
+                    'amount': amount
+                })
             return schedule_plan
 
     def get_contribution_type(self):
diff --git a/report/report_scop_bordereau.xml b/report/report_scop_bordereau.xml
index e0c8c7e..2671a36 100644
--- a/report/report_scop_bordereau.xml
+++ b/report/report_scop_bordereau.xml
@@ -161,7 +161,6 @@
                 report_type="qweb-pdf"
                 name="cgscop_cotisation_cg.report_bordereau"
                 file="cgscop_cotisation_cg.report_bordereau"
-                menu="True"
         />
 
     </data>
-- 
GitLab