From 8e6d1d7d243c2a35f34db9ab16c0136a5e0bd81a Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Thu, 7 Jan 2021 16:19:25 +0000 Subject: [PATCH] [FIX] base_automation: reset active_id(s) in onchange handler If we change ``active_model`` in context, we have to reset active_id(s), otherwise we read a random records which may not exist. STEPS: 1. Activate Developer mode 2. Go to Settings > Technical > Automation > Automated Actions 3. Define a new Automated Action with the following settings: - Model: Lead/Opportunity - Action To Do: Execute Python Code - Trigger: Based on Form Modification - Trigger Fields: Customer (crm.lead) - Python Code: ``` raise Warning(records) ``` 4. Go to Contacts, create a new contact and save it. 5. Click on the "Opportunities" Smart Button on the top left of the contact record. 6. Click "Create". BEFORE: ``records`` in context read crm.lead, while id is for res.partner record AFTER: ``records`` is None --- opw-2424392 closes odoo/odoo#64421 X-original-commit: 6fd6d68ee6eee6460ffda8b7dd691c0ef93b7a30 Signed-off-by: Ivan Yelizariev // IEL Signed-off-by: Raphael Collet (rco) --- addons/base_automation/models/base_automation.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/base_automation/models/base_automation.py b/addons/base_automation/models/base_automation.py index e21df36ee9a..201b16417f7 100644 --- a/addons/base_automation/models/base_automation.py +++ b/addons/base_automation/models/base_automation.py @@ -402,7 +402,12 @@ class BaseAutomation(models.Model): def base_automation_onchange(self): action_rule = self.env['base.automation'].browse(action_rule_id) result = {} - server_action = action_rule.sudo().action_server_id.with_context(active_model=self._name, onchange_self=self) + server_action = action_rule.sudo().action_server_id.with_context( + active_model=self._name, + active_id=self._origin.id, + active_ids=self._origin.ids, + onchange_self=self, + ) try: res = server_action.run() except Exception as e: