[FIX] pos_adyen: Fix the last status deleted

Actually the last status is deleted by the fist request who can reach it
So if a request is lost the answer too

With this fix we delete the last response only when we start a new one

closes odoo/odoo#79706

X-original-commit: 63abab836d95df9a45f6f7d038bb18df88f864b4
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
This commit is contained in:
lejeune quentin
2021-11-12 15:48:07 +00:00
committed by Joseph Caburnay
parent 8f73a13c71
commit 5a431ff23e
2 changed files with 7 additions and 2 deletions
@@ -78,7 +78,6 @@ class PosPaymentMethod(models.Model):
latest_response = self.sudo().adyen_latest_response
latest_response = json.loads(latest_response) if latest_response else False
self.sudo().adyen_latest_response = '' # avoid handling old responses multiple times
return {
'latest_response': latest_response,
@@ -87,6 +86,9 @@ class PosPaymentMethod(models.Model):
def proxy_adyen_request(self, data, operation=False):
''' Necessary because Adyen's endpoints don't have CORS enabled '''
if data['SaleToPOIRequest']['MessageHeader']['MessageCategory'] == 'Payment': # Clear only if it is a payment request
self.sudo().adyen_latest_response = '' # avoid handling old responses multiple times
if not operation:
operation = 'terminal_request'
@@ -197,6 +197,9 @@ var PaymentAdyen = PaymentInterface.extend({
self.poll_error_order = self.pos.get_order();
return self._handle_odoo_connection_failure(data);
}
// This is to make sure that if 'data' is not an instance of Error (i.e. timeout error),
// this promise don't resolve -- that is, it doesn't go to the 'then' clause.
return Promise.reject(data);
}).then(function (status) {
var notification = status.latest_response;
var last_diagnosis_service_id = status.last_received_diagnosis_id;
@@ -302,7 +305,7 @@ var PaymentAdyen = PaymentInterface.extend({
self.polling = setInterval(function () {
self._poll_for_response(resolve, reject);
}, 3000);
}, 5500);
});
// make sure to stop polling when we're done