diff --git a/.tx/config b/.tx/config index 49e5dfff215..0455f8de589 100644 --- a/.tx/config +++ b/.tx/config @@ -107,9 +107,9 @@ file_filter = addons/barcodes/i18n/.po source_file = addons/barcodes/i18n/barcodes.pot source_lang = en -[odoo-master.base_action_rule] -file_filter = addons/base_action_rule/i18n/.po -source_file = addons/base_action_rule/i18n/base_action_rule.pot +[odoo-master.base_automation] +file_filter = addons/base_automation/i18n/.po +source_file = addons/base_automation/i18n/base_automation.pot source_lang = en [odoo-master.base_gengo] diff --git a/addons/account_asset/data/account_asset_data.xml b/addons/account_asset/data/account_asset_data.xml index f858fbb2237..3f9a28987df 100644 --- a/addons/account_asset/data/account_asset_data.xml +++ b/addons/account_asset/data/account_asset_data.xml @@ -1,13 +1,13 @@ - - Generate Asset Entries + + Account Asset: Generate asset entries + + code + model._cron_generate_entries() 1 months -1 - - - \ No newline at end of file diff --git a/addons/base_action_rule/data/base_action_rule_demo.xml b/addons/base_action_rule/data/base_action_rule_demo.xml deleted file mode 100644 index d59b7ba45ff..00000000000 --- a/addons/base_action_rule/data/base_action_rule_demo.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - Test lead in state 'draft' - base.action.rule.lead.test - [('state', '=', 'draft')] - - - - Test lead in state 'open' - base.action.rule.lead.test - [('state', '=', 'open')] - - - - Test lead in state 'done' - base.action.rule.lead.test - [('state', '=', 'done')] - - - - Test rule on create - on_create - - - - - - - Test rule on write - on_write - - - - - - - - Test rule on recompute - on_write - - - [('customer', '=', True)] - - - - Test rule on secondary record - on_create - - - - diff --git a/addons/base_action_rule/security/ir.model.access.csv b/addons/base_action_rule/security/ir.model.access.csv deleted file mode 100644 index cec3f676e0b..00000000000 --- a/addons/base_action_rule/security/ir.model.access.csv +++ /dev/null @@ -1,5 +0,0 @@ -id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_base_action_rule,base.action.rule,model_base_action_rule,,1,0,0,0 -access_base_action_rule_config,base.action.rule config,model_base_action_rule,base.group_system,1,1,1,1 -access_base_action_rule_lead_test,access_base_action_rule_lead_test,model_base_action_rule_lead_test,base.group_system,1,1,1,1 -access_base_action_rule_line_test,access_base_action_rule_line_test,model_base_action_rule_line_test,base.group_system,1,1,1,1 diff --git a/addons/base_action_rule/views/base_action_rule_view.xml b/addons/base_action_rule/views/base_action_rule_view.xml deleted file mode 100644 index 8418c07b632..00000000000 --- a/addons/base_action_rule/views/base_action_rule_view.xml +++ /dev/null @@ -1,138 +0,0 @@ - - - - - base.action.rule.form - base.action.rule - -
- - -
-
-
- - - - base.action.rule.tree - base.action.rule - - - - - - - - - - - - - base.action.rule.search - base.action.rule - - - - - - - - - - - Automated Actions - base.action.rule - form - tree,form - - -

- Click to setup a new automated action rule. -

- Use automated actions to automatically trigger actions for - various screens. Example: a lead created by a specific user may - be automatically set to a specific sales channel, or an - opportunity which still has status pending after 14 days might - trigger an automatic reminder email. -

