From b6489f2763c3f062ab2e5a96b2c804b445f79809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20L=C3=B3pez?= Date: Fri, 29 May 2020 01:37:04 +0000 Subject: [PATCH] [IMP] base_automation: Return early if there are not base.automation to process Installing base_automation module the methods: create, write, unlink and compute_field are patched. So, they will be used for all models. It is important to save resources as possible. The patched methods in base.automation read the original data before to change so run all base.automation records. But What about if there are not base.automation records? So, we can save an extra read for all models The same to pre-filter and post-filter It adds a return early in order to skip this extra task when it will be useless. closes odoo/odoo#52134 Signed-off-by: Xavier Morel (xmo) --- addons/base_automation/models/base_automation.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/base_automation/models/base_automation.py b/addons/base_automation/models/base_automation.py index 0d1e5604f88..77be0ddc76d 100644 --- a/addons/base_automation/models/base_automation.py +++ b/addons/base_automation/models/base_automation.py @@ -304,6 +304,8 @@ class BaseAutomation(models.Model): def create(self, vals_list, **kw): # retrieve the action rules to possibly execute actions = self.env['base.automation']._get_actions(self, ['on_create', 'on_create_or_write']) + if not actions: + return create.origin(self, vals_list, **kw) # call original method records = create.origin(self.with_env(actions.env), vals_list, **kw) # check postconditions, and execute actions on the records that satisfy them @@ -318,6 +320,8 @@ class BaseAutomation(models.Model): def write(self, vals, **kw): # retrieve the action rules to possibly execute actions = self.env['base.automation']._get_actions(self, ['on_write', 'on_create_or_write']) + if not (actions and self): + return write.origin(self, vals, **kw) records = self.with_env(actions.env) # check preconditions on records pre = {action: action._filter_pre(records) for action in actions} @@ -349,6 +353,9 @@ class BaseAutomation(models.Model): # retrieve the action rules to possibly execute actions = self.env['base.automation']._get_actions(self, ['on_write', 'on_create_or_write']) records = self.filtered('id').with_env(actions.env) + if not (actions and records): + _compute_field_value.origin(self, field) + return True # check preconditions on records pre = {action: action._filter_pre(records) for action in actions} # read old values before the update