diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index de3362c6644..00b179655f0 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -84,18 +84,9 @@ specifies you can put a negative number. If you need a delay before the \ trigger date, like sending a reminder 15 minutes before a meeting."), 'trg_date_range_type': fields.selection([('minutes', 'Minutes'), ('hour', 'Hours'), \ ('day', 'Days'), ('month', 'Months')], 'Delay type'), - 'trg_user_id': fields.many2one('res.users', 'Responsible'), - 'trg_partner_id': fields.many2one('res.partner', 'Partner'), - 'trg_partner_categ_id': fields.many2one('res.partner.category', 'Partner Category'), - 'trg_state_from': fields.selection(_state_get, 'and previously was', size=16), - 'trg_state_to': fields.selection(_state_get, 'Status changes to', size=16), - 'act_user_id': fields.many2one('res.users', 'Set Responsible to'), 'act_state': fields.selection(_state_get, 'Set State to', size=16), 'act_followers': fields.many2many("res.partner", string="Set Followers"), - 'regex_name': fields.char('Regex on Resource Name', size=128, help="Regular expression for matching name of the resource\ -\ne.g.: 'urgent.*' will search for records having name starting with the string 'urgent'\ -\nNote: This is case sensitive search."), 'server_action_ids': fields.one2many('ir.actions.server', 'action_rule_id', 'Server Action', help="Define Server actions.\neg:Email Reminders, Call Object Service, etc.."), #TODO: set domain [('model_id','=',model_id)] 'filter_id':fields.many2one('ir.filters', 'Postcondition Filter', required=False), #TODO: set domain [('model_id','=',model_id.model)] 'filter_pre_id': fields.many2one('ir.filters', 'Precondition Filter', required=False), @@ -290,26 +281,6 @@ trigger date, like sending a reminder 15 minutes before a meeting."), ctx.update(eval(action.filter_id.context)) obj_ids = self.pool.get(action.model_id.model).search(cr, uid, eval(action.filter_id.domain), context=ctx) ok = ok and obj.id in obj_ids - if getattr(obj, 'user_id', False): - ok = ok and (not action.trg_user_id.id or action.trg_user_id.id==obj.user_id.id) - if getattr(obj, 'partner_id', False): - ok = ok and (not action.trg_partner_id.id or action.trg_partner_id.id==obj.partner_id.id) - ok = ok and ( - not action.trg_partner_categ_id.id or - ( - obj.partner_id.id and - (action.trg_partner_categ_id.id in map(lambda x: x.id, obj.partner_id.category_id or [])) - ) - ) - reg_name = action.regex_name - result_name = True - if reg_name: - ptrn = re.compile(ustr(reg_name)) - _result = ptrn.search(ustr(obj.name)) - if not _result: - result_name = False - regex_n = not reg_name or result_name - ok = ok and regex_n return ok def do_action(self, cr, uid, action, obj, context=None): @@ -359,38 +330,10 @@ trigger date, like sending a reminder 15 minutes before a meeting."), context.update({'action': False}) return True -base_action_rule() - class actions_server(osv.osv): _inherit = 'ir.actions.server' _columns = { 'action_rule_id': fields.many2one("base.action.rule", string="Action Rule") } -actions_server() - -class ir_cron(osv.osv): - _inherit = 'ir.cron' - _init_done = False - - def _poolJobs(self, db_name, check=False): - if not self._init_done: - self._init_done = True - try: - db = pooler.get_db(db_name) - except: - return False - cr = db.cursor() - try: - next = datetime.now().strftime('%Y-%m-%d %H:00:00') - # Putting nextcall always less than current time in order to call it every time - cr.execute('UPDATE ir_cron set nextcall = \'%s\' where numbercall<>0 and active and model=\'base.action.rule\' ' % (next)) - finally: - cr.commit() - cr.close() - - super(ir_cron, self)._poolJobs(db_name, check=check) - -ir_cron() - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/base_action_rule/base_action_rule_view.xml b/addons/base_action_rule/base_action_rule_view.xml index 257465b490a..aab9ce0000c 100644 --- a/addons/base_action_rule/base_action_rule_view.xml +++ b/addons/base_action_rule/base_action_rule_view.xml @@ -23,10 +23,10 @@

