diff --git a/models/account_move.py b/models/account_move.py index 5dfbe1591332840bd5fc12265d17899a78d86fda..a7bc458d42caf0a866bb4e08eb66c52551c624fe 100644 --- a/models/account_move.py +++ b/models/account_move.py @@ -25,10 +25,24 @@ class ScopAccountMove(models.Model): selection=[("1", "1"), ("2", "2"), ("3", "3"), ("4", "4")], required=False, ) + amount_called = fields.Monetary( + string="Montant Appelé", + currency_field="company_currency_id", + compute="_compute_amount_called", + ) # ------------------------------------------------------ # Compute fields # ------------------------------------------------------ + def _compute_amount_called(self): + for invoice in self: + if invoice.move_type == "out_invoice": + payment_ids = invoice.move_line_payment_ids + refund_ids = payment_ids.mapped("move_id").filtered( + lambda r: r.move_type == "out_refund") + invoice.amount_called = invoice.amount_total_signed + sum(refund_ids.mapped("amount_total_signed")) + else: + invoice.amount_called = 0 # ------------------------------------------------------ # Override parent diff --git a/models/scop_bordereau_cg.py b/models/scop_bordereau_cg.py index 509e58b1a1e972a7bd9b461f59ddc7e6cf7ccbab..eb9af3d9c8168bc6d11a04458f62d9b668fa6ab9 100644 --- a/models/scop_bordereau_cg.py +++ b/models/scop_bordereau_cg.py @@ -1203,27 +1203,38 @@ class Bordereau(models.Model): Get payment dates for invoices in bordereau :return: dict with date as key and amount (float) as value """ - # TODO: voir si possible d'optimiser avec le nouveau modèle - MoveLine = self.env["account.move.line"] + Move = self.env["account.move"] for bordereau in self: - inv_ids = bordereau.invoice_ids.ids - schedule_plan = MoveLine.read_group( + payments = bordereau.invoice_ids.move_line_payment_ids.filtered( + lambda r: r.move_id.move_type == "entry").sorted(lambda p: p.date) + schedule_plan = Move.read_group( [ - ("move_id", "in", inv_ids), - ("account_id.internal_type", "=", "receivable"), + ("bordereau_id", "=", bordereau.id), ], - fields=["date_maturity", "credit", "debit", "amount_residual"], - groupby=["date_maturity:day"], - orderby="date_maturity", + fields=["cotiz_quarter", "amount_total_signed", "amount_residual_signed"], + groupby=["cotiz_quarter"], + orderby="cotiz_quarter", lazy=False, ) - total_amount = sum(list(map(lambda l: l.get("debit"), schedule_plan))) + schedule_date = [ + bordereau.base_cotisation_cg.trimester_1, + bordereau.base_cotisation_cg.trimester_2, + bordereau.base_cotisation_cg.trimester_3, + bordereau.base_cotisation_cg.trimester_4, + ] + for contribution in schedule_plan: + i = int(contribution.get("cotiz_quarter")) - 1 + contribution["date_maturity"] = schedule_date[i] + + total_amount = sum(list(map( + lambda l: l.get("amount_total_signed"), schedule_plan))) total_residual = sum( - list(map(lambda l: l.get("amount_residual"), schedule_plan)) + list(map(lambda l: l.get("amount_residual_signed"), schedule_plan)) ) total_paid = total_amount - total_residual return { "plan": schedule_plan, + "payments": payments, "total_amount": total_amount, "total_paid": total_paid, "total_residual": total_residual, diff --git a/templates/report_scop_bordereau_payments.xml b/templates/report_scop_bordereau_payments.xml index 14f8b94c287cf8318314cda44f1b2f295aca2a6d..b2cd1487ce3d4ea9711c025713cab705e21d187d 100644 --- a/templates/report_scop_bordereau_payments.xml +++ b/templates/report_scop_bordereau_payments.xml @@ -6,6 +6,11 @@ <t t-call="web.external_layout"> <t t-set="o" t-value="o.sudo().with_context(lang='fr')" /> <div class="page" style="font-size: 15px;"> + <t + t-set="schedule_line" + t-value="o.get_bordereau_move_line_with_payments()" + /> + <!-- Adresse --> <div class="row"> <div class="col-6 offset-6 oe_mt64 oe_mb64"> <span @@ -28,6 +33,7 @@ /></t> </div> </div> + <!-- Titre --> <div class="row"> <div class="col-12 text-center"> <h2 style="color: #E5074D;"> @@ -37,6 +43,7 @@ </h2> </div> </div> + <!-- Détail adhérent et n° de bordereau --> <div class="row"> <div class="col-12 oe_mb16"> <p> @@ -48,13 +55,15 @@ /><br /> N° Bordereau : <span t-field="o.name" /><t t-if="o.is_regul" - >-<span t-field="o.version" /></t> + >-<span t-field="o.version" /></t><br /> + Le <t t-esc="datetime.date.today()" t-options="{'widget': 'date', 'format': 'dd MMMM YYYY'}" /> </p> </div> </div> + <div class="row"> + <!-- Rappel cotisations annuelles --> <div class="col-6" style="border: 1px solid #aaa;"> - <div /> <h5 class="oe_mt8" style="font-weight: 600;" @@ -75,6 +84,7 @@ t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}" />. </p> + <!-- Récapitulatif des cotisations --> <p> <t t-set="amount_line" @@ -101,6 +111,7 @@ </tr> </table> </p> + <!-- Total des cotisations --> <p> <table class="table table-sm" style="border: none;"> <tr style="border: none"> @@ -122,66 +133,31 @@ </tr> </table> </p> + </div> - <h5 style="font-weight: 600;">Échéancier</h5> - - <p id="schedule_table_with_payments"> - <t - t-set="schedule_line" - t-value="o.get_bordereau_move_line_with_payments()" - /> - <table - class="table table-sm table-striped" - style="border: none;" - > - <tr> - <th>Date d'échéance</th> - <th class="text-right">Montant appelé</th> - <th class="text-right">Montant dû</th> - </tr> - <tr - t-foreach="schedule_line.get('plan')" - t-as="line" - style="border-bottom: 1px solid #ccc;" - > - <t t-if="line.get('debit') > 0"> - <td - style="border: none; background: inherit; color: inherit;" - ><t - t-esc="line.get('date_maturity:day')" - /></td> - <td - class="text-right" - style="border: none; background: inherit; color: inherit;" - ><t - t-esc="line.get('debit')" - t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}" - /></td> - <td - class="text-right" - style="border: none; background: inherit; color: inherit;" - ><t - t-esc="line.get('amount_residual')" - t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}" - /></td> - </t> - </tr> - </table> + <!-- Récapitulatif Global --> + <div class="col-6" style="border: 1px solid #aaa;"> + <h5 + class="oe_mt8" + style="font-weight: 600;" + >Récapitulatif</h5> + <p> <table class="table table-sm table-striped" style="border: none;" > <tr> - <th>Montant dû</th> <th class="text-right">Total appelé</th> <th class="text-right">Total réglé</th> + <th class="text-right">Montant dû</th> </tr> <tr style="border-bottom: 1px solid #ccc;"> <td + class="text-right" style="border: none; background: inherit; color: inherit;" > <t - t-esc="schedule_line.get('total_residual')" + t-esc="schedule_line.get('total_amount')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}" /> </td> @@ -190,7 +166,7 @@ style="border: none; background: inherit; color: inherit;" > <t - t-esc="schedule_line.get('total_amount')" + t-esc="schedule_line.get('total_paid')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}" /> </td> @@ -199,25 +175,95 @@ style="border: none; background: inherit; color: inherit;" > <t - t-esc="schedule_line.get('total_paid')" + t-esc="schedule_line.get('total_residual')" t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}" /> </td> </tr> </table> </p> + </div> + </div> + + <div class="row oe_mt32"> + <!-- Rappel Echéancier --> + <div class="col-6" style="border: 1px solid #aaa;"> + <h5 class="oe_mt8" style="font-weight: 600;">Rappel Échéancier</h5> + <p id="schedule_table_with_payments"> + <table + class="table table-sm table-striped" + style="border: none;" + > + <tr> + <th>Date d'échéance</th> + <th class="text-right">Montant appelé</th> + <th class="text-right">Montant dû</th> + </tr> + <tr + t-foreach="schedule_line.get('plan')" + t-as="line" + style="border-bottom: 1px solid #ccc;" + > + <td + style="border: none; background: inherit; color: inherit;" + ><t + t-esc="line.get('date_maturity')" t-options="{'widget': 'date', 'format': 'dd/MM/YYYY'}" + /></td> + <td + class="text-right" + style="border: none; background: inherit; color: inherit;" + ><t + t-esc="line.get('amount_total_signed')" + t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}" + /></td> + <td + class="text-right" + style="border: none; background: inherit; color: inherit;" + ><t + t-esc="line.get('amount_residual_signed')" + t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}" + /></td> + </tr> + </table> + </p> <p style="font-size: 13px;"> <em >IBAN: FR76 4255 9100 0008 0024 8837 710 - BIC : CCOPFRPPXXX</em> </p> </div> - <div class="col-6" style="margin-top: 220px;"> - <div style="border: 1px solid #aaa; padding: 15px;"> - CG Scop <br /> - 30, rue des Epinettes <br /> - 75017 PARIS - </div> + <!-- Détail des règlements --> + <div class="col-6" style="border: 1px solid #aaa;"> + <h5 class="oe_mt8" style="font-weight: 600;">Détail des règlements</h5> + <p id="schedule_table_with_payments"> + <table + class="table table-sm table-striped" + style="border: none;" + > + <tr> + <th>Date de règlement</th> + <th class="text-right">Montant réglé</th> + </tr> + <tr + t-foreach="schedule_line.get('payments')" + t-as="payment" + style="border-bottom: 1px solid #ccc;" + > + <td + style="border: none; background: inherit; color: inherit;" + ><t + t-esc="payment.date" t-options="{'widget': 'date', 'format': 'dd/MM/YYYY'}" + /></td> + <td + class="text-right" + style="border: none; background: inherit; color: inherit;" + ><t + t-esc="payment.credit" + t-options="{'widget': 'monetary', 'display_currency': o.company_id.currency_id}" + /></td> + </tr> + </table> + </p> </div> </div>