From 74da02ded0fd7842e9ca69fd5620c5b1e3d3c459 Mon Sep 17 00:00:00 2001 From: jordan <jordan@le-filament.com> Date: Tue, 8 Feb 2022 11:37:54 +0100 Subject: [PATCH] [update] report invoice and contribution deal with multi-modules (cg, riga, idf) --- __manifest__.py | 1 + report/__init__.py | 1 + report/account_invoice_all.py | 42 ++++++++++++++++++-- report/scop_contribution_report.py | 61 ++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 report/scop_contribution_report.py diff --git a/__manifest__.py b/__manifest__.py index 2dc5e4a..6f9b93b 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -9,6 +9,7 @@ "installable": True, "depends": [ "cgscop_partner", + "cgscop_cotisation", "multi_company_menu", ], "data": [ diff --git a/report/__init__.py b/report/__init__.py index 8c22d98..cf825a9 100755 --- a/report/__init__.py +++ b/report/__init__.py @@ -2,3 +2,4 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import account_invoice_all +from . import scop_contribution_report diff --git a/report/account_invoice_all.py b/report/account_invoice_all.py index 27aa6ca..f025fb7 100644 --- a/report/account_invoice_all.py +++ b/report/account_invoice_all.py @@ -1,18 +1,20 @@ # © 2022 Le Filament (<http://www.le-filament.com>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import models +from odoo import models, api class ScopAccountInvoiceIDFReport(models.Model): _inherit = "account.invoice.all" - def _select(self): - select_str = super(ScopAccountInvoiceIDFReport, self)._select() + # ------------------------------------------------------ + # Query + # ------------------------------------------------------ + def _subquery(self): + select_str = super(ScopAccountInvoiceIDFReport, self)._subquery() select_str += """ UNION ALL ( SELECT - id, null as invoice_id, writing_date as date_invoice, writing_date as date_due, @@ -36,3 +38,35 @@ class ScopAccountInvoiceIDFReport(models.Model): ) """ return select_str + + # ------------------------------------------------------ + # Computed fields + # ------------------------------------------------------ + @api.multi + def _compute_lines(self): + for inv in self: + ur_idf_id = self.env.ref('cgscop_partner.riga_14231') + if not inv.invoice_id and inv.partner_id.ur_id == ur_idf_id: + invoice_idf_id = self.env['scop.invoice.idf'].sudo().search([ + ('partner_id', '=', inv.partner_id.id), + ('writing_date', '=', inv.date_invoice), + ('acc_doc', '=', inv.number), + ('type', '=', 'inv'), + ]) + if len(invoice_idf_id) == 1: + inv.lines = "<table class='table table-hover table-striped table-sm'>" \ + "<thead class='thead-light'><tr><th>Description</th><th>Quantité</th><th>P.U</th>" \ + "<th>Total HT</th><th>Total TTC</th></tr></thead><tbody>" + \ + ''.join( + invoice_idf_id.mapped( + lambda l: ("<tr><td>" + l.name.replace( + '\n', '<br/>') + "</td>" + + "<td></td>" + + "<td>" + str( + l.debit) + "</td>" + + "<td>" + str( + l.debit) + "</td>" + + "<td>" + str( + l.debit) + "</td></tr>"))) + "</tbody></table>" + if not inv.lines: + super(ScopAccountInvoiceIDFReport, inv)._compute_lines() diff --git a/report/scop_contribution_report.py b/report/scop_contribution_report.py new file mode 100644 index 0000000..4075c0e --- /dev/null +++ b/report/scop_contribution_report.py @@ -0,0 +1,61 @@ +# © 2022 Le Filament (<http://www.le-filament.com>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields + + +class ScopContributionReport(models.Model): + _inherit = "scop.contribution.report" + + source = fields.Selection( + selection_add=[ + ('idf', 'IDF')]) + + # ------------------------------------------------------ + # Query + # ------------------------------------------------------ + def _subquery(self): + contribution_ur_id = self.env.ref('cgscop_partner.riga_14399').id + query = super(ScopContributionReport, self)._subquery() + query += """ + UNION ALL ( + SELECT + 'idf' as source, + year, + %s as type_contribution_id, + partner_id, + debit AS amount_called, + debit - amount_residual AS amount_paid, + amount_residual AS amount_due + FROM + scop_cotisation_idf + WHERE + type = 'inv' + ) + """ % contribution_ur_id + return query + + # ------------------------------------------------------ + # Business functions + # ------------------------------------------------------ + def _get_payment(self): + self.ensure_one() + if self.source == 'idf': + payment_ids = self.env['scop.cotisation.idf'].sudo().search([ + ('year', '=', self.year), + ('partner_id', '=', self.partner_id.id), + ('type', '!=', 'inv'), + ]) + if payment_ids: + payments = payment_ids.mapped(lambda p: { + 'date': p.writing_date, + 'name': p.name, + 'ref': p.piece, + 'credit': p.credit, + }) + payments_html = self._get_html_table(payments) + else: + payments_html = "<p>Il n'y a pas de paiements associés à cette cotisation</p>" + return payments_html + else: + return super(ScopContributionReport, self)._get_payment() -- GitLab