-
-
- - - -
diff --git a/addons/base_action_rule/__init__.py b/addons/base_automation/__init__.py similarity index 100% rename from addons/base_action_rule/__init__.py rename to addons/base_automation/__init__.py diff --git a/addons/base_action_rule/__manifest__.py b/addons/base_automation/__manifest__.py similarity index 85% rename from addons/base_action_rule/__manifest__.py rename to addons/base_automation/__manifest__.py index 5452547618e..82d32552ecb 100644 --- a/addons/base_action_rule/__manifest__.py +++ b/addons/base_automation/__manifest__.py @@ -18,10 +18,10 @@ trigger an automatic reminder email. 'depends': ['base', 'resource', 'mail'], 'data': [ 'security/ir.model.access.csv', - 'data/base_action_rule_data.xml', - 'views/base_action_rule_view.xml', + 'data/base_automation_data.xml', + 'views/base_automation_view.xml', ], 'demo': [ - 'data/base_action_rule_demo.xml', + 'data/base_automation_demo.xml', ], } diff --git a/addons/base_action_rule/data/base_action_rule_data.xml b/addons/base_automation/data/base_automation_data.xml similarity index 53% rename from addons/base_action_rule/data/base_action_rule_data.xml rename to addons/base_automation/data/base_automation_data.xml index afcc01447a4..2cf13f4617e 100644 --- a/addons/base_action_rule/data/base_action_rule_data.xml +++ b/addons/base_automation/data/base_automation_data.xml @@ -1,18 +1,16 @@ - - - Check Action Rules + + Base Action Rule: check and execute + + code + model._check(True) 4 hours -1 - - - - diff --git a/addons/base_automation/data/base_automation_demo.xml b/addons/base_automation/data/base_automation_demo.xml new file mode 100644 index 00000000000..a4014a64c3e --- /dev/null +++ b/addons/base_automation/data/base_automation_demo.xml @@ -0,0 +1,64 @@ + + + + Test lead in state 'draft' + base.automation.lead.test + [('state', '=', 'draft')] + + + + Test lead in state 'open' + base.automation.lead.test + [('state', '=', 'open')] + + + + Test lead in state 'done' + base.automation.lead.test + [('state', '=', 'done')] + + + + Base Automation: test rule on create + + code + + on_create + + + + + + + Base Automation: test rule on write + + code + + on_write + + + + + + + + Base Automation: test rule on recompute + + code + + on_write + + + [('customer', '=', True)] + + + + Base Automation: test rule on secondary model + + code + + on_create + + + + diff --git a/addons/base_action_rule/i18n/af.po b/addons/base_automation/i18n/af.po similarity index 100% rename from addons/base_action_rule/i18n/af.po rename to addons/base_automation/i18n/af.po diff --git a/addons/base_action_rule/i18n/ar.po b/addons/base_automation/i18n/ar.po similarity index 100% rename from addons/base_action_rule/i18n/ar.po rename to addons/base_automation/i18n/ar.po diff --git a/addons/base_action_rule/i18n/base_action_rule.pot b/addons/base_automation/i18n/base_automation.pot similarity index 100% rename from addons/base_action_rule/i18n/base_action_rule.pot rename to addons/base_automation/i18n/base_automation.pot diff --git a/addons/base_action_rule/i18n/bg.po b/addons/base_automation/i18n/bg.po similarity index 100% rename from addons/base_action_rule/i18n/bg.po rename to addons/base_automation/i18n/bg.po diff --git a/addons/base_action_rule/i18n/bs.po b/addons/base_automation/i18n/bs.po similarity index 100% rename from addons/base_action_rule/i18n/bs.po rename to addons/base_automation/i18n/bs.po diff --git a/addons/base_action_rule/i18n/ca.po b/addons/base_automation/i18n/ca.po similarity index 100% rename from addons/base_action_rule/i18n/ca.po rename to addons/base_automation/i18n/ca.po diff --git a/addons/base_action_rule/i18n/cs.po b/addons/base_automation/i18n/cs.po similarity index 100% rename from addons/base_action_rule/i18n/cs.po rename to addons/base_automation/i18n/cs.po diff --git a/addons/base_action_rule/i18n/da.po b/addons/base_automation/i18n/da.po similarity index 100% rename from addons/base_action_rule/i18n/da.po rename to addons/base_automation/i18n/da.po diff --git a/addons/base_action_rule/i18n/de.po b/addons/base_automation/i18n/de.po similarity index 100% rename from addons/base_action_rule/i18n/de.po rename to addons/base_automation/i18n/de.po diff --git a/addons/base_action_rule/i18n/el.po b/addons/base_automation/i18n/el.po similarity index 100% rename from addons/base_action_rule/i18n/el.po rename to addons/base_automation/i18n/el.po diff --git a/addons/base_action_rule/i18n/en_AU.po b/addons/base_automation/i18n/en_AU.po similarity index 100% rename from addons/base_action_rule/i18n/en_AU.po rename to addons/base_automation/i18n/en_AU.po diff --git a/addons/base_action_rule/i18n/en_GB.po b/addons/base_automation/i18n/en_GB.po similarity index 100% rename from addons/base_action_rule/i18n/en_GB.po rename to addons/base_automation/i18n/en_GB.po diff --git a/addons/base_action_rule/i18n/es.po b/addons/base_automation/i18n/es.po similarity index 100% rename from addons/base_action_rule/i18n/es.po rename to addons/base_automation/i18n/es.po diff --git a/addons/base_action_rule/i18n/es_AR.po b/addons/base_automation/i18n/es_AR.po similarity index 100% rename from addons/base_action_rule/i18n/es_AR.po rename to addons/base_automation/i18n/es_AR.po diff --git a/addons/base_action_rule/i18n/es_BO.po b/addons/base_automation/i18n/es_BO.po similarity index 100% rename from addons/base_action_rule/i18n/es_BO.po rename to addons/base_automation/i18n/es_BO.po diff --git a/addons/base_action_rule/i18n/es_CL.po b/addons/base_automation/i18n/es_CL.po similarity index 100% rename from addons/base_action_rule/i18n/es_CL.po rename to addons/base_automation/i18n/es_CL.po diff --git a/addons/base_action_rule/i18n/es_CO.po b/addons/base_automation/i18n/es_CO.po similarity index 100% rename from addons/base_action_rule/i18n/es_CO.po rename to addons/base_automation/i18n/es_CO.po diff --git a/addons/base_action_rule/i18n/es_CR.po b/addons/base_automation/i18n/es_CR.po similarity index 100% rename from addons/base_action_rule/i18n/es_CR.po rename to addons/base_automation/i18n/es_CR.po diff --git a/addons/base_action_rule/i18n/es_DO.po b/addons/base_automation/i18n/es_DO.po similarity index 100% rename from addons/base_action_rule/i18n/es_DO.po rename to addons/base_automation/i18n/es_DO.po diff --git a/addons/base_action_rule/i18n/es_EC.po b/addons/base_automation/i18n/es_EC.po similarity index 100% rename from addons/base_action_rule/i18n/es_EC.po rename to addons/base_automation/i18n/es_EC.po diff --git a/addons/base_action_rule/i18n/es_PE.po b/addons/base_automation/i18n/es_PE.po similarity index 100% rename from addons/base_action_rule/i18n/es_PE.po rename to addons/base_automation/i18n/es_PE.po diff --git a/addons/base_action_rule/i18n/es_PY.po b/addons/base_automation/i18n/es_PY.po similarity index 100% rename from addons/base_action_rule/i18n/es_PY.po rename to addons/base_automation/i18n/es_PY.po diff --git a/addons/base_action_rule/i18n/es_VE.po b/addons/base_automation/i18n/es_VE.po similarity index 100% rename from addons/base_action_rule/i18n/es_VE.po rename to addons/base_automation/i18n/es_VE.po diff --git a/addons/base_action_rule/i18n/et.po b/addons/base_automation/i18n/et.po similarity index 100% rename from addons/base_action_rule/i18n/et.po rename to addons/base_automation/i18n/et.po diff --git a/addons/base_action_rule/i18n/eu.po b/addons/base_automation/i18n/eu.po similarity index 100% rename from addons/base_action_rule/i18n/eu.po rename to addons/base_automation/i18n/eu.po diff --git a/addons/base_action_rule/i18n/fa.po b/addons/base_automation/i18n/fa.po similarity index 100% rename from addons/base_action_rule/i18n/fa.po rename to addons/base_automation/i18n/fa.po diff --git a/addons/base_action_rule/i18n/fi.po b/addons/base_automation/i18n/fi.po similarity index 100% rename from addons/base_action_rule/i18n/fi.po rename to addons/base_automation/i18n/fi.po diff --git a/addons/base_action_rule/i18n/fo.po b/addons/base_automation/i18n/fo.po similarity index 100% rename from addons/base_action_rule/i18n/fo.po rename to addons/base_automation/i18n/fo.po diff --git a/addons/base_action_rule/i18n/fr.po b/addons/base_automation/i18n/fr.po similarity index 100% rename from addons/base_action_rule/i18n/fr.po rename to addons/base_automation/i18n/fr.po diff --git a/addons/base_action_rule/i18n/fr_BE.po b/addons/base_automation/i18n/fr_BE.po similarity index 100% rename from addons/base_action_rule/i18n/fr_BE.po rename to addons/base_automation/i18n/fr_BE.po diff --git a/addons/base_action_rule/i18n/fr_CA.po b/addons/base_automation/i18n/fr_CA.po similarity index 100% rename from addons/base_action_rule/i18n/fr_CA.po rename to addons/base_automation/i18n/fr_CA.po diff --git a/addons/base_action_rule/i18n/gl.po b/addons/base_automation/i18n/gl.po similarity index 100% rename from addons/base_action_rule/i18n/gl.po rename to addons/base_automation/i18n/gl.po diff --git a/addons/base_action_rule/i18n/gu.po b/addons/base_automation/i18n/gu.po similarity index 100% rename from addons/base_action_rule/i18n/gu.po rename to addons/base_automation/i18n/gu.po diff --git a/addons/base_action_rule/i18n/he.po b/addons/base_automation/i18n/he.po similarity index 100% rename from addons/base_action_rule/i18n/he.po rename to addons/base_automation/i18n/he.po diff --git a/addons/base_action_rule/i18n/hi.po b/addons/base_automation/i18n/hi.po similarity index 100% rename from addons/base_action_rule/i18n/hi.po rename to addons/base_automation/i18n/hi.po diff --git a/addons/base_action_rule/i18n/hr.po b/addons/base_automation/i18n/hr.po similarity index 100% rename from addons/base_action_rule/i18n/hr.po rename to addons/base_automation/i18n/hr.po diff --git a/addons/base_action_rule/i18n/hu.po b/addons/base_automation/i18n/hu.po similarity index 100% rename from addons/base_action_rule/i18n/hu.po rename to addons/base_automation/i18n/hu.po diff --git a/addons/base_action_rule/i18n/id.po b/addons/base_automation/i18n/id.po similarity index 100% rename from addons/base_action_rule/i18n/id.po rename to addons/base_automation/i18n/id.po diff --git a/addons/base_action_rule/i18n/it.po b/addons/base_automation/i18n/it.po similarity index 100% rename from addons/base_action_rule/i18n/it.po rename to addons/base_automation/i18n/it.po diff --git a/addons/base_action_rule/i18n/ja.po b/addons/base_automation/i18n/ja.po similarity index 100% rename from addons/base_action_rule/i18n/ja.po rename to addons/base_automation/i18n/ja.po diff --git a/addons/base_action_rule/i18n/ka.po b/addons/base_automation/i18n/ka.po similarity index 100% rename from addons/base_action_rule/i18n/ka.po rename to addons/base_automation/i18n/ka.po diff --git a/addons/base_action_rule/i18n/kab.po b/addons/base_automation/i18n/kab.po similarity index 100% rename from addons/base_action_rule/i18n/kab.po rename to addons/base_automation/i18n/kab.po diff --git a/addons/base_action_rule/i18n/kk.po b/addons/base_automation/i18n/kk.po similarity index 100% rename from addons/base_action_rule/i18n/kk.po rename to addons/base_automation/i18n/kk.po diff --git a/addons/base_action_rule/i18n/ko.po b/addons/base_automation/i18n/ko.po similarity index 100% rename from addons/base_action_rule/i18n/ko.po rename to addons/base_automation/i18n/ko.po diff --git a/addons/base_action_rule/i18n/lt.po b/addons/base_automation/i18n/lt.po similarity index 100% rename from addons/base_action_rule/i18n/lt.po rename to addons/base_automation/i18n/lt.po diff --git a/addons/base_action_rule/i18n/lv.po b/addons/base_automation/i18n/lv.po similarity index 100% rename from addons/base_action_rule/i18n/lv.po rename to addons/base_automation/i18n/lv.po diff --git a/addons/base_action_rule/i18n/mk.po b/addons/base_automation/i18n/mk.po similarity index 100% rename from addons/base_action_rule/i18n/mk.po rename to addons/base_automation/i18n/mk.po diff --git a/addons/base_action_rule/i18n/mn.po b/addons/base_automation/i18n/mn.po similarity index 100% rename from addons/base_action_rule/i18n/mn.po rename to addons/base_automation/i18n/mn.po diff --git a/addons/base_action_rule/i18n/nb.po b/addons/base_automation/i18n/nb.po similarity index 100% rename from addons/base_action_rule/i18n/nb.po rename to addons/base_automation/i18n/nb.po diff --git a/addons/base_action_rule/i18n/nl.po b/addons/base_automation/i18n/nl.po similarity index 100% rename from addons/base_action_rule/i18n/nl.po rename to addons/base_automation/i18n/nl.po diff --git a/addons/base_action_rule/i18n/nl_BE.po b/addons/base_automation/i18n/nl_BE.po similarity index 100% rename from addons/base_action_rule/i18n/nl_BE.po rename to addons/base_automation/i18n/nl_BE.po diff --git a/addons/base_action_rule/i18n/pl.po b/addons/base_automation/i18n/pl.po similarity index 100% rename from addons/base_action_rule/i18n/pl.po rename to addons/base_automation/i18n/pl.po diff --git a/addons/base_action_rule/i18n/pt.po b/addons/base_automation/i18n/pt.po similarity index 100% rename from addons/base_action_rule/i18n/pt.po rename to addons/base_automation/i18n/pt.po diff --git a/addons/base_action_rule/i18n/pt_BR.po b/addons/base_automation/i18n/pt_BR.po similarity index 100% rename from addons/base_action_rule/i18n/pt_BR.po rename to addons/base_automation/i18n/pt_BR.po diff --git a/addons/base_action_rule/i18n/ro.po b/addons/base_automation/i18n/ro.po similarity index 100% rename from addons/base_action_rule/i18n/ro.po rename to addons/base_automation/i18n/ro.po diff --git a/addons/base_action_rule/i18n/ru.po b/addons/base_automation/i18n/ru.po similarity index 100% rename from addons/base_action_rule/i18n/ru.po rename to addons/base_automation/i18n/ru.po diff --git a/addons/base_action_rule/i18n/sk.po b/addons/base_automation/i18n/sk.po similarity index 100% rename from addons/base_action_rule/i18n/sk.po rename to addons/base_automation/i18n/sk.po diff --git a/addons/base_action_rule/i18n/sl.po b/addons/base_automation/i18n/sl.po similarity index 100% rename from addons/base_action_rule/i18n/sl.po rename to addons/base_automation/i18n/sl.po diff --git a/addons/base_action_rule/i18n/sq.po b/addons/base_automation/i18n/sq.po similarity index 100% rename from addons/base_action_rule/i18n/sq.po rename to addons/base_automation/i18n/sq.po diff --git a/addons/base_action_rule/i18n/sr.po b/addons/base_automation/i18n/sr.po similarity index 100% rename from addons/base_action_rule/i18n/sr.po rename to addons/base_automation/i18n/sr.po diff --git a/addons/base_action_rule/i18n/sr@latin.po b/addons/base_automation/i18n/sr@latin.po similarity index 100% rename from addons/base_action_rule/i18n/sr@latin.po rename to addons/base_automation/i18n/sr@latin.po diff --git a/addons/base_action_rule/i18n/sv.po b/addons/base_automation/i18n/sv.po similarity index 100% rename from addons/base_action_rule/i18n/sv.po rename to addons/base_automation/i18n/sv.po diff --git a/addons/base_action_rule/i18n/ta.po b/addons/base_automation/i18n/ta.po similarity index 100% rename from addons/base_action_rule/i18n/ta.po rename to addons/base_automation/i18n/ta.po diff --git a/addons/base_action_rule/i18n/th.po b/addons/base_automation/i18n/th.po similarity index 100% rename from addons/base_action_rule/i18n/th.po rename to addons/base_automation/i18n/th.po diff --git a/addons/base_action_rule/i18n/tr.po b/addons/base_automation/i18n/tr.po similarity index 100% rename from addons/base_action_rule/i18n/tr.po rename to addons/base_automation/i18n/tr.po diff --git a/addons/base_action_rule/i18n/uk.po b/addons/base_automation/i18n/uk.po similarity index 100% rename from addons/base_action_rule/i18n/uk.po rename to addons/base_automation/i18n/uk.po diff --git a/addons/base_action_rule/i18n/vi.po b/addons/base_automation/i18n/vi.po similarity index 100% rename from addons/base_action_rule/i18n/vi.po rename to addons/base_automation/i18n/vi.po diff --git a/addons/base_action_rule/i18n/zh_CN.po b/addons/base_automation/i18n/zh_CN.po similarity index 100% rename from addons/base_action_rule/i18n/zh_CN.po rename to addons/base_automation/i18n/zh_CN.po diff --git a/addons/base_action_rule/i18n/zh_TW.po b/addons/base_automation/i18n/zh_TW.po similarity index 100% rename from addons/base_action_rule/i18n/zh_TW.po rename to addons/base_automation/i18n/zh_TW.po diff --git a/addons/base_action_rule/models/__init__.py b/addons/base_automation/models/__init__.py similarity index 70% rename from addons/base_action_rule/models/__init__.py rename to addons/base_automation/models/__init__.py index 1f1a8086873..ef96b3be347 100644 --- a/addons/base_action_rule/models/__init__.py +++ b/addons/base_automation/models/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import base_action_rule +import base_automation +import ir_actions diff --git a/addons/base_action_rule/models/base_action_rule.py b/addons/base_automation/models/base_automation.py similarity index 76% rename from addons/base_action_rule/models/base_action_rule.py rename to addons/base_automation/models/base_automation.py index 7f13bf9f3ef..051198edc17 100644 --- a/addons/base_action_rule/models/base_action_rule.py +++ b/addons/base_automation/models/base_automation.py @@ -25,24 +25,24 @@ DATE_RANGE_FUNCTION = { } -class BaseActionRule(models.Model): - """ Base Action Rules """ - - _name = 'base.action.rule' - _description = 'Action Rules' +class BaseAutomation(models.Model): + _name = 'base.automation' + _description = 'Automated Action' _order = 'sequence' - name = fields.Char(string='Rule Name', required=True) - model_id = fields.Many2one('ir.model', string='Related Document Model', required=True, domain=[('transient', '=', False)]) - model = fields.Char(related='model_id.model', readonly=True) + action_server_id = fields.Many2one( + 'ir.actions.server', 'Server Actions', + domain="[('model_id', '=', model_id)]", + delegate=True, required=True, ondelete='restrict') active = fields.Boolean(default=True, help="When unchecked, the rule is hidden and will not be executed.") - sequence = fields.Integer(help="Gives the sequence order when displaying a list of rules.") - kind = fields.Selection([('on_create', 'On Creation'), - ('on_write', 'On Update'), - ('on_create_or_write', 'On Creation & Update'), - ('on_unlink', 'On Deletion'), - ('on_change', 'Based on Form Modification'), - ('on_time', 'Based on Timed Condition')], string='When to Run', required=True) + trigger = fields.Selection([ + ('on_create', 'On Creation'), + ('on_write', 'On Update'), + ('on_create_or_write', 'On Creation & Update'), + ('on_unlink', 'On Deletion'), + ('on_change', 'Based on Form Modification'), + ('on_time', 'Based on Timed Condition') + ], string='Trigger condition', required=True, oldname="kind") trg_date_id = fields.Many2one('ir.model.fields', string='Trigger Date', help="""When should the condition be triggered. If present, will be checked by the scheduler. If empty, will be checked at creation and update.""", @@ -55,34 +55,33 @@ class BaseActionRule(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.") - act_user_id = fields.Many2one('res.users', string='Set Responsible') - act_followers = fields.Many2many("res.partner", string="Add Followers") - server_action_ids = fields.Many2many('ir.actions.server', string='Server Actions', domain="[('model_id', '=', model_id)]", - help="Examples: email reminders, call object service, etc.") - filter_pre_id = fields.Many2one("ir.filters", string='Before Update Filter', ondelete='restrict', domain="[('model_id', '=', model_id.model)]", + 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_id.model)]", + 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.") # which fields have an impact on the registry - CRITICAL_FIELDS = ['model_id', 'active', 'kind', 'on_change_fields'] + CRITICAL_FIELDS = ['model_id', 'active', 'trigger', 'on_change_fields'] @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('kind') - def onchange_kind(self): - if self.kind in ['on_create', 'on_create_or_write', 'on_unlink']: + @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 - elif self.kind in ['on_write', 'on_create_or_write']: + 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.kind == 'on_time': + elif self.trigger == 'on_time': self.filter_pre_id = self.filter_pre_domain = False @api.onchange('filter_pre_id') @@ -95,14 +94,15 @@ class BaseActionRule(models.Model): @api.model def create(self, vals): - base_action_rule = super(BaseActionRule, self).create(vals) + vals['usage'] = 'base_automation' + base_automation = super(BaseAutomation, self).create(vals) self._update_cron() self._update_registry() - return base_action_rule + return base_automation @api.multi def write(self, vals): - res = super(BaseActionRule, self).write(vals) + res = super(BaseAutomation, self).write(vals) if set(vals).intersection(self.CRITICAL_FIELDS): self._update_cron() self._update_registry() @@ -110,7 +110,7 @@ class BaseActionRule(models.Model): @api.multi def unlink(self): - res = super(BaseActionRule, self).unlink() + res = super(BaseAutomation, self).unlink() self._update_cron() self._update_registry() return res @@ -119,8 +119,8 @@ class BaseActionRule(models.Model): """ Activate the cron job depending on whether there exists action rules based on time conditions. """ - cron = self.env.ref('base_action_rule.ir_cron_crm_action', raise_if_not_found=False) - return cron and cron.toggle(model=self._name, domain=[('kind', '=', 'on_time')]) + cron = self.env.ref('base_automation.ir_cron_data_base_automation_check', raise_if_not_found=False) + return cron and cron.toggle(model=self._name, domain=[('trigger', '=', 'on_time')]) def _update_registry(self): """ Update the registry after a modification on action rules. """ @@ -131,13 +131,13 @@ class BaseActionRule(models.Model): registry = Registry.new(self._cr.dbname) registry.signal_registry_change() - def _get_actions(self, records, kinds): - """ Return the actions of the given kinds for records' model. The + def _get_actions(self, records, triggers): + """ Return the actions of the given triggers for records' model. The returned actions' context contain an object to manage processing. """ if '__action_done' not in self._context: self = self.with_context(__action_done={}) - domain = [('model', '=', records._name), ('kind', 'in', kinds)] + domain = [('model_name', '=', records._name), ('trigger', 'in', triggers)] actions = self.with_context(active_test=True).search(domain) return actions.with_env(self.env) @@ -191,27 +191,14 @@ class BaseActionRule(models.Model): values = {} if 'date_action_last' in records._fields: values['date_action_last'] = fields.Datetime.now() - if self.act_user_id and 'user_id' in records._fields: - values['user_id'] = self.act_user_id.id if values: records.write(values) - # subscribe followers - if self.act_followers and hasattr(records, 'message_subscribe'): - followers = self.env['mail.followers'].sudo().search( - [('res_model', '=', records._name), - ('res_id', 'in', records.ids), - ('partner_id', 'in', self.act_followers.ids), - ] - ) - if not len(followers) == len(self.act_followers): - records.message_subscribe(self.act_followers.ids) - # execute server actions - if self.server_action_ids: + if self.action_server_id: for record in records: ctx = {'active_model': record._name, 'active_ids': record.ids, 'active_id': record.id} - self.server_action_ids.with_context(**ctx).run() + self.action_server_id.with_context(**ctx).run() @api.model_cr def _register_hook(self): @@ -232,7 +219,7 @@ class BaseActionRule(models.Model): @api.model def create(self, vals, **kw): # retrieve the action rules to possibly execute - actions = self.env['base.action.rule']._get_actions(self, ['on_create', 'on_create_or_write']) + actions = self.env['base.automation']._get_actions(self, ['on_create', 'on_create_or_write']) # call original method record = create.origin(self.with_env(actions.env), vals, **kw) # check postconditions, and execute actions on the records that satisfy them @@ -251,7 +238,7 @@ class BaseActionRule(models.Model): @api.multi def _write(self, vals, **kw): # retrieve the action rules to possibly execute - actions = self.env['base.action.rule']._get_actions(self, ['on_write', 'on_create_or_write']) + actions = self.env['base.automation']._get_actions(self, ['on_write', 'on_create_or_write']) records = self.with_env(actions.env) # check preconditions on records pre = {action: action._filter_pre(records) for action in actions} @@ -274,7 +261,7 @@ class BaseActionRule(models.Model): @api.multi def unlink(self, **kwargs): # retrieve the action rules to possibly execute - actions = self.env['base.action.rule']._get_actions(self, ['on_unlink']) + actions = self.env['base.automation']._get_actions(self, ['on_unlink']) records = self.with_env(actions.env) # check conditions, and execute actions on the records that satisfy them for action in actions: @@ -286,22 +273,22 @@ class BaseActionRule(models.Model): def make_onchange(action_rule_id): """ Instanciate an onchange method for the given action rule. """ - def base_action_rule_onchange(self): - action_rule = self.env['base.action.rule'].browse(action_rule_id) + def base_automation_onchange(self): + action_rule = self.env['base.automation'].browse(action_rule_id) result = {} - for server_action in action_rule.server_action_ids.with_context(active_model=self._name, onchange_self=self): - res = server_action.run() - if res: - if 'value' in res: - res['value'].pop('id', None) - self.update({key: val for key, val in res['value'].iteritems() if key in self._fields}) - if 'domain' in res: - result.setdefault('domain', {}).update(res['domain']) - if 'warning' in res: - result['warning'] = res['warning'] + server_action = action_rule.action_server_id.with_context(active_model=self._name, onchange_self=self) + res = server_action.run() + if res: + if 'value' in res: + res['value'].pop('id', None) + self.update({key: val for key, val in res['value'].iteritems() if key in self._fields}) + if 'domain' in res: + result.setdefault('domain', {}).update(res['domain']) + if 'warning' in res: + result['warning'] = res['warning'] return result - return base_action_rule_onchange + return base_automation_onchange patched_models = defaultdict(set) def patch(model, name, method): @@ -312,21 +299,21 @@ class BaseActionRule(models.Model): # retrieve all actions, and patch their corresponding model for action_rule in self.with_context({}).search([]): - Model = self.env[action_rule.model] - if action_rule.kind == 'on_create': + Model = self.env[action_rule.model_name] + if action_rule.trigger == 'on_create': patch(Model, 'create', make_create()) - elif action_rule.kind == 'on_create_or_write': + elif action_rule.trigger == 'on_create_or_write': patch(Model, 'create', make_create()) patch(Model, '_write', make_write()) - elif action_rule.kind == 'on_write': + elif action_rule.trigger == 'on_write': patch(Model, '_write', make_write()) - elif action_rule.kind == 'on_unlink': + elif action_rule.trigger == 'on_unlink': patch(Model, 'unlink', make_unlink()) - elif action_rule.kind == 'on_change': + elif action_rule.trigger == 'on_change': # register an onchange method for the action_rule method = make_onchange(action_rule.id) for field_name in action_rule.on_change_fields.split(","): @@ -352,7 +339,7 @@ class BaseActionRule(models.Model): # retrieve all the action rules to run based on a timed condition eval_context = self._get_eval_context() - for action in self.with_context(active_test=True).search([('kind', '=', 'on_time')]): + for action in self.with_context(active_test=True).search([('trigger', '=', 'on_time')]): last_run = fields.Datetime.from_string(action.last_run) or datetime.datetime.utcfromtimestamp(0) # retrieve all the records that satisfy the action's condition @@ -369,7 +356,7 @@ class BaseActionRule(models.Model): 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].with_context(context).search(domain) + records = self.env[action.model_name].with_context(context).search(domain) # determine when action should occur for the records if action.trg_date_id.name == 'date_action_last' and 'create_date' in records._fields: diff --git a/addons/base_automation/models/ir_actions.py b/addons/base_automation/models/ir_actions.py new file mode 100644 index 00000000000..67e75872873 --- /dev/null +++ b/addons/base_automation/models/ir_actions.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class ServerAction(models.Model): + _inherit = "ir.actions.server" + + usage = fields.Selection(selection_add=[('base_automation', 'Automated Action')]) diff --git a/addons/base_automation/security/ir.model.access.csv b/addons/base_automation/security/ir.model.access.csv new file mode 100644 index 00000000000..2dc7103a91b --- /dev/null +++ b/addons/base_automation/security/ir.model.access.csv @@ -0,0 +1,5 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_base_automation,base.automation,model_base_automation,,1,0,0,0 +access_base_automation_config,base.automation config,model_base_automation,base.group_system,1,1,1,1 +access_base_automation_lead_test,access_base_automation_lead_test,model_base_automation_lead_test,base.group_system,1,1,1,1 +access_base_automation_line_test,access_base_automation_line_test,model_base_automation_line_test,base.group_system,1,1,1,1 \ No newline at end of file diff --git a/addons/base_action_rule/tests/__init__.py b/addons/base_automation/tests/__init__.py similarity index 80% rename from addons/base_action_rule/tests/__init__.py rename to addons/base_automation/tests/__init__.py index f4257911f95..4232ef4d2e7 100644 --- a/addons/base_action_rule/tests/__init__.py +++ b/addons/base_automation/tests/__init__.py @@ -2,4 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import test_models -import test_base_action_rule +import test_base_automation diff --git a/addons/base_action_rule/tests/test_base_action_rule.py b/addons/base_automation/tests/test_base_automation.py similarity index 95% rename from addons/base_action_rule/tests/test_base_action_rule.py rename to addons/base_automation/tests/test_base_automation.py index 49acc7239a1..9fddfad983d 100644 --- a/addons/base_action_rule/tests/test_base_action_rule.py +++ b/addons/base_automation/tests/test_base_automation.py @@ -6,10 +6,10 @@ from odoo.tests import common @common.at_install(False) @common.post_install(True) -class base_action_rule_test(common.TransactionCase): +class base_automation_test(common.TransactionCase): def setUp(self): - super(base_action_rule_test, self).setUp() + super(base_automation_test, self).setUp() self.user_admin = self.env.ref('base.user_root') self.user_demo = self.env.ref('base.user_demo') @@ -19,7 +19,7 @@ class base_action_rule_test(common.TransactionCase): 'user_id': self.user_admin.id, } vals.update(kwargs) - return self.env['base.action.rule.lead.test'].create(vals) + return self.env['base.automation.lead.test'].create(vals) def test_00_check_to_state_open_pre(self): """ @@ -96,7 +96,7 @@ class base_action_rule_test(common.TransactionCase): """ Check that a rule is executed after creating a line record. """ - line = self.env['base.action.rule.line.test'].create({'name': "Line"}) + line = self.env['base.automation.line.test'].create({'name': "Line"}) self.assertEqual(line.user_id, self.user_demo) def test_20_indirect_line(self): diff --git a/addons/base_action_rule/tests/test_models.py b/addons/base_automation/tests/test_models.py similarity index 81% rename from addons/base_action_rule/tests/test_models.py rename to addons/base_automation/tests/test_models.py index f88d61ccd2d..36893e37447 100644 --- a/addons/base_action_rule/tests/test_models.py +++ b/addons/base_automation/tests/test_models.py @@ -5,7 +5,7 @@ from odoo import fields, models class LeadTest(models.Model): - _name = "base.action.rule.lead.test" + _name = "base.automation.lead.test" _description = "Action Rule Test" name = fields.Char(string='Subject', required=True, index=True) @@ -17,13 +17,13 @@ class LeadTest(models.Model): partner_id = fields.Many2one('res.partner', string='Partner') date_action_last = fields.Datetime(string='Last Action', readonly=True) customer = fields.Boolean(related='partner_id.customer', readonly=True, store=True) - line_ids = fields.One2many('base.action.rule.line.test', 'lead_id') + line_ids = fields.One2many('base.automation.line.test', 'lead_id') class LineTest(models.Model): - _name = "base.action.rule.line.test" + _name = "base.automation.line.test" _description = "Action Rule Line Test" name = fields.Char() - lead_id = fields.Many2one('base.action.rule.lead.test', ondelete='cascade') + lead_id = fields.Many2one('base.automation.lead.test', ondelete='cascade') user_id = fields.Many2one('res.users') diff --git a/addons/base_automation/views/base_automation_view.xml b/addons/base_automation/views/base_automation_view.xml new file mode 100644 index 00000000000..838b1a62ccb --- /dev/null +++ b/addons/base_automation/views/base_automation_view.xml @@ -0,0 +1,98 @@ + + + + + + Automations + base.automation + primary + + + +