[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>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user