Merge branch 'master-automation-rem-fp'

This commit is contained in:
Fabien Pinckaers
2017-02-10 15:25:27 -08:00
4 changed files with 11 additions and 73 deletions
@@ -1,22 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="test_filter_draft" model="ir.filters">
<field name="name">Test lead in state 'draft'</field>
<field name="model_id">base.automation.lead.test</field>
<field name="domain">[('state', '=', 'draft')]</field>
</record>
<record id="test_filter_open" model="ir.filters">
<field name="name">Test lead in state 'open'</field>
<field name="model_id">base.automation.lead.test</field>
<field name="domain">[('state', '=', 'open')]</field>
</record>
<record id="test_filter_done" model="ir.filters">
<field name="name">Test lead in state 'done'</field>
<field name="model_id">base.automation.lead.test</field>
<field name="domain">[('state', '=', 'done')]</field>
</record>
<record id="test_rule_on_create" model="base.automation">
<field name="name">Base Automation: test rule on create</field>
@@ -26,7 +9,7 @@
<field name="trigger">on_create</field>
<field name="active" eval="True"/>
<field name="model_id" ref="base_automation.model_base_automation_lead_test"/>
<field name="filter_id" ref="test_filter_draft"/>
<field name="filter_domain">[('state', '=', 'draft')]</field>
</record>
<record id="test_rule_on_write" model="base.automation">
@@ -37,8 +20,8 @@
<field name="trigger">on_write</field>
<field name="active" eval="True"/>
<field name="model_id" ref="base_automation.model_base_automation_lead_test"/>
<field name="filter_pre_id" ref="test_filter_open"/>
<field name="filter_id" ref="test_filter_done"/>
<field name="filter_domain">[('state', '=', 'done')]</field>
<field name="filter_pre_domain">[('state', '=', 'open')]</field>
</record>
<record id="test_rule_on_recompute" model="base.automation">
@@ -55,14 +55,8 @@ class BaseAutomation(models.Model):
string='Delay type', default='day')
trg_date_calendar_id = fields.Many2one("resource.calendar", string='Use Calendar',
help="When calculating a day-based timed condition, it is possible to use a calendar to compute the date based on working days.")
filter_pre_id = fields.Many2one("ir.filters", string='Before Update Filter', ondelete='restrict',
domain="[('model_id', '=', model_name)]",
help="If present, this condition must be satisfied before the update of the record.")
filter_pre_domain = fields.Char(string='Before Update Domain',
help="If present, this condition must be satisfied before the update of the record.")
filter_id = fields.Many2one("ir.filters", string='Filter', ondelete='restrict',
domain="[('model_id', '=', model_name)]",
help="If present, this condition must be satisfied before executing the action rule.")
filter_domain = fields.Char(string='Domain', help="If present, this condition must be satisfied before executing the action rule.")
last_run = fields.Datetime(readonly=True, copy=False)
on_change_fields = fields.Char(string="On Change Fields Trigger", help="Comma-separated list of field names that triggers the onchange.")
@@ -72,25 +66,16 @@ class BaseAutomation(models.Model):
@api.onchange('model_id')
def onchange_model_id(self):
self.filter_pre_id = self.filter_id = False
self.model_name = self.model_id.model
@api.onchange('trigger')
def onchange_trigger(self):
if self.trigger in ['on_create', 'on_create_or_write', 'on_unlink']:
self.filter_pre_id = self.filter_pre_domain = self.trg_date_id = self.trg_date_range = self.trg_date_range_type = False
self.filter_pre_domain = self.trg_date_id = self.trg_date_range = self.trg_date_range_type = False
elif self.trigger in ['on_write', 'on_create_or_write']:
self.trg_date_id = self.trg_date_range = self.trg_date_range_type = False
elif self.trigger == 'on_time':
self.filter_pre_id = self.filter_pre_domain = False
@api.onchange('filter_pre_id')
def onchange_filter_pre_id(self):
self.filter_pre_domain = self.filter_pre_id.domain
@api.onchange('filter_id')
def onchange_filter_id(self):
self.filter_domain = self.filter_id.domain
self.filter_pre_domain = False
@api.model
def create(self, vals):
@@ -155,11 +140,7 @@ class BaseAutomation(models.Model):
def _filter_pre(self, records):
""" Filter the records that satisfy the precondition of action ``self``. """
if self.filter_pre_id and records:
domain = [('id', 'in', records.ids)] + safe_eval(self.filter_pre_id.domain, self._get_eval_context())
ctx = safe_eval(self.filter_pre_id.context)
return records.with_context(**ctx).search(domain).with_env(records.env)
elif self.filter_pre_domain and records:
if self.filter_pre_domain and records:
domain = [('id', 'in', records.ids)] + safe_eval(self.filter_pre_domain, self._get_eval_context())
return records.search(domain)
else:
@@ -167,11 +148,7 @@ class BaseAutomation(models.Model):
def _filter_post(self, records):
""" Filter the records that satisfy the postcondition of action ``self``. """
if self.filter_id and records:
domain = [('id', 'in', records.ids)] + safe_eval(self.filter_id.domain, self._get_eval_context())
ctx = safe_eval(self.filter_id.context)
return records.with_context(**ctx).search(domain).with_env(records.env)
elif self.filter_domain and records:
if self.filter_domain and records:
domain = [('id', 'in', records.ids)] + safe_eval(self.filter_domain, self._get_eval_context())
return records.search(domain)
else:
@@ -347,15 +324,6 @@ class BaseAutomation(models.Model):
context = dict(self._context)
if action.filter_domain:
domain = safe_eval(action.filter_domain, eval_context)
elif action.filter_id:
domain = safe_eval(action.filter_id.domain, eval_context)
context.update(safe_eval(action.filter_id.context))
if 'lang' not in context:
# Filters might be language-sensitive, attempt to reuse creator lang
# as we are usually running this as super-user in background
filter_meta = action.filter_id.get_metadata()[0]
user_id = (filter_meta['write_uid'] or filter_meta['create_uid'])[0]
context['lang'] = self.env['res.users'].browse(user_id).lang
records = self.env[action.model_name].with_context(context).search(domain)
# determine when action should occur for the records
@@ -19,22 +19,9 @@
<group>
<field name="trigger"/>
<label for="filter_pre_id" attrs="{'invisible': [('trigger', 'not in', ['on_write','on_create_or_write'])]}"/>
<div attrs="{'invisible': [('trigger', 'not in', ['on_write','on_create_or_write'])]}">
<field name="filter_pre_domain" widget="domain" options="{'model': 'model_name', 'in_dialog': True}"/>
<div class="oe_edit_only">Set selection based on a search filter:
<field name="filter_pre_id" domain="[('model_id', '=', model_name), '|', ('user_id', '=', uid), ('user_id', '=', False)]"
context="{'default_model_id': model_name, 'default_active': False, 'active_test': False}"/></div>
</div>
<field name="filter_pre_domain" widget="domain" options="{'model': 'model_name', 'in_dialog': True}" attrs="{'invisible': [('trigger', 'not in', ['on_write','on_create_or_write'])]}"/>
<field name="filter_domain" widget="domain" options="{'model': 'model_name', 'in_dialog': True}"/>
<label for="filter_id"/>
<div>
<field name="filter_domain" widget="domain" options="{'model': 'model_name', 'in_dialog': True}"/>
<div class="oe_edit_only">Set selection based on a search filter:
<field name="filter_id" domain="[('model_id', '=', model_name), '|', ('user_id', '=', uid), ('user_id', '=', False)]"
context="{'default_model_id': model_name, 'default_active': False, 'active_test': False}"/>
</div>
</div>
<field name="on_change_fields"
attrs="{'invisible': [('trigger', '!=', 'on_change')], 'required': [('trigger', '=', 'on_change')]}"/>
<field name="trg_date_id"
@@ -100,4 +87,4 @@
<menuitem id="menu_base_automation_form"
parent="base.menu_automation" action="base_automation_act" sequence="1"/>
</odoo>
</odoo>
+1 -1
View File
@@ -466,7 +466,7 @@ class IrActionsServer(models.Model):
('object_create', 'Create a new Record'),
('object_write', 'Update the Record'),
('multi', 'Execute several actions')], string='Action To Do',
default='code', required=True, # set default to write ?
default='object_write', required=True,
help="Type of server action. The following values are available:\n"
"- 'Execute Python Code': a block of python code that will be executed\n"
"- 'Create or Copy a new Record': create a new record with new values, or copy an existing record in your database\n"