From 5a9530cdfd8043bef4633a36c92b857f8897c891 Mon Sep 17 00:00:00 2001 From: Juhil Somaiya Date: Fri, 1 Mar 2019 05:40:32 +0000 Subject: [PATCH] [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 --- addons/account/controllers/portal.py | 5 +++++ addons/payment/models/payment_acquirer.py | 13 +++++++++++++ addons/payment/views/payment_templates.xml | 6 ++++++ addons/sale/controllers/portal.py | 1 + addons/website_sale/controllers/main.py | 6 ++---- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/addons/account/controllers/portal.py b/addons/account/controllers/portal.py index f4356d7b1b6..99d44428f29 100644 --- a/addons/account/controllers/portal.py +++ b/addons/account/controllers/portal.py @@ -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) # ------------------------------------------------------------ diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 0f2ce5d222a..8fa4d67c36a 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -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. """ diff --git a/addons/payment/views/payment_templates.xml b/addons/payment/views/payment_templates.xml index 550939e21b7..99e450dc179 100644 --- a/addons/payment/views/payment_templates.xml +++ b/addons/payment/views/payment_templates.xml @@ -63,6 +63,12 @@ t-att-checked="acquirers_count==1 and pms_count==0 or acquirers[0] == acq"/> + + + Fee + + + (Some fees may apply) +