Skip to content
Snippets Groups Projects
Commit dd7552b1 authored by jev-odoo's avatar jev-odoo
Browse files

[FIX] payment_paypal: Less confusing transaction logs


Before this commit, the log displayed "set as done"
before actually trying to put the transaction in done.
If an error then occurred in the'_set_transaction_done'
function and the transaction could not be processed,
this could lead to a misinterpretation of these logs.

This log is therefore moved after the transaction is
processed and is only displayed if it is actually successful.

This is valid for'done','pending' and'cancel'.

closes odoo/odoo#39364

Signed-off-by: default avatarRichard Mathot (rim) <rim@openerp.com>
parent bc8e21af
Branches
Tags
No related merge requests found
......@@ -191,12 +191,12 @@ class TxPaypal(models.Model):
@api.multi
def _paypal_form_validate(self, data):
status = data.get('payment_status')
former_tx_state = self.state
res = {
'acquirer_reference': data.get('txn_id'),
'paypal_txn_type': data.get('payment_type'),
}
if status in ['Completed', 'Processed']:
_logger.info('Validated Paypal payment for tx %s: set as done' % (self.reference))
try:
# dateutil and pytz don't recognize abbreviations PDT/PST
tzinfos = {
......@@ -208,15 +208,22 @@ class TxPaypal(models.Model):
date = fields.Datetime.now()
res.update(date=date)
self._set_transaction_done()
return self.write(res)
if self.state == 'done' and self.state != former_tx_state:
_logger.info('Validated Paypal payment for tx %s: set as done' % (self.reference))
return self.write(res)
return True
elif status in ['Pending', 'Expired']:
_logger.info('Received notification for Paypal payment %s: set as pending' % (self.reference))
res.update(state_message=data.get('pending_reason', ''))
self._set_transaction_pending()
return self.write(res)
if self.state == 'pending' and self.state != former_tx_state:
_logger.info('Received notification for Paypal payment %s: set as pending' % (self.reference))
return self.write(res)
return True
else:
error = 'Received unrecognized status for Paypal payment %s: %s, set as error' % (self.reference, status)
_logger.info(error)
res.update(state_message=error)
self._set_transaction_cancel()
return self.write(res)
if self.state == 'cancel' and self.state != former_tx_state:
_logger.info(error)
return self.write(res)
return True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment