[IMP]: base_action_rule: * Removed fields that are not in the crm.case,

* Added a domain to be applied on the object, for the conditions

bzr revid: rpa@tinyerp.com-20100427101934-3envktbthc7w3n3o
This commit is contained in:
rpa (Open ERP)
2010-04-27 15:49:34 +05:30
parent 5da6db1f9a
commit c2b5890db2
3 changed files with 31 additions and 53 deletions
+12 -35
View File
@@ -44,15 +44,6 @@ class base_action_rule(osv.osv):
return self.state_get(cr, uid, context=context)
def _priority_get(self, cr, uid, context={}):
""" Get Priority
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param context: A standard dictionary for contextual values """
return self.priority_get(cr, uid, context=context)
def state_get(self, cr, uid, context={}):
""" Get State
@param self: The object pointer
@@ -62,15 +53,6 @@ class base_action_rule(osv.osv):
return [('','')]
def priority_get(self, cr, uid, context={}):
""" Get Priority
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param context: A standard dictionary for contextual values """
return [('','')]
_columns = {
'name': fields.many2one('ir.model', 'Model', required=True),
'max_level': fields.integer('Max Level', help='Specifies maximum level.'),
@@ -79,7 +61,6 @@ class base_action_rule(osv.osv):
it will allow you to hide the rule without removing it."),
'sequence': fields.integer('Sequence', help="Gives the sequence order when\
displaying a list of rules."),
'trg_date_type': fields.selection([
('none','None'),
('create','Creation Date'),
@@ -100,13 +81,10 @@ class base_action_rule(osv.osv):
'trg_partner_categ_id': fields.many2one('res.partner.category', 'Partner Category'),
'trg_state_from': fields.selection(_state_get, 'State', size=16),
'trg_state_to': fields.selection(_state_get, 'Button Pressed', size=16),
'trg_priority_from': fields.selection(_priority_get, 'Minimum Priority'),
'trg_priority_to': fields.selection(_priority_get, 'Maximum Priority'),
'act_method': fields.char('Call Object Method', size=64),
'act_user_id': fields.many2one('res.users', 'Set responsible to'),
'act_state': fields.selection(_state_get, 'Set state to', size=16),
'act_priority': fields.selection(_priority_get, 'Set priority to'),
'act_email_cc': fields.char('Add watchers (Cc)', size=250, help="These people\
will receive a copy of the future communication between partner and users by email"),
@@ -131,6 +109,7 @@ class base_action_rule(osv.osv):
'server_action_id': fields.many2one('ir.actions.server','Server Action',help="Describes the\
action name." \
"eg:on which object which action to be taken on basis of which condition"),
'domain':fields.char('Domain', size=124, required=False, readonly=False),
}
_defaults = {
@@ -142,8 +121,11 @@ class base_action_rule(osv.osv):
'act_remind_partner': lambda *a: 0,
'act_remind_user': lambda *a: 0,
'act_mail_to_watchers': lambda *a: 0,
'domain': lambda *a: '[]'
}
_order = 'sequence'
def format_body(self, body):
""" Foramat Action rule's body
@param self: The object pointer """
@@ -153,7 +135,6 @@ class base_action_rule(osv.osv):
def format_mail(self, obj, body):
""" Foramat Mail
@param self: The object pointer """
data = {
'object_id': obj.id,
'object_subject': hasattr(obj, 'name') and obj.name or False,
@@ -202,6 +183,10 @@ class base_action_rule(osv.osv):
@param context: A standard dictionary for contextual values """
ok = True
if eval(action.domain):
obj_ids = obj._table.search(cr, uid, eval(action.domain), context=context)
if not obj.id in obj_ids:
ok = False
if hasattr(obj, 'user_id'):
ok = ok and (not action.trg_user_id.id or action.trg_user_id.id==obj.user_id.id)
if hasattr(obj, 'partner_id'):
@@ -219,10 +204,6 @@ class base_action_rule(osv.osv):
if state_to:
ok = ok and (not action.trg_state_to or action.trg_state_to==state_to)
if hasattr(obj, 'priority'):
ok = ok and (not action.trg_priority_from or action.trg_priority_from>=obj.priority)
ok = ok and (not action.trg_priority_to or action.trg_priority_to<=obj.priority)
reg_name = action.regex_name
result_name = True
if reg_name:
@@ -260,10 +241,6 @@ class base_action_rule(osv.osv):
obj.categ_id = action.act_categ_id
write['categ_id'] = action.act_categ_id.id
if hasattr(obj, 'priority') and action.act_priority:
obj.priority = action.act_priority
write['priority'] = action.act_priority
model_obj.write(cr, uid, [obj.id], write, context)
if hasattr(model_obj, 'remind_user') and action.act_remind_user:
@@ -295,10 +272,11 @@ class base_action_rule(osv.osv):
@param ids: List of Basic Action Rule’s IDs,
@param objects: pass objects
@param context: A standard dictionary for contextual values """
if not scrit:
scrit = []
for action in self.browse(cr, uid, ids):
cr.execute("select id from base_action_rule order by sequence")
rule_ids = map(lambda x: x[0], cr.fetchall())
for action in self.browse(cr, uid, rule_ids):
level = action.max_level
if not level:
break
@@ -342,7 +320,6 @@ class base_action_rule(osv.osv):
model_obj.write(cr, uid, [obj.id], {'date_action_next': dt}, context)
else:
ok = action.trg_date_type=='none'
if ok:
self.do_action(cr, uid, action, model_obj, obj, context)
break
@@ -16,7 +16,9 @@
<form string="Action Rule">
<field name="name" select="1"/>
<field name="active"/>
<field name="sequence"/>
<field name="max_level" />
<field name="domain" colspan="4"/>
<notebook colspan="4">
<page string="Conditions">
<group col="2" colspan="2" name="model">
@@ -34,11 +36,6 @@
<field name="trg_state_from"/>
<field name="trg_state_to"/>
</group>
<group col="2" colspan="2">
<separator colspan="4" string="Conditions on Priority Range"/>
<field name="trg_priority_from"/>
<field name="trg_priority_to"/>
</group>
<group col="2" colspan="2">
<separator colspan="4" string="Conditions on Timing"/>
<field name="trg_date_type"/>
@@ -55,7 +52,6 @@
<separator colspan="4" string="Fields to Change"/>
<field name="act_user_id"/>
<field name="act_state"/>
<field name="act_priority"/>
<separator colspan="4" string="E-Mail Reminders (includes the content of the object)"/>
<field name="act_remind_partner"/>
<field name="act_remind_attach"/>
@@ -72,7 +68,9 @@
<field name="act_mail_to_user"/>
<field name="act_mail_to_watchers"/>
<field colspan="4" name="act_mail_to_email"/>
<field colspan="4" name="act_mail_body" attrs="{'required':[('act_remind_user','=',True)]}"/>
<separator colspan="4" string="Mail Body"/>
<field colspan="4" name="act_mail_body"
nolabel="1" attrs="{'required':[('act_remind_user','=',True)]}" />
<separator colspan="4" string="Special Keywords to Be Used in The Body"/>
<label align="0.0" string="%%(object_id)s = Object ID" colspan="2"/>
<label align="0.0" string="%%(object_subject)s = Object subject" colspan="2"/>
@@ -99,7 +97,9 @@
<field name="arch" type="xml">
<tree string="Action Rule">
<field name="name" colspan="4"/>
<field name="sequence"/>
<field name="max_level"/>
<field name="domain"/>
</tree>
</field>
</record>
+12 -11
View File
@@ -180,6 +180,17 @@ class base_action_rule(osv.osv):
if not emailfrom:
raise osv.except_osv(_('Error!'),
_("No E-Mail ID Found for your Company address!"))
if hasattr(obj, 'section_id'):
smtp_pool = self.pool.get('email.smtpclient')
if obj.section_id and obj.section_id.server_id:
flag = smtp_pool.send_email(
cr=cr,
uid=uid,
server_id=obj.section_id.server_id.id,
emailto=emails,
subject=name,
body="<pre>%s</pre>" % body,
)
return tools.email_send(emailfrom, emails, name, body, reply_to=reply_to, openobject_id=str(obj.id))
def do_check(self, cr, uid, action, obj, context={}):
@@ -251,17 +262,7 @@ class base_action_rule(osv.osv):
@param context: A standard dictionary for contextual values """
res = super(base_action_rule, self).state_get(cr, uid, context=context)
return res + [('escalate','Escalate')] + crm.AVAILABLE_STATES
def priority_get(self, cr, uid, context={}):
"""@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param context: A standard dictionary for contextual values """
res = super(base_action_rule, self).priority_get(cr, uid, context=context)
return res + crm.AVAILABLE_PRIORITIES
return res + [('escalate', 'Escalate')] + crm.AVAILABLE_STATES
base_action_rule()