As of https://github.com/odoo/odoo/pull/114024, `display_name` is implicit in every form view (see the use of addFieldDependencies in the Form controller). Therefore, when you create a new record for this model, it calls the first `onchange`, which will compute display_name for a new record (id without origin). Some `_compute_display_name` don't handle new records correctly and raise a traceback. These models are sometimes directly accessible: - Accounting > Account Group > New => Traceback - Contact > Contact Tags > New => Traceback Other models are inaccessible by default (no view to access or create a new record), but if someone creates a view for them with studio (or modifies an existing one to allow creation): - `crm.iap.lead.role` - `crm.iap.lead.seniority` - `chatbot.script.answer` - `payment.token` Change the code of `_compute_display_name` on these models to be more defensive and avoid (potential) tracebacks. Similarly, change the `convert_to_display_name` of `fields.Datetime` to take into account `None` value. closes odoo/odoo#139592 Related: odoo/enterprise#49721 Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
import contextlib
|
|
|
|
from odoo.exceptions import UserError
|
|
from odoo.tests.common import TransactionCase, tagged
|
|
|
|
|
|
IGNORE_MODEL_NAMES = {
|
|
'ir.attachment',
|
|
'test_new_api.attachment',
|
|
'payment.link.wizard',
|
|
'account.multicurrency.revaluation.wizard',
|
|
'account_followup.manual_reminder',
|
|
}
|
|
|
|
@tagged('-at_install', 'post_install')
|
|
class TestEveryModel(TransactionCase):
|
|
|
|
def test_display_name_new_record(self):
|
|
for model_name in self.registry:
|
|
model = self.env[model_name]
|
|
if model._abstract or not model._auto or model_name in IGNORE_MODEL_NAMES:
|
|
continue
|
|
|
|
with self.subTest(
|
|
msg="`_compute_display_name` doesn't work with new record (first onchange call).",
|
|
model=model_name,
|
|
):
|
|
# Check that the first onchange with display_name works on every models
|
|
# OR it will fail anyway when people will use click on New
|
|
fields_used = model._fields['display_name'].get_depends(model)[0]
|
|
fields_used = [f.split('.', 1)[0] for f in fields_used]
|
|
fields_spec = dict.fromkeys(fields_used + ['display_name'], {})
|
|
with contextlib.suppress(UserError):
|
|
model.onchange({}, [], fields_spec)
|