diff --git a/report/scop_contribution_report.py b/report/scop_contribution_report.py index 82a525f4f5f05c2e73ca0b3beb034ed8ddb8ea54..bb8cdbd4d9c2a1d399936465370e219e3b949f1a 100644 --- a/report/scop_contribution_report.py +++ b/report/scop_contribution_report.py @@ -13,6 +13,11 @@ class ScopContributionReport(models.Model): name = fields.Char(compute='_compute_name') year = fields.Char('Année de cotisation') + source = fields.Selection( + string='Source', + selection=[('odoo', 'Odoo')], + required=True,) + type_contribution_id = fields.Many2one( comodel_name="scop.contribution.type", string="Type de cotisation", @@ -38,6 +43,7 @@ class ScopContributionReport(models.Model): def _select_invoice(self): select_str = """ SELECT + 'odoo' as source, CAST(i.year AS VARCHAR), i.type_contribution_id, i.partner_id, @@ -87,6 +93,7 @@ class ScopContributionReport(models.Model): select_str = """ SELECT ROW_NUMBER() OVER(ORDER BY c.year, c.partner_id) AS id, + c.source, c.year, c.type_contribution_id, c.partner_id, @@ -102,7 +109,8 @@ class ScopContributionReport(models.Model): GROUP BY c.year, c.type_contribution_id, - c.partner_id + c.partner_id, + c.source """ def _query_order(self): @@ -160,32 +168,40 @@ class ScopContributionReport(models.Model): def _get_payment(self): self.ensure_one() + payments_html = False + if self.source == 'odoo': + invoice_ids = self.get_invoice_contribution() + payment_ids = invoice_ids.mapped('payment_move_line_ids') + if payment_ids: + payments = payment_ids.mapped(lambda p: { + 'date': p.date, + 'name': p.name, + 'ref': p.ref, + 'credit': p.credit, + 'class': '' + } if not p.invoice_id else { + 'date': p.date, + 'name': p.name, + 'ref': '', + 'credit': p.credit, + 'class': 'text-danger' + }) + payments_html = self._get_html_table(payments) + if not payments_html: + payments_html = "<p>Il n'y a pas de paiements associés à cette cotisation</p>" + return payments_html + + def get_invoice_contribution(self): invoice_ids = self.env['account.invoice'].sudo().search([ ('year', '=', int(self.year)), ('partner_id', '=', self.partner_id.id), ('type_contribution_id', '=', self.type_contribution_id.id), ('type', '=', 'out_invoice'), - ('bordereau_id.state', 'not in', ('cancel',)) + '|', + ('bordereau_id.state', 'not in', ('cancel',)), + ('bordereau_id', '=', False) ]) - payment_ids = invoice_ids.mapped('payment_move_line_ids') - if payment_ids: - payments = payment_ids.mapped(lambda p: { - 'date': p.date, - 'name': p.name, - 'ref': p.ref, - 'credit': p.credit, - 'class': '' - } if not p.invoice_id else { - 'date': p.date, - 'name': p.name, - 'ref': '', - 'credit': p.credit, - 'class': 'text-danger' - }) - 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 + return invoice_ids def _get_html_table(self, payments): """