diff --git a/report/scop_contribution_report.py b/report/scop_contribution_report.py index 4986c5e16f6248b092e1e4f43e6c58b2ade57efd..c999b79f28f1d415d6a93ac0e04e638219fc6349 100644 --- a/report/scop_contribution_report.py +++ b/report/scop_contribution_report.py @@ -1,7 +1,9 @@ # © 2022 Le Filament (<http://www.le-filament.com>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import _, fields, models +import base64 + +from odoo import SUPERUSER_ID, _, fields, models from odoo.exceptions import UserError @@ -39,7 +41,7 @@ class ScopContributionReport(models.Model): contribution.has_bordereau = False # ------------------------------------------------------ - # Button + # Button / Action # ------------------------------------------------------ def print_report_with_payment(self): bordereau = ( @@ -63,6 +65,32 @@ class ScopContributionReport(models.Model): else: raise UserError(_("Pas de bordereau rattaché à cette cotisation.")) + def print_contribution(self): + self.ensure_one() + bordereau = ( + self.env["scop.bordereau"] + .sudo() + .search( + [ + ("partner_id", "=", self.partner_id.id), + ("year", "=", self.year), + ("state", "not in", ["draft", "cancel"]), + ] + ) + ) + if len(bordereau) == 1: + report_sudo = self.env.ref( + "cgscop_cotisation_cg.cgscop_bordereau_report" + ).sudo() + bordereau_pdf = report_sudo.with_user(SUPERUSER_ID)._render_qweb_pdf( + bordereau.id + )[0] + return base64.b64encode(bordereau_pdf) + else: + raise UserError( + _("Impossible de télécharger le bordereau associé à cette cotisation.") + ) + # ------------------------------------------------------ # Business method # ------------------------------------------------------