Sélectionner une révision Git
scop_contribution_report.py 2,63 Kio
# © 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, api
from odoo.exceptions import UserError
class ScopContributionReport(models.Model):
_inherit = "scop.contribution.report"
has_bordereau = fields.Boolean("Bordereau lié", compute="_compute_has_bordereau")
# ------------------------------------------------------
# Compute
# ------------------------------------------------------
@api.multi
def _compute_has_bordereau(self):
contrib_cg = self.env.ref('cgscop_partner.riga_14397')
for contribution in self:
# exclude contribution before 2021 from RIGA
if contribution.year > '2020':
if contribution.type_contribution_id == contrib_cg:
bordereau = self.env['scop.bordereau'].sudo().search([
('partner_id', '=', self.partner_id.id),
('year', '=', self.year),
])
if len(bordereau) == 1:
contribution.has_bordereau = True
else:
contribution.has_bordereau = False
else:
contribution.has_bordereau = False
else:
contribution.has_bordereau = False
# ------------------------------------------------------
# Button
# ------------------------------------------------------
def print_report_with_payment(self):
bordereau = self.env['scop.bordereau'].sudo().search([
('partner_id', '=', self.partner_id.id),
('year', '=', self.year),
])
if len(bordereau) == 1:
return self.env.ref(
'cgscop_cotisation_cg.cgscop_bordereau_report_with_payments'
).sudo().report_action(bordereau.sudo())
else:
raise UserError('Pas de bordereau rattaché à cette cotisation.')
# ------------------------------------------------------
# Business method
# ------------------------------------------------------
def get_invoice_contribution(self):
"""
If cotiz is type CG, then we filtered on not canceled bordereaux
"""
self.ensure_one()
invoice_ids = super(
ScopContributionReport, self).get_invoice_contribution()
contribution_cg = self.env.ref('cgscop_partner.riga_14397')
if self.type_contribution_id == contribution_cg:
invoice_ids = invoice_ids.filtered(
lambda i: i.bordereau_id.state not in ('cancel',)
)
return invoice_ids