- Select a filter or a timer as condition.
- To create a new filter,
- - Go to your Model's page and set the filter parameters in the "Search" view
- - In this same "Search" view, select the menu "Save Current Filter", enter the name and add the option "Share with all users"
+ Select a filter or a timer as condition.
An action rule is checked when you create or modify the "Related Document Model". The precondition filter is checked right before the modification while the postcondition filter is checked after the modification. A precondition filter will therefore not work during a creation.
+ To create a new filter:
+ - Go to your "Related Document Model" page and set the filter parameters in the "Search" view (Example of filter based on Leads/Opportunities: Creation Date "is equal to" 01/01/2012)
+ - In this same "Search" view, select the menu "Save Current Filter", enter the name (Ex: Create the 01/01/2012) and add the option "Share with all users"
The filter must therefore be available in this page.

diff --git a/addons/crm/crm_action_rule.py b/addons/crm/crm_action_rule.py index 74fc749f33c..1344b170b9a 100644 --- a/addons/crm/crm_action_rule.py +++ b/addons/crm/crm_action_rule.py @@ -35,42 +35,10 @@ class base_action_rule(osv.osv): _description = 'Action Rules' _columns = { - 'trg_section_id': fields.many2one('crm.case.section', 'Sales Team'), - 'trg_max_history': fields.integer('Maximum Communication History'), - 'trg_categ_id': fields.many2one('crm.case.categ', 'Category'), - 'regex_history' : fields.char('Regular Expression on Case History', size=128), 'act_section_id': fields.many2one('crm.case.section', 'Set Team to'), 'act_categ_id': fields.many2one('crm.case.categ', 'Set Category to'), } - def do_check(self, cr, uid, action, obj, precondition_ok=True, context=None): - ok = super(base_action_rule, self).do_check(cr, uid, action, obj, precondition_ok=precondition_ok, context=context) - - if hasattr(obj, 'section_id'): - ok = ok and (not action.trg_section_id or action.trg_section_id.id == obj.section_id.id) - if hasattr(obj, 'categ_ids'): - ok = ok and (not action.trg_categ_id or action.trg_categ_id.id in [x.id for x in obj.categ_ids]) - - #Cheking for history - regex = action.regex_history - if regex: - res = False - ptrn = re.compile(ustr(regex)) - for history in obj.message_ids: - _result = ptrn.search(ustr(history.subject)) - if _result: - res = True - break - ok = ok and res - - if action.trg_max_history: - res_count = False - history_ids = filter(lambda x: x.email_from, obj.message_ids) - if len(history_ids) <= action.trg_max_history: - res_count = True - ok = ok and res_count - return ok - def do_action(self, cr, uid, action, obj, context=None): res = super(base_action_rule, self).do_action(cr, uid, action, obj, context=context) model_obj = self.pool.get(action.model_id.model) diff --git a/addons/crm/crm_action_rule_demo.xml b/addons/crm/crm_action_rule_demo.xml index 83f5681f311..31f07e59034 100644 --- a/addons/crm/crm_action_rule_demo.xml +++ b/addons/crm/crm_action_rule_demo.xml @@ -72,7 +72,6 @@ Thanks, Set Auto Followers on leads which are urgent and come from USA. 2 - urgent.* diff --git a/addons/crm/test/process/action_rule.yml b/addons/crm/test/process/action_rule.yml deleted file mode 100644 index f76e6c250bc..00000000000 --- a/addons/crm/test/process/action_rule.yml +++ /dev/null @@ -1,20 +0,0 @@ -- - I create a record rule. -- - !python {model: base.action.rule}: | - model_ids = self.pool.get("ir.model").search(cr, uid, [('model', '=', 'crm.lead')]) - from datetime import datetime - new_id = self.create(cr, uid, {'name': 'New Rule', 'model_id': model_ids[0], 'trg_user_id': ref('base.user_root'), 'trg_partner_id': ref('base.res_partner_1'), 'act_user_id': ref('base.user_demo') }) - self._check(cr, uid) -- - I create a new lead to check the record rule. -- - !record {model: crm.lead, id: crm_lead_test_rules_id}: - name: 'Test lead rules' - partner_id: base.res_partner_1 -- - I check if the record rule is applied and the responsible is changed. -- - !python {model: crm.lead}: | - lead_user = self.browse(cr, uid, ref('crm_lead_test_rules_id')) - assert lead_user.user_id.id == ref('base.user_demo'), "Responsible of lead is not changed."