[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
This commit is contained in:
Pierre-Yves Dufays
2023-02-23 14:53:57 +01:00
committed by Thibault Delavallée
parent 69011e329c
commit 3f413ca3da
+5
View File
@@ -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)