[IMP] account, payment, sale, website_sale: added extra fees on payment

Purpose of the task is when extra fee is activated on the payment acquirer,
the customer is no warned about extra cost when choosing the payment acquirer.

so display the extra fees on payment acquirer when doing the payment.

Related Task ID : 1845815
Closes : #31730
This commit is contained in:
Juhil Somaiya
2019-04-09 06:44:48 +00:00
committed by Romain Derie
parent 556d6d6059
commit 5a9530cdfd
5 changed files with 27 additions and 4 deletions
+5
View File
@@ -85,6 +85,11 @@ class PortalAccount(CustomerPortal):
return self._show_report(model=invoice_sudo, report_type=report_type, report_ref='account.account_invoices', download=download)
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.residual, invoice_sudo.currency_id, country_id)
return request.render("account.portal_invoice_page", values)
# ------------------------------------------------------------
+13
View File
@@ -296,6 +296,19 @@ class PaymentAcquirer(models.Model):
self.journal_id.show_on_dashboard = self.website_published
return True
@api.multi
def get_acquirer_extra_fees(self, amount, currency_id, country_id):
extra_fees = {
'currency_id': currency_id
}
acquirers = self.filtered(lambda x: x.fees_active)
for acq in acquirers:
custom_method_name = '%s_compute_fees' % acq.provider
if hasattr(acq, custom_method_name):
fees = getattr(acq, custom_method_name)(amount, currency_id, country_id)
extra_fees[acq] = fees
return extra_fees
@api.multi
def get_form_action_url(self):
""" Returns the form action URL, for form-based acquirer implementations. """
@@ -63,6 +63,12 @@
t-att-checked="acquirers_count==1 and pms_count==0 or acquirers[0] == acq"/>
</t>
<span class="payment_option_name" t-esc="acq.name"/>
<t t-if="acq_extra_fees and acq_extra_fees.get(acq)">
<span class="badge badge-pill badge-secondary"> + <t t-esc="acq_extra_fees[acq]" t-options='{"widget": "monetary", "display_currency": acq_extra_fees["currency_id"]}'/> Fee </span>
</t>
<t t-elif="acq.fees_active">
<small class="text-muted">(Some fees may apply)</small>
</t>
</label>
<ul class="float-right list-inline payment_icon_list">
<t t-set="i" t-value="0"/>
+1
View File
@@ -185,6 +185,7 @@ class CustomerPortal(CustomerPortal):
values['pms'] = request.env['payment.token'].search(
[('partner_id', '=', order_sudo.partner_id.id),
('acquirer_id', 'in', acquirers.filtered(lambda acq: acq.payment_flow == 's2s').ids)])
values['acq_extra_fees'] = acquirers.get_acquirer_extra_fees(order_sudo.amount_total, order_sudo.currency_id, order_sudo.partner_id.country_id.id)
if order_sudo.state in ('draft', 'sent', 'cancel'):
history = request.session.get('my_quotations_history', [])
+2 -4
View File
@@ -788,10 +788,6 @@ class WebsiteSale(http.Controller):
# ------------------------------------------------------
def _get_shop_payment_values(self, order, **kwargs):
shipping_partner_id = False
if order:
shipping_partner_id = order.partner_shipping_id.id or order.partner_invoice_id.id
values = dict(
website_sale_order=order,
errors=[],
@@ -816,6 +812,8 @@ class WebsiteSale(http.Controller):
[('partner_id', '=', order.partner_id.id),
('acquirer_id', 'in', acquirers.ids)])
if order:
values['acq_extra_fees'] = acquirers.get_acquirer_extra_fees(order.amount_total, order.currency_id, order.partner_id.country_id.id)
return values
@http.route(['/shop/payment'], type='http', auth="public", website=True)