Maintainers
This module is maintained by the OCA.
-
+
+
+
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
diff --git a/pms/wizards/__init__.py b/pms/wizards/__init__.py index 42e35d4e5..7911df37b 100644 --- a/pms/wizards/__init__.py +++ b/pms/wizards/__init__.py @@ -7,3 +7,4 @@ from . import wizard_payment_folio from . import wizard_folio_changes from . import wizard_several_partners from . import pms_booking_duplicate +from . import folio_payment_link diff --git a/pms/wizards/folio_payment_link.py b/pms/wizards/folio_payment_link.py new file mode 100644 index 000000000..253f8354a --- /dev/null +++ b/pms/wizards/folio_payment_link.py @@ -0,0 +1,59 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from werkzeug import urls + +from odoo import api, models + + +class FolioPaymentLink(models.TransientModel): + _inherit = "payment.link.wizard" + _description = "Generate Sales Payment Link" + + @api.model + def default_get(self, fields): + res = super(FolioPaymentLink, self).default_get(fields) + if res["res_id"] and res["res_model"] == "pms.folio": + record = self.env[res["res_model"]].browse(res["res_id"]) + res.update( + { + "description": record.name, + "amount": record.pending_amount, + "currency_id": record.currency_id.id, + "partner_id": record.partner_id.id if record.partner_id else False, + "amount_max": record.pending_amount, + } + ) + return res + + def _generate_link(self): + """Override of the base method to add the folio_id in the link.""" + for payment_link in self: + if payment_link.res_model == "pms.folio": + # TODO: Review controller /website_payment/pay, + # how inherit it to add acquirers by property? + # now we send the first acquirer that has the property in pms_property_ids + folio = self.env["pms.folio"].browse(payment_link.res_id) + acquirer = self.env["payment.acquirer"].search( + [ + ("pms_property_ids", "in", folio.property_id.id), + ], + limit=1, + ) + record = self.env[payment_link.res_model].browse(payment_link.res_id) + payment_link.link = ( + "%s/website_payment/pay?reference=%s&amount=%s¤cy_id=%s" + "&acquirer_id=%s&partner_id=%s&folio_id=%s&company_id=%s" + "&access_token=%s" + ) % ( + record.get_base_url(), + urls.url_quote_plus(payment_link.description), + payment_link.pending_amount, + payment_link.currency_id.id, + acquirer.id if acquirer else None, + payment_link.partner_id.id if payment_link.partner_id else None, + payment_link.res_id, + payment_link.company_id.id, + payment_link.access_token, + ) + else: + super(FolioPaymentLink, payment_link)._generate_link() diff --git a/pms/wizards/folio_payment_link_views.xml b/pms/wizards/folio_payment_link_views.xml new file mode 100644 index 000000000..882ea561b --- /dev/null +++ b/pms/wizards/folio_payment_link_views.xml @@ -0,0 +1,14 @@ + +