summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Prieels <anp@odoo.com>2020-01-29 13:31:59 +0000
committerPierre Masereel <pim@odoo.com>2020-09-29 11:44:46 +0000
commit761639b56b0c9210c77e277f01cea45725b82ef6 (patch)
treeaff1ca3a4b846d774f86c163a2801b39b2f38149
parentc7414488602d12ea91a18d3b6df69f4612b66e70 (diff)
[REV] pos_adyen: avoid concurrent updates
Revert commit e6372c3, the concurrent updates were solved by the change in the order of the lines, not by the fact that functions were defined as api.model
-rw-r--r--addons/pos_adyen/models/pos_payment_method.py38
-rw-r--r--addons/pos_adyen/static/src/js/models.js2
-rw-r--r--addons/pos_adyen/static/src/js/payment_adyen.js8
3 files changed, 15 insertions, 33 deletions
diff --git a/addons/pos_adyen/models/pos_payment_method.py b/addons/pos_adyen/models/pos_payment_method.py
index 327fc9af52d..ddc0ab395b9 100644
--- a/addons/pos_adyen/models/pos_payment_method.py
+++ b/addons/pos_adyen/models/pos_payment_method.py
@@ -40,7 +40,7 @@ class PosPaymentMethod(models.Model):
whitelisted_fields = set(('adyen_latest_response', 'adyen_latest_diagnosis'))
return super(PosPaymentMethod, self)._is_write_forbidden(fields - whitelisted_fields)
- def _adyen_diagnosis_request_data(self, pos_config_name, terminal_identifier):
+ def _adyen_diagnosis_request_data(self, pos_config_name):
service_id = ''.join(random.choices(string.ascii_letters + string.digits, k=10))
return {
"SaleToPOIRequest": {
@@ -51,7 +51,7 @@ class PosPaymentMethod(models.Model):
"MessageType": "Request",
"ServiceID": service_id,
"SaleID": pos_config_name,
- "POIID": terminal_identifier,
+ "POIID": self.adyen_terminal_identifier,
},
"DiagnosisRequest": {
"HostDiagnosisFlag": False
@@ -59,41 +59,27 @@ class PosPaymentMethod(models.Model):
}
}
- @api.model
- def get_latest_adyen_status(self, payment_method_id, pos_config_name, terminal_identifier, test_mode, api_key):
- '''See the description of proxy_adyen_request as to why this is an
- @api.model function.
- '''
+ def get_latest_adyen_status(self, pos_config_name):
+ self.ensure_one()
# Poll the status of the terminal if there's no new
# notification we received. This is done so we can quickly
# notify the user if the terminal is no longer reachable due
# to connectivity issues.
- self.proxy_adyen_request(self._adyen_diagnosis_request_data(pos_config_name, terminal_identifier),
- test_mode,
- api_key)
+ self.proxy_adyen_request(self._adyen_diagnosis_request_data(pos_config_name))
- payment_method = self.sudo().browse(payment_method_id)
- latest_response = payment_method.adyen_latest_response
+ latest_response = self.sudo().adyen_latest_response
latest_response = json.loads(latest_response) if latest_response else False
- payment_method.adyen_latest_response = '' # avoid handling old responses multiple times
+ self.adyen_latest_response = '' # avoid handling old responses multiple times
return {
'latest_response': latest_response,
- 'last_received_diagnosis_id': payment_method.adyen_latest_diagnosis,
+ 'last_received_diagnosis_id': self.adyen_latest_diagnosis,
}
- @api.model
- def proxy_adyen_request(self, data, test_mode, api_key, test_endpoint=False, live_endpoint=False):
- '''Necessary because Adyen's endpoints don't have CORS enabled. This is an
- @api.model function to avoid concurrent update errors. Adyen's
- async endpoint can still take well over a second to complete a
- request. By using @api.model and passing in all data we need from
- the POS we avoid locking the pos_payment_method table. This way we
- avoid concurrent update errors when Adyen calls us back on
- /pos_adyen/notification which will need to write on
- pos.payment.method.
- '''
+ def proxy_adyen_request(self, data, test_endpoint=False, live_endpoint=False):
+ ''' Necessary because Adyen's endpoints don't have CORS enabled '''
+ self.ensure_one()
TIMEOUT = 10
if not test_endpoint:
@@ -107,7 +93,7 @@ class PosPaymentMethod(models.Model):
_logger.info('request to adyen\n%s', pprint.pformat(data))
headers = {
- 'x-api-key': api_key,
+ 'x-api-key': self.adyen_api_key,
'Content-Type': 'application/json'
}
req = requests.post(endpoint, data=json.dumps(data), headers=headers, timeout=TIMEOUT)
diff --git a/addons/pos_adyen/static/src/js/models.js b/addons/pos_adyen/static/src/js/models.js
index 6865f795733..f2734e00a94 100644
--- a/addons/pos_adyen/static/src/js/models.js
+++ b/addons/pos_adyen/static/src/js/models.js
@@ -3,5 +3,5 @@ var models = require('point_of_sale.models');
var PaymentAdyen = require('pos_adyen.payment');
models.register_payment_method('adyen', PaymentAdyen);
-models.load_fields('pos.payment.method', ['adyen_terminal_identifier', 'adyen_test_mode', 'adyen_api_key']);
+models.load_fields('pos.payment.method', 'adyen_terminal_identifier');
});
diff --git a/addons/pos_adyen/static/src/js/payment_adyen.js b/addons/pos_adyen/static/src/js/payment_adyen.js
index df63ec49bdd..82c6a9f91ea 100644
--- a/addons/pos_adyen/static/src/js/payment_adyen.js
+++ b/addons/pos_adyen/static/src/js/payment_adyen.js
@@ -48,7 +48,7 @@ var PaymentAdyen = PaymentInterface.extend({
return rpc.query({
model: 'pos.payment.method',
method: 'proxy_adyen_request',
- args: [data, this.payment_method.adyen_test_mode, this.payment_method.adyen_api_key, test_endpoint, live_endpoint],
+ args: [[this.payment_method.id], data, test_endpoint, live_endpoint],
}, {
// When a payment terminal is disconnected it takes Adyen
// a while to return an error (~6s). So wait 10 seconds
@@ -174,11 +174,7 @@ var PaymentAdyen = PaymentInterface.extend({
return rpc.query({
model: 'pos.payment.method',
method: 'get_latest_adyen_status',
- args: [this.payment_method.id,
- this._adyen_get_sale_id(),
- this.payment_method.adyen_terminal_identifier,
- this.payment_method.adyen_test_mode,
- this.payment_method.adyen_api_key],
+ args: [[this.payment_method.id], this._adyen_get_sale_id()],
}, {
timeout: 5000,
shadow: true,