summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2019-07-22 07:17:43 +0000
committerMartin Trigaux <mat@odoo.com>2019-07-22 07:17:43 +0000
commiteb4700f17f5fa2fb10e2170642b8e56291f77a36 (patch)
treeed4b365aa8e53a632f28876b9c63b8a0c20433f5
parent1e66c382380f1c9dbf40e789e7d1fcd6ebdb2dbf (diff)
parent160b7c87bb1a4eb02f323b96a8c223bdae213ea2 (diff)
[MERGE] Forward port of saas-14 to 11.0 up to 160b7c87bb1
closes odoo/odoo#35044 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
-rw-r--r--addons/l10n_be_intrastat/wizard/xml_decl.py11
-rw-r--r--addons/payment_authorize/models/payment.py29
-rw-r--r--addons/payment_authorize/views/payment_views.xml1
3 files changed, 34 insertions, 7 deletions
diff --git a/addons/l10n_be_intrastat/wizard/xml_decl.py b/addons/l10n_be_intrastat/wizard/xml_decl.py
index 86f3bda9f57..9e1e7794c8c 100644
--- a/addons/l10n_be_intrastat/wizard/xml_decl.py
+++ b/addons/l10n_be_intrastat/wizard/xml_decl.py
@@ -115,6 +115,11 @@ class XmlDeclaration(models.TransientModel):
round_digits = self._get_rounding_digits()
_round = partial(float_round, precision_digits=round_digits)
+ value, weight, supply_units = amounts
+ # Assuming weight cannot be negative
+ if weight >= 0 and weight < 0.01:
+ weight = 0.01
+
self._set_Dim(item, 'EXSEQCODE', text_type(numlgn))
self._set_Dim(item, 'EXTRF', text_type(linekey.EXTRF))
self._set_Dim(item, 'EXCNT', text_type(linekey.EXCNT))
@@ -124,9 +129,9 @@ class XmlDeclaration(models.TransientModel):
if extendedmode:
self._set_Dim(item, 'EXTPC', text_type(linekey.EXTPC))
self._set_Dim(item, 'EXDELTRM', text_type(linekey.EXDELTRM))
- self._set_Dim(item, 'EXTXVAL', text_type(_round(amounts[0], 0)).replace(".", ","))
- self._set_Dim(item, 'EXWEIGHT', text_type(_round(amounts[1], 0)).replace(".", ","))
- self._set_Dim(item, 'EXUNITS', text_type(_round(amounts[2], 0)).replace(".", ","))
+ self._set_Dim(item, 'EXTXVAL', text_type(_round(value, 0)).replace(".", ","))
+ self._set_Dim(item, 'EXWEIGHT', text_type(_round(weight, 0)).replace(".", ","))
+ self._set_Dim(item, 'EXUNITS', text_type(_round(supply_units, 0)).replace(".", ","))
def _get_intrastat_linekey(self, declcode, inv_line, dispatchmode, extendedmode):
IntrastatRegion = self.env['l10n_be_intrastat.region']
diff --git a/addons/payment_authorize/models/payment.py b/addons/payment_authorize/models/payment.py
index 58d3c4ae88e..7e4affddd53 100644
--- a/addons/payment_authorize/models/payment.py
+++ b/addons/payment_authorize/models/payment.py
@@ -24,6 +24,7 @@ class PaymentAcquirerAuthorize(models.Model):
provider = fields.Selection(selection_add=[('authorize', 'Authorize.Net')])
authorize_login = fields.Char(string='API Login Id', required_if_provider='authorize', groups='base.group_user')
authorize_transaction_key = fields.Char(string='API Transaction Key', required_if_provider='authorize', groups='base.group_user')
+ authorize_signature_key = fields.Char(string='API Signature Key', groups='base.group_user', compute="_compute_auth_signature_key", inverse="_inverse_auth_signature_key")
def _get_feature_support(self):
"""Get advanced feature support by provider.
@@ -41,6 +42,16 @@ class PaymentAcquirerAuthorize(models.Model):
res['tokenize'].append('authorize')
return res
+ def _compute_auth_signature_key(self):
+ ICP = self.env['ir.config_parameter'].sudo()
+ for acquirer in self.filtered(lambda a: a.provider == 'authorize'):
+ acquirer.authorize_signature_key = ICP.get_param('payment_authorize.signature_key_%s' % acquirer.id)
+
+ def _inverse_auth_signature_key(self):
+ ICP = self.env['ir.config_parameter'].sudo()
+ for acquirer in self.filtered(lambda a: a.provider == 'authorize'):
+ ICP.set_param('payment_authorize.signature_key_%s' % acquirer.id, acquirer.authorize_signature_key)
+
def _get_authorize_urls(self, environment):
""" Authorize URLs """
if environment == 'prod':
@@ -56,12 +67,22 @@ class PaymentAcquirerAuthorize(models.Model):
values['x_amount'],
values['x_currency_code']]).encode('utf-8')
- # [BACKWARD COMPATIBILITY] Check that the merchant did update his transaction
- # key to signature key (end of MD5 support from Authorize.net)
+ # [BACKWARD COMPATIBILITY, 2nd edition]
# The signature key is now '128-character hexadecimal format', while the
# transaction key was only 16-character.
- if len(values['x_trans_key']) == 128:
- return hmac.new(values['x_trans_key'].decode("hex").encode('utf-8'), data, hashlib.sha512).hexdigest().upper()
+ # One of 2 things should have happened:
+ # 1/ the Transaction Key has been replaced with the Signature Key value (patch from March 2019)
+ # => Use that to sign, but server-to-server won't work since it uses transaction key
+ # as its credentials
+ # 2/ the Signature key is a new field (patch from July 2019)
+ # => Use that field for the signature
+
+ # FORWARD-PORT NOTE NUMERO DOS: forward part to saas-12.4 but no further
+ if len(values['x_trans_key']) == 128 and not self.authorize_signature_key:
+ self.authorize_signature_key = values['x_trans_key'] # store in the correct field
+ return hmac.new(bytes.fromhex(values['x_trans_key']), data, hashlib.sha512).hexdigest().upper()
+ elif self.authorize_signature_key:
+ return hmac.new(bytes.fromhex(self.authorize_signature_key), data, hashlib.sha512).hexdigest().upper()
else:
return hmac.new(values['x_trans_key'].encode('utf-8'), data, hashlib.md5).hexdigest()
diff --git a/addons/payment_authorize/views/payment_views.xml b/addons/payment_authorize/views/payment_views.xml
index 0237325e0c2..b60385ed9f0 100644
--- a/addons/payment_authorize/views/payment_views.xml
+++ b/addons/payment_authorize/views/payment_views.xml
@@ -9,6 +9,7 @@
<group attrs="{'invisible': [('provider', '!=', 'authorize')]}">
<field name="authorize_login"/>
<field name="authorize_transaction_key" password="True"/>
+ <field name="authorize_signature_key" password="True"/>
<a colspan="2" href="https://www.odoo.com/documentation/user/online/ecommerce/shopper_experience/authorize.html" target="_blank">How to get paid with Authorize.Net</a>
</group>
</xpath>