From 9e0562ac53559536927a7e0f38ef0f5efcc1fe5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Sun, 6 Nov 2022 10:02:50 +0100 Subject: [PATCH] [IMP]pms: add report proforma routes --- pms/__manifest__.py | 1 + pms/controllers/pms_portal.py | 38 ++++++++++++++++++++++++++ pms/models/account_move.py | 35 ++++++++++++++++++++++++ pms/models/pms_folio.py | 6 ++-- pms/views/account_portal_templates.xml | 17 ++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 pms/views/account_portal_templates.xml diff --git a/pms/__manifest__.py b/pms/__manifest__.py index 1195acef9..f5469d0d1 100644 --- a/pms/__manifest__.py +++ b/pms/__manifest__.py @@ -94,6 +94,7 @@ "views/account_move_line_views.xml", "report/proforma_report_templates.xml", "report/proforma_report.xml", + "views/account_portal_templates.xml", ], "demo": [ "demo/pms_master_data.xml", diff --git a/pms/controllers/pms_portal.py b/pms/controllers/pms_portal.py index fb8631814..c0e6c27ba 100644 --- a/pms/controllers/pms_portal.py +++ b/pms/controllers/pms_portal.py @@ -570,3 +570,41 @@ class PortalPrecheckin(CustomerPortal): if firstname and email: checkin_partner.write({"firstname": firstname, "email": email}) checkin_partner.send_portal_invitation_email(firstname, email) + + +class PortalAccount(CustomerPortal): + @http.route( + ["/my/invoices/proforma/"], + type="http", + auth="public", + website=True, + ) + def portal_proforma_my_invoice_detail( + self, invoice_id, access_token=None, report_type=None, download=False, **kw + ): + try: + invoice_sudo = self._document_check_access( + "account.move", invoice_id, access_token + ) + except (AccessError, MissingError): + return request.redirect("/my") + + if report_type in ("html", "pdf", "text"): + return self._show_report( + model=invoice_sudo, + report_type=report_type, + report_ref="pms.action_report_pms_pro_forma_invoice", + download=download, + ) + + invoice_sudo = invoice_sudo.with_context(proforma=True) + values = self._invoice_get_page_view_values(invoice_sudo, access_token, **kw) + acquirers = values.get("acquirers") + if acquirers: + country_id = ( + values.get("partner_id") and values.get("partner_id")[0].country_id.id + ) + values["acq_extra_fees"] = acquirers.get_acquirer_extra_fees( + invoice_sudo.amount_residual, invoice_sudo.currency_id, country_id + ) + return request.render("pms.pms_proforma_invoice_template", values) diff --git a/pms/models/account_move.py b/pms/models/account_move.py index b438ccdea..f8edf187e 100644 --- a/pms/models/account_move.py +++ b/pms/models/account_move.py @@ -353,3 +353,38 @@ class AccountMove(models.Model): self.folio_ids.message_post(body=mens) raise ValidationError(mens) return True + + def _proforma_access_url(self): + self.ensure_one() + if self.is_invoice(include_receipts=True): + return "/my/invoices/proforma/%s" % (self.id) + else: + return False + + def get_proforma_portal_url( + self, + suffix=None, + report_type=None, + download=None, + query_string=None, + anchor=None, + ): + """ + Get a proforma portal url for this model, including access_token. + The associated route must handle the flags for them to have any effect. + - suffix: string to append to the url, before the query string + - report_type: report_type query string, often one of: html, pdf, text + - download: set the download query string to true + - query_string: additional query string + - anchor: string to append after the anchor # + """ + self.ensure_one() + url = self._proforma_access_url() + "%s?access_token=%s%s%s%s%s" % ( + suffix if suffix else "", + self._portal_ensure_token(), + "&report_type=%s" % report_type if report_type else "", + "&download=true" if download else "", + query_string if query_string else "", + "#%s" % anchor if anchor else "", + ) + return url diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index d32e4d983..569d55d6a 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -1896,6 +1896,7 @@ class PmsFolio(models.Model): else partner_invoice.invoicing_policy ) + invoice_date = False if date: invoice_date = date if partner_invoice_policy == "checkout": @@ -1926,8 +1927,9 @@ class PmsFolio(models.Model): datetime.date.today().month + 1, month_day, ) - for vals in invoice_vals_list: - vals["invoice_date"] = invoice_date + if invoice_date: + for vals in invoice_vals_list: + vals["invoice_date"] = invoice_date # 3) Create invoices. diff --git a/pms/views/account_portal_templates.xml b/pms/views/account_portal_templates.xml new file mode 100644 index 000000000..3315c652d --- /dev/null +++ b/pms/views/account_portal_templates.xml @@ -0,0 +1,17 @@ + + + + +