From 2ea7d9b10eadb167c417028d74596374c44d5cac Mon Sep 17 00:00:00 2001 From: Nikunj Ladava Date: Thu, 30 Aug 2018 15:24:16 +0530 Subject: [PATCH] [IMP] payment: Improved error message for an empty field in payment.acquirer form view - payment.acquirer have many fields with 'required_if_provider' attribute and while saving form it gave an error like "Required fields not filled", so it was confusing to know which required fields were empty. - after this commit, it is displayed like "Required fields not filled (field name)" opw:1881054 --- addons/payment/models/payment_acquirer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 98992c2a679..52c7b57463a 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -184,9 +184,13 @@ class PaymentAcquirer(models.Model): def _check_required_if_provider(self): """ If the field has 'required_if_provider=""' attribute, then it required if record.provider is . """ + empty_field = [] for acquirer in self: - if any(getattr(f, 'required_if_provider', None) == acquirer.provider and not acquirer[k] for k, f in self._fields.items()): - return False + for k, f in acquirer._fields.items(): + if getattr(f, 'required_if_provider', None) == acquirer.provider and not acquirer[k]: + empty_field.append(self.env['ir.model.fields'].search([('name', '=', k), ('model', '=', acquirer._name)]).field_description) + if empty_field: + raise ValidationError((', ').join(empty_field)) return True _constraints = [