From 86f8d9bc64aaef5b6e63b544aec863c4682ad68e Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Fri, 9 Jul 2010 17:24:22 +0530 Subject: [PATCH] [IMP]: base_action_rule: Improvement for computing regex on history and number of history bzr revid: rpa@tinyerp.com-20100709115422-hu6s5adz77qpzvk5 --- addons/base_action_rule/base_action_rule.py | 4 +++- .../base_action_rule_view.xml | 2 +- addons/crm/crm_action_rule.py | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index be1a53046a7..b0fa217e747 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -105,7 +105,9 @@ the rule to mark CC(mail to any other person defined in actions)."), 'act_mail_to_email': fields.char('Mail to these Emails', size=128, \ help="Email-id of the persons whom mail is to be sent"), 'act_mail_body': fields.text('Mail body', help="Content of mail"), - 'regex_name': fields.char('Regular Expression on Model Name', size=128), + 'regex_name': fields.char('Regex on Resource Name', size=128, help="Regular expression for mathching name of the resource\ +\ne.g.: urgent.* will search for records having name starting with urgent\ +\nNote: This is case sensitive search."), 'server_action_id': fields.many2one('ir.actions.server', 'Server Action', help="Describes the action name.\neg:on which object which action to be taken on basis of which condition"), 'filter_id':fields.many2one('ir.filters', 'Filter', required=False), 'domain':fields.char('Domain', size=124, required=False, readonly=False), diff --git a/addons/base_action_rule/base_action_rule_view.xml b/addons/base_action_rule/base_action_rule_view.xml index c9164962439..36140e62649 100644 --- a/addons/base_action_rule/base_action_rule_view.xml +++ b/addons/base_action_rule/base_action_rule_view.xml @@ -24,7 +24,7 @@ - + diff --git a/addons/crm/crm_action_rule.py b/addons/crm/crm_action_rule.py index 1f11f2c4c0c..521a183b770 100644 --- a/addons/crm/crm_action_rule.py +++ b/addons/crm/crm_action_rule.py @@ -80,6 +80,26 @@ this if you want the rule to send an email to the partner."), if hasattr(obj, 'categ_id'): ok = ok and (not action.trg_categ_id or action.trg_categ_id.id==obj.categ_id.id) + #Cheking for history + regex = action.regex_history + result_history = True + if regex: + res = False + ptrn = re.compile(str(regex)) + for history in obj.message_ids: + _result = ptrn.search(str(history.name)) + if _result: + res = True + break + result_history = res + ok = ok and (not regex or result_history) + + res_count = True + if action.trg_max_history: + res_count = False + if len(obj.message_ids) >= action.trg_max_history: + res_count = True + ok = ok and res_count return ok def do_action(self, cr, uid, action, model_obj, obj, context={}):