[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#42089

X-original-commit: dd7552b1a48020f3f48cd40a5fc1cbc4c38a7f90
Signed-off-by: jev <jev-odoo@users.noreply.github.com>
This commit is contained in:
jev-odoo
2019-12-18 07:06:31 +00:00
parent 1f8706edd4
commit b308a173a6
+13 -6
View File
@@ -184,6 +184,7 @@ class TxPaypal(models.Model):
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'),
@@ -205,7 +206,6 @@ class TxPaypal(models.Model):
self.env['mail.mail'].sudo().create(mail_values).send()
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 = {
@@ -217,15 +217,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