[IMP] crm: preserve action context for lost lead

Prior to this all of the context of the action called in the list
action was overriden. We now combine the action context with the
environment context.

This allows keeping the context from the XML action that defines the modal sizing.

task-3235932

closes odoo/odoo#116287

Related: odoo/upgrade#4493
Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
Renaud Thiry
2023-04-04 17:03:28 +02:00
parent 7b21be10fd
commit f91782279a
2 changed files with 9 additions and 7 deletions
+2 -7
View File
@@ -4,18 +4,13 @@
<!--
'Mark as Lost' in action dropdown
-->
<record id="action_mark_as_lost" model="ir.actions.server">
<record id="action_set_lost_with_reason" model="ir.actions.server">
<field name="name">Mark as lost</field>
<field name="model_id" ref="model_crm_lead"/>
<field name="binding_model_id" ref="crm.model_crm_lead"/>
<field name="binding_view_types">list</field>
<field name="state">code</field>
<field name="code">
if record:
action_values = env.ref('crm.crm_lead_lost_action').sudo().read()[0]
action_values.update({'context': env.context})
action = action_values
</field>
<field name="code">action = model.action_set_lost_with_reason()</field>
</record>
<record id="action_your_pipeline" model="ir.actions.server">
+7
View File
@@ -4,6 +4,7 @@
import logging
import pytz
import threading
from ast import literal_eval
from collections import OrderedDict, defaultdict
from datetime import date, datetime, timedelta
from markupsafe import Markup
@@ -997,6 +998,12 @@ class Lead(models.Model):
self.write(dict(additional_values))
return res
@api.model
def action_set_lost_with_reason(self):
action = self.env['ir.actions.act_window']._for_xml_id('crm.crm_lead_lost_action')
action.update({'context': {**self.env.context, **literal_eval(action.get('context', '{}'))}})
return action
def action_set_won(self):
""" Won semantic: probability = 100 (active untouched) """
self.action_unarchive()