Skip to content
Extraits de code Groupes Projets
Valider b1fd1bec rédigé par jordan's avatar jordan
Parcourir les fichiers

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

parent 5677ce33
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -13,6 +13,11 @@ class ScopContributionReport(models.Model): ...@@ -13,6 +13,11 @@ class ScopContributionReport(models.Model):
name = fields.Char(compute='_compute_name') name = fields.Char(compute='_compute_name')
year = fields.Char('Année de cotisation') year = fields.Char('Année de cotisation')
source = fields.Selection(
string='Source',
selection=[('odoo', 'Odoo')],
required=True,)
type_contribution_id = fields.Many2one( type_contribution_id = fields.Many2one(
comodel_name="scop.contribution.type", comodel_name="scop.contribution.type",
string="Type de cotisation", string="Type de cotisation",
...@@ -38,6 +43,7 @@ class ScopContributionReport(models.Model): ...@@ -38,6 +43,7 @@ class ScopContributionReport(models.Model):
def _select_invoice(self): def _select_invoice(self):
select_str = """ select_str = """
SELECT SELECT
'odoo' as source,
CAST(i.year AS VARCHAR), CAST(i.year AS VARCHAR),
i.type_contribution_id, i.type_contribution_id,
i.partner_id, i.partner_id,
...@@ -87,6 +93,7 @@ class ScopContributionReport(models.Model): ...@@ -87,6 +93,7 @@ class ScopContributionReport(models.Model):
select_str = """ select_str = """
SELECT SELECT
ROW_NUMBER() OVER(ORDER BY c.year, c.partner_id) AS id, ROW_NUMBER() OVER(ORDER BY c.year, c.partner_id) AS id,
c.source,
c.year, c.year,
c.type_contribution_id, c.type_contribution_id,
c.partner_id, c.partner_id,
...@@ -102,7 +109,8 @@ class ScopContributionReport(models.Model): ...@@ -102,7 +109,8 @@ class ScopContributionReport(models.Model):
GROUP BY GROUP BY
c.year, c.year,
c.type_contribution_id, c.type_contribution_id,
c.partner_id c.partner_id,
c.source
""" """
def _query_order(self): def _query_order(self):
...@@ -160,13 +168,9 @@ class ScopContributionReport(models.Model): ...@@ -160,13 +168,9 @@ class ScopContributionReport(models.Model):
def _get_payment(self): def _get_payment(self):
self.ensure_one() self.ensure_one()
invoice_ids = self.env['account.invoice'].sudo().search([ payments_html = False
('year', '=', int(self.year)), if self.source == 'odoo':
('partner_id', '=', self.partner_id.id), invoice_ids = self.get_invoice_contribution()
('type_contribution_id', '=', self.type_contribution_id.id),
('type', '=', 'out_invoice'),
('bordereau_id.state', 'not in', ('cancel',))
])
payment_ids = invoice_ids.mapped('payment_move_line_ids') payment_ids = invoice_ids.mapped('payment_move_line_ids')
if payment_ids: if payment_ids:
payments = payment_ids.mapped(lambda p: { payments = payment_ids.mapped(lambda p: {
...@@ -183,10 +187,22 @@ class ScopContributionReport(models.Model): ...@@ -183,10 +187,22 @@ class ScopContributionReport(models.Model):
'class': 'text-danger' 'class': 'text-danger'
}) })
payments_html = self._get_html_table(payments) 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>" payments_html = "<p>Il n'y a pas de paiements associés à cette cotisation</p>"
return payments_html 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): def _get_html_table(self, payments):
""" """
:param payments: list of dict {date, name, ref, amount} :param payments: list of dict {date, name, ref, amount}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter