[FIX] payment: fees recomputation on transaction amount/acquirer change
Fees were not recomputed when the amount or the acquirer of the payment transaction was changed. This can happen if the user clicks on "Pay now", which creates the transaction and computes the fees for the first time and then redirects to the payment provider, and then the user came back from the payment provider, hitting the previous button in his browser, for instance, and then changes the content of his cart (the quantity, or even the products) or change of payment provider (from Ogone to Paypal, for instance). opw-649509
This commit is contained in:
parent
9365ecaada
commit
2c81ab75c8
|
@ -413,6 +413,32 @@ class PaymentTransaction(osv.Model):
|
|||
|
||||
return super(PaymentTransaction, self).create(cr, uid, values, context=context)
|
||||
|
||||
def write(self, cr, uid, ids, values, context=None):
|
||||
Acquirer = self.pool['payment.acquirer']
|
||||
if ('acquirer_id' in values or 'amount' in values) and 'fees' not in values:
|
||||
# The acquirer or the amount has changed, and the fees are not explicitely forced. Fees must be recomputed.
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
for txn_id in ids:
|
||||
vals = dict(values)
|
||||
vals['fees'] = 0.0
|
||||
transaction = self.browse(cr, uid, txn_id, context=context)
|
||||
if 'acquirer_id' in values:
|
||||
acquirer = Acquirer.browse(cr, uid, values['acquirer_id'], context=context) if values['acquirer_id'] else None
|
||||
else:
|
||||
acquirer = transaction.acquirer_id
|
||||
if acquirer:
|
||||
custom_method_name = '%s_compute_fees' % acquirer.provider
|
||||
if hasattr(Acquirer, custom_method_name):
|
||||
amount = (values['amount'] if 'amount' in values else transaction.amount) or 0.0
|
||||
currency_id = values.get('currency_id') or transaction.currency_id.id
|
||||
country_id = values.get('partner_country_id') or transaction.partner_country_id.id
|
||||
fees = getattr(Acquirer, custom_method_name)(cr, uid, acquirer.id, amount, currency_id, country_id, context=None)
|
||||
vals['fees'] = float_round(fees, 2)
|
||||
res = super(PaymentTransaction, self).write(cr, uid, txn_id, vals, context=context)
|
||||
return res
|
||||
return super(PaymentTransaction, self).write(cr, uid, ids, values, context=context)
|
||||
|
||||
def on_change_partner_id(self, cr, uid, ids, partner_id, context=None):
|
||||
partner = None
|
||||
if partner_id:
|
||||
|
|
Loading…
Reference in New Issue