diff options
| author | Raphael Collet <rco@odoo.com> | 2020-02-06 15:36:03 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-07-24 08:37:45 +0000 |
| commit | 4147f1d313f64fb6f2746cf4b55da77dbd0c23b0 (patch) | |
| tree | 5673930f3c10a1b29ddc675be0298b81270d03c0 | |
| parent | e1f514f100dc70c1a4b324e8e1df16b7009eb9de (diff) | |
[FIX] core: make check_company's error message clearer
Make the error message more comprehensible for users, using the record's
display name, the company's name, the field's label and value.
Incompatible companies on records:
- 'Foo' belongs to company 'X' and 'Contact' (partner_id: 'Bar')
belongs to another company.
closes odoo/odoo#54883
X-original-commit: e410c90bbddb581100d170bf8180e790bb7af5fd
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
| -rw-r--r-- | odoo/addons/base/i18n/base.pot | 27 | ||||
| -rw-r--r-- | odoo/models.py | 47 |
2 files changed, 40 insertions, 34 deletions
diff --git a/odoo/addons/base/i18n/base.pot b/odoo/addons/base/i18n/base.pot index b7a542202b4..7ebb1f343ad 100644 --- a/odoo/addons/base/i18n/base.pot +++ b/odoo/addons/base/i18n/base.pot @@ -5898,6 +5898,14 @@ msgid ", required" msgstr "" #. module: base +#: code:addons/models.py:0 +#, python-format +msgid "" +"- %(record)r belongs to company %(company)r and %(field)r (%(fname)s: " +"%(values)s) belongs to another company." +msgstr "" + +#. module: base #: code:addons/model.py:0 #, python-format msgid "" @@ -5906,6 +5914,14 @@ msgid "" msgstr "" #. module: base +#: code:addons/models.py:0 +#, python-format +msgid "" +"- Record is company %(company)r and %(field)r (%(fname)s: %(values)s) " +"belongs to another company." +msgstr "" + +#. module: base #: model_terms:ir.ui.view,arch_db:base.report_irmodeloverview msgid "- domain =" msgstr "" @@ -21687,17 +21703,6 @@ msgid "Somalia" msgstr "" #. module: base -#: code:addons/models.py:0 -#, python-format -msgid "" -"Some records are incompatible with the company of the %(document_descr)s.\n" -"\n" -"Incompatibilities:\n" -"Fields: %(fields)s\n" -"Record ids: %(records)s\n" -msgstr "" - -#. module: base #: model:ir.model.fields,help:base.field_res_bank__bic #: model:ir.model.fields,help:base.field_res_partner_bank__bank_bic msgid "Sometimes called BIC or Swift." diff --git a/odoo/models.py b/odoo/models.py index 44413e31cb9..a5371e03327 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -3211,8 +3211,7 @@ Fields: if not (regular_fields or property_fields): return - inconsistent_fields = set() - inconsistent_recs = self.browse() + inconsistencies = [] for record in self: company = record.company_id if record._name != 'res.company' else record # The first part of the check verifies that all records linked via relation fields are compatible @@ -3222,11 +3221,9 @@ Fields: # Special case with `res.users` since an user can belong to multiple companies. if corecord._name == 'res.users' and corecord.company_ids: if not (company <= corecord.company_ids): - inconsistent_fields.add(name) - inconsistent_recs |= record + inconsistencies.append((record, name, corecord)) elif not (corecord.company_id <= company): - inconsistent_fields.add(name) - inconsistent_recs |= record + inconsistencies.append((record, name, corecord)) # The second part of the check (for property / company-dependent fields) verifies that the records # linked via those relation fields are compatible with the company that owns the property value, i.e. # the company for which the value is being assigned, i.e: @@ -3237,24 +3234,28 @@ Fields: corecord = record.sudo()[name] if corecord._name == 'res.users' and corecord.company_ids: if not (company <= corecord.company_ids): - inconsistent_fields.add(name) - inconsistent_recs |= record + inconsistencies.append((record, name, corecord)) elif not (corecord.company_id <= company): - inconsistent_fields.add(name) - inconsistent_recs |= record - - if inconsistent_fields: - message = _("""Some records are incompatible with the company of the %(document_descr)s. - -Incompatibilities: -Fields: %(fields)s -Record ids: %(records)s -""") - raise UserError(message % { - 'document_descr': self.env['ir.model']._get(self._name).name, - 'fields': ', '.join(sorted(inconsistent_fields)), - 'records': ', '.join([str(a) for a in inconsistent_recs.ids[:6]]), - }) + inconsistencies.append((record, name, corecord)) + + if inconsistencies: + lines = [_("Incompatible companies on records:")] + company_msg = _("- Record is company %(company)r and %(field)r (%(fname)s: %(values)s) belongs to another company.") + record_msg = _("- %(record)r belongs to company %(company)r and %(field)r (%(fname)s: %(values)s) belongs to another company.") + for record, name, corecords in inconsistencies[:5]: + if record._name == 'res.company': + msg, company = company_msg, record + else: + msg, company = record_msg, record.company_id + field = self.env['ir.model.fields']._get(self._name, name) + lines.append(msg % { + 'record': record.display_name, + 'company': company.display_name, + 'field': field.field_description, + 'fname': field.name, + 'values': ", ".join(repr(rec.display_name) for rec in corecords), + }) + raise UserError("\n".join(lines)) @api.model def check_access_rights(self, operation, raise_exception=True): |
