[IMP]pms: allow custom amount portal payment

This commit is contained in:
Darío Lodeiros
2024-03-16 12:49:00 +01:00
parent 5c06ffb6e5
commit 7b5397a820
3 changed files with 29 additions and 9 deletions

View File

@@ -93,6 +93,10 @@ class PortalFolio(CustomerPortal):
"success_url",
"%s?%s" % (folio_sudo.access_url, access_token if access_token else ""),
)
custom_amount = False
if "custom_amount" in kwargs:
custom_amount = float(kwargs["custom_amount"])
vals = {
"acquirer_id": acquirer_id,
"return_url": success_url,
@@ -118,6 +122,7 @@ class PortalFolio(CustomerPortal):
"subscription payments will be made automatically."
),
},
amount=custom_amount,
)
@http.route(
@@ -199,6 +204,8 @@ class PortalFolio(CustomerPortal):
download=download,
)
values = self._folio_get_page_view_values(folio_sudo, access_token, **kw)
if "custom_amount" in kw:
values["custom_amount"] = float(kw["custom_amount"])
return request.render("pms.folio_portal_template", values)

View File

@@ -22,7 +22,9 @@ class PaymentTransaction(models.Model):
add_payment_vals["folio_ids"] = [(6, 0, self.folio_ids.ids)]
return super(PaymentTransaction, self)._create_payment(add_payment_vals)
def render_folio_button(self, folio, submit_txt=None, render_values=None):
def render_folio_button(
self, folio, submit_txt=None, render_values=None, custom_amount=None
):
values = {
"partner_id": folio.partner_id.id,
"type": self.type,
@@ -36,7 +38,7 @@ class PaymentTransaction(models.Model):
.sudo()
.render(
self.reference,
folio.pending_amount,
custom_amount or folio.pending_amount,
folio.currency_id.id,
values=values,
)

View File

@@ -78,7 +78,7 @@
<template id="portal_folio_payment" name="Folio Payment">
<div
class="row"
t-if="not tx_ids and folio.state in ('confirm','done') and folio.payment_state in ('not_paid', 'partial') and folio.amount_total"
t-if="folio.payment_state in ('not_paid', 'partial') and folio.pending_amount"
id="portal_pay"
>
<div class="modal fade" id="pay_with" role="dialog">
@@ -117,6 +117,10 @@
t-set="access_token"
t-value="access_token or ''"
/>
<t
t-set="custom_amount"
t-value="custom_amount or ''"
/>
<t t-set="callback_method" t-value="''" />
<t
t-set="form_action"
@@ -124,9 +128,14 @@
/>
<t
t-set="prepare_tx_url"
t-value="'/folio/pay/' + str(folio.id) + '/form_tx/'"
t-value="'/folio/pay/' + str(folio.id) + '?custom_amount=' + custom_amount + '/form_tx/'"
/>
<t t-set="submit_txt">Pay Now</t>
<t t-if="custom_amount" t.set="submit_txt">
Pay <t t-esc="custom_amount" />
</t>
<t t-else="" t-set="submit_txt">
Pay Now
</t>
<t t-set="icon_class" t-value="'fa-lock'" />
</t>
</div>
@@ -146,10 +155,11 @@
t-set="pending_manual_txs"
t-value="tx_ids.filtered(lambda tx: tx.state == 'pending' and tx.acquirer_id.provider in ('transfer', 'manual'))"
/>
<t t-set="custom_amount" t-value="custom_amount or ''" />
<div>
<a
href="#"
t-if="folio.state in ('confirm','done') and folio.payment_state in ('not_paid', 'partial') and folio.amount_total and (pending_manual_txs or not tx_ids)"
t-if="folio.payment_state in ('not_paid', 'partial') and folio.pending_amount and not custom_amount"
class="btn btn-primary btn-block mb-2"
data-toggle="modal"
data-target="#pay_with"
@@ -157,10 +167,11 @@
<i class="fa fa-fw fa-arrow-circle-right" /> Pay Now
</a>
<div
t-if="tx_ids and not pending_manual_txs and folio.payment_state in ('not_paid', 'partial')"
t-if="folio.payment_state in ('not_paid', 'partial') and folio.pending_amount"
class="alert alert-info py-1 mb-2"
>
<i class="fa fa-fw fa-check-circle" /> Pending
<!-- añadimos el importe en el boton-->
<i class="fa fa-fw fa-check-circle" /> Pay <t t-esc="custom_amount" />
</div>
<div
t-if="folio.payment_state in ('paid', 'overpayment')"
@@ -175,7 +186,7 @@
t-value="folio.transaction_ids.filtered(lambda tx: tx.state in ('authorized', 'done'))"
/>
<div
t-if="not tx_ids and folio.state in('confirm','done') and folio.payment_state in ('not_paid', 'partial') and folio.amount_total"
t-if="folio.payment_state in ('not_paid', 'partial') and folio.pending_amount"
id="portal_pay"
>
<div t-if="pms or acquirers" id="payment_method">