From 9bb9be2a008da9643d60ee9443d24c92d379e968 Mon Sep 17 00:00:00 2001 From: Antoine Prieels Date: Mon, 5 Oct 2020 11:17:44 +0000 Subject: [PATCH] [FIX] adyen_platforms: Fixes following the review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes odoo/odoo#59122 X-original-commit: e9a075b996886851b3e5134d996db36376a68964 Signed-off-by: pimodoo Signed-off-by: Antoine Prieƫls --- .../adyen_platforms/models/adyen_account.py | 35 +++++++++++-------- .../views/adyen_account_views.xml | 4 +-- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/addons/adyen_platforms/models/adyen_account.py b/addons/adyen_platforms/models/adyen_account.py index 434f9f3bc06..a119bbcbf3e 100644 --- a/addons/adyen_platforms/models/adyen_account.py +++ b/addons/adyen_platforms/models/adyen_account.py @@ -47,21 +47,28 @@ class AdyenIDMixin(models.AbstractModel): def write(self, vals): res = super(AdyenIDMixin, self).write(vals) - if vals.get('id_front'): - document_type = self.id_type - if self.id_type in ['ID_CARD', 'DRIVING_LICENSE']: - document_type += '_FRONT' - self._check_file_requirements(self.id_front, self.id_front_filename) - self._upload_photo_id(document_type, self.id_front, self.id_front_filename) - if vals.get('id_back'): - document_type = self.id_type + '_BACK' - self._check_file_requirements(self.id_back, self.id_back_filename) - self._upload_photo_id(document_type, self.id_back, self.id_back_filename) - return res + # Check file formats + if vals.get('id_front'): + self._check_file_requirements(vals.get('id_front'), vals.get('id_front_filename')) + if vals.get('id_back'): + self._check_file_requirements(vals.get('id_back'), vals.get('id_back_filename')) + + for adyen_account in self: + if vals.get('id_front'): + document_type = adyen_account.id_type + if adyen_account.id_type in ['ID_CARD', 'DRIVING_LICENSE']: + document_type += '_FRONT' + adyen_account._upload_photo_id(document_type, adyen_account.id_front, adyen_account.id_front_filename) + if vals.get('id_back') and adyen_account.id_type in ['ID_CARD', 'DRIVING_LICENSE']: + document_type = adyen_account.id_type + '_BACK' + adyen_account._upload_photo_id(document_type, adyen_account.id_back, adyen_account.id_back_filename) + return res + + @api.model def _check_file_requirements(self, content, filename): file_extension = os.path.splitext(filename)[1] - file_size = len(content) + file_size = int(len(content) * 3/4) # Compute file_size in bytes if file_extension not in ['.jpeg', '.jpg', '.pdf', '.png']: raise ValidationError(_('Allowed file formats for photo IDs are jpeg, jpg, pdf or png')) if file_size >> 20 > 4 or (file_size >> 10 < 1 and file_extension == '.pdf') or (file_size >> 10 < 100 and file_extension != '.pdf') : @@ -222,7 +229,7 @@ class AdyenAccount(models.Model): 'documentType': document_type, 'filename': filename, }, - 'documentContent': content, + 'documentContent': content.decode(), }) def _format_data(self): @@ -471,7 +478,7 @@ class AdyenShareholder(models.Model): 'documentType': document_type, 'filename': filename, }, - 'documentContent': content, + 'documentContent': content.decode(), }) def _format_data(self): diff --git a/addons/adyen_platforms/views/adyen_account_views.xml b/addons/adyen_platforms/views/adyen_account_views.xml index 0eb10fb6752..d6b650a219f 100644 --- a/addons/adyen_platforms/views/adyen_account_views.xml +++ b/addons/adyen_platforms/views/adyen_account_views.xml @@ -106,8 +106,8 @@
- - + +