Skip to content
Snippets Groups Projects
Commit b1fd1bec authored by jordan's avatar jordan
Browse files

[update] report invoice and contribution deal with multi-modules (cg, riga, idf)

parent 5677ce33
No related branches found
No related tags found
No related merge requests found
......@@ -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,13 +168,9 @@ class ScopContributionReport(models.Model):
def _get_payment(self):
self.ensure_one()
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',))
])
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: {
......@@ -183,10 +187,22 @@ class ScopContributionReport(models.Model):
'class': 'text-danger'
})
payments_html = self._get_html_table(payments)
else:
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', '=', False)
])
return invoice_ids
def _get_html_table(self, payments):
"""
:param payments: list of dict {date, name, ref, amount}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment