[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

closes odoo/odoo#26833
This commit is contained in:
Nikunj Ladava
2018-09-10 09:10:13 +00:00
committed by Goffin Simon
parent e2819a234c
commit ec803cc1a0
+6 -2
View File
@@ -196,9 +196,13 @@ class PaymentAcquirer(models.Model):
def _check_required_if_provider(self):
""" If the field has 'required_if_provider="<provider>"' attribute, then it
required if record.provider is <provider>. """
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 = [