From 3f413ca3dad0778f490d340fc74d18f81405090d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Dufays Date: Wed, 11 Jan 2023 08:02:48 +0000 Subject: [PATCH] [FIX] mail: fix incorrect view form for partner auto creation This fixes the problem of the full res_partner form being displayed instead of the simplified one in some cases (and vice-versa). The problem can be reproduced by the following steps: - launch odoo without xml dev_mode enabled (otherwise the cache is disabled) - in helpdesk, go to an existing ticket and click on an existing customer (this will load the full form for the customer into cache) - create a new ticket by first completing name and customer name, save it - complete the email address, save it - go to "Send message" and click on the email checkbox - the full form is loaded instead of the simplified one (base.view_partner_simple_form) It is also possible to get the simple form instead of the full form by reversing the order of the visited forms. Technical note: The problem has been fixed by adding the context key "force_email" as cache key using _get_view_cache_key override. Indeed, _get_view_cache uses _get_view which result depends on that context variable in its redefinition in res_partner. Task-3024050 Part-of: odoo/odoo#105111 --- addons/mail/models/res_partner.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/mail/models/res_partner.py b/addons/mail/models/res_partner.py index 165d99c4fe5..6edb1893dac 100644 --- a/addons/mail/models/res_partner.py +++ b/addons/mail/models/res_partner.py @@ -75,6 +75,11 @@ class Partner(models.Model): # ------------------------------------------------------------ # ORM # ------------------------------------------------------------ + @api.model + def _get_view_cache_key(self, view_id=None, view_type='form', **options): + """Add context variable force_email in the key as _get_view depends on it.""" + key = super()._get_view_cache_key(view_id, view_type, **options) + return key + (self._context.get('force_email'),) @api.model @api.returns('self', lambda value: value.id)