odoo/odoo#190152

Created by fw-bot
Merged at 0006efba8d8b5d414541bc3d1e027f8e728cb1ca

Statuses:

label
odoo-dev:18.0-17.0-sentry-6088927895-keyerror-loyalty-alsh-3lBc-fw
head
5bb7d95bc273e86e607105d8833437c6319c0d3e
merged
1 year ago by Bugfix, Altaf Shaik (alsh)
odoo/odoo
17.0 #189864
saas-17.2 #190128
saas-17.4 #190135
18.0 #190152
saas-18.2
saas-18.3
saas-18.4
19.0
master #190153

[FW][FIX] mail, loyalty: cascade mail template if model used in temp is uninstalled

A traceback error occurs when the user uninstalls the model used in the mail template
referenced in the loyalty program.

To reproduce this issue:

1) Install sale, stock, and enable loyalty from settings
2) Create a new loyalty record from sale/product/discount & Loyalty
3) Set program type as loyalty cards and add mail template from communication
4) Open the selected mail template and change the model to the stock lot
5) Now uninstall the stock module and open the above loyalty record
6) From the Loyalty Cards stat button create a record with a partner

Error:-

KeyError: False

We used the stock lot in the mail template. However, when the user uninstalls
the stock module, the value of model_id will be set to False in that mail template,
which leads to the traceback mentioned above from the code below.

https://github.com/odoo/odoo/blob/28815810d9835772aa2fbe72339360f0771634a9/addons/mail/models/mail_template.py#L574-L575

We can resolve this issue by applying ondelete equals to cascade on model_id and
template_id of the mail_template and the loyalty_mail respectively.

As the model is deleted, mail template and loyalty mail must also deleted

Note:-
We already solved a similar type issue from this PR #180307

sentry-6088927895

Forward-Port-Of: #189864