[IMP] crm*: update crm modules to new mail module (wip)
[odoo/odoo.git] / addons / crm / crm_action_rule.py
index f510ac7..c5872b1 100644 (file)
@@ -45,13 +45,12 @@ class base_action_rule(osv.osv):
         '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'),
-        'act_mail_to_partner': fields.boolean('Mail to Partner', help="Check \
-this if you want the rule to send an email to the partner."),
+        'act_mail_to_partner': fields.boolean('Mail to Partner',
+                                              help="Check this if you want the rule to send an email to the partner."),
     }
 
-
     def email_send(self, cr, uid, obj, emails, body, emailfrom=tools.config.get('email_from', False), context=None):
-        email_message_obj = self.pool.get('email.message')
+        mail_message = self.pool.get('mail.message')
         body = self.format_mail(obj, body)
         if not emailfrom:
             if hasattr(obj, 'user_id')  and obj.user_id and obj.user_id.address_id and obj.user_id.address_id.email:
@@ -64,15 +63,10 @@ this if you want the rule to send an email to the partner."),
         else:
             reply_to = emailfrom
         if not emailfrom:
-            raise osv.except_osv(_('Error!'),
-                    _("No E-Mail ID Found for your Company address!"))
-        return email_message_obj.schedule_with_attach(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, openobject_id=str(obj.id))
+            raise osv.except_osv(_('Error!'), _("No E-Mail Found for your Company address!"))
+        return mail_message.schedule_with_attach(cr, uid, emailfrom, emails, name, body, model='base.action.rule', reply_to=reply_to, res_id=str(obj.id))
 
     def do_check(self, cr, uid, action, obj, context=None):
-        """ @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"""
         ok = super(base_action_rule, self).do_check(cr, uid, action, obj, context=context)
 
         if hasattr(obj, 'section_id'):
@@ -82,7 +76,6 @@ this if you want the rule to send an email to the partner."),
 
         #Cheking for history
         regex = action.regex_history
-        result_history = True
         if regex:
             res = False
             ptrn = re.compile(str(regex))
@@ -91,23 +84,17 @@ this if you want the rule to send an email to the partner."),
                 if _result:
                     res = True
                     break
-            result_history = res
-        ok = ok and (not regex or result_history)
+            ok = ok and res
 
-        res_count = True
         if action.trg_max_history:
             res_count = False
-            history_ids = filter(lambda x: x.history, obj.message_ids)
+            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
+            ok = ok and res_count
         return ok
 
     def do_action(self, cr, uid, action, model_obj, obj, context=None):
-        """ @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).do_action(cr, uid, action, model_obj, obj, context=context)
         write = {}
 
@@ -140,22 +127,12 @@ this if you want the rule to send an email to the partner."),
 
 
     def state_get(self, cr, uid, context=None):
-        """Gets available states for crm
-        @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 """
+        """Gets available states for crm"""
         res = super(base_action_rule, self).state_get(cr, uid, context=context)
         return res  + crm.AVAILABLE_STATES
 
     def priority_get(self, cr, uid, context=None):
-        """@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
 
-base_action_rule()
-
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: