summaryrefslogtreecommitdiff
path: root/addons/base_automation
diff options
context:
space:
mode:
authorMoisés López <moylop260@vauxoo.com>2020-05-29 01:37:04 +0000
committerMoisés López <moylop260@vauxoo.com>2020-05-29 07:23:28 +0000
commitb6489f2763c3f062ab2e5a96b2c804b445f79809 (patch)
treeb3fcd55bfc4b5699fa6a5068a84c6963b13b47a9 /addons/base_automation
parentcfbbc229d88b74ec7080c47cf1b6555dfc3c23b4 (diff)
[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) <xmo@odoo.com>
Diffstat (limited to 'addons/base_automation')
-rw-r--r--addons/base_automation/models/base_automation.py7
1 files changed, 7 insertions, 0 deletions
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