[IMP]: crm: Apply doc string + optimization
[odoo/odoo.git] / addons / crm / crm_action_rule.py
index 1e7c505..f2d5a19 100644 (file)
@@ -27,26 +27,47 @@ import tools
 import mx.DateTime
 
 from tools.translate import _
-from osv import fields 
-from osv import osv 
+from osv import fields
+from osv import osv
 from osv import orm
 from osv.orm import except_orm
 
 import crm
 
 class case(osv.osv):
+    """ Case """
+
     _inherit = 'crm.case'
+    _description = 'case'
+
     _columns = {
         'date_action_last': fields.datetime('Last Action', readonly=1),
         'date_action_next': fields.datetime('Next Action', readonly=1),
     }
 
     def remind_partner(self, cr, uid, ids, context={}, attach=False):
+
+        """
+        @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 ids: List of Remind Partner's IDs
+        @param context: A standard dictionary for contextual values
+
+        """
         return self.remind_user(cr, uid, ids, context, attach,
                 destination=False)
 
-    def remind_user(self, cr, uid, ids, context={}, attach=False, 
-            destination=True):
+    def remind_user(self, cr, uid, ids, context={}, attach=False,destination=True):
+
+        """
+        @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 ids: List of Remind user's IDs
+        @param context: A standard dictionary for contextual values
+
+        """
         for case in self.browse(cr, uid, ids):
             if not case.section_id.reply_to:
                 raise osv.except_osv(_('Error!'), ("Reply To is not specified in Section"))
@@ -83,34 +104,40 @@ class case(osv.osv):
                     raise osv.except_osv(_('Email!'),("Email Successfully Sent"))
                 else:
                     raise osv.except_osv(_('Email Fail!'),("Email is not sent successfully"))
-        return True    
+        return True
 
     def _check(self, cr, uid, ids=False, context={}):
-        '''
+        """
         Function called by the scheduler to process cases for date actions
         Only works on not done and cancelled cases
-        '''
+
+        @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
+        """
         cr.execute('select * from crm_case \
                 where (date_action_last<%s or date_action_last is null) \
                 and (date_action_next<=%s or date_action_next is null) \
                 and state not in (\'cancel\',\'done\')',
                 (time.strftime("%Y-%m-%d %H:%M:%S"),
                     time.strftime('%Y-%m-%d %H:%M:%S')))
-        ids2 = map(lambda x: x[0], cr.fetchall() or [])        
+
+        ids2 = map(lambda x: x[0], cr.fetchall() or [])
         cases = self.browse(cr, uid, ids2, context)
-        return self._action(cr, uid, cases, False, context=context)        
+        return self._action(cr, uid, cases, False, context=context)
 
-    def _action(self, cr, uid, cases, state_to, scrit=None, context={}):     
+    def _action(self, cr, uid, cases, state_to, scrit=None, context={}):
         if not context:
             context = {}
-        context['state_to'] = state_to        
+        context['state_to'] = state_to
         rule_obj = self.pool.get('base.action.rule')
         model_obj = self.pool.get('ir.model')
-        model_ids = model_obj.search(cr, uid, [('model','=',self._name)])        
+        model_ids = model_obj.search(cr, uid, [('model','=',self._name)])
         rule_ids = rule_obj.search(cr, uid, [('name','=',model_ids[0])])
         return rule_obj._action(cr, uid, rule_ids, cases, scrit=scrit, context=context)
 
-    def format_body(self, body):        
+    def format_body(self, body):
         return self.pool.get('base.action.rule').format_body(body)
 
     def format_mail(self, obj, body):
@@ -118,12 +145,19 @@ class case(osv.osv):
 case()
 
 class base_action_rule(osv.osv):
+    """ Base Action Rule """
     _inherit = 'base.action.rule'
     _description = 'Action Rules'
-    
+
     def do_check(self, cr, uid, action, obj, 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"""
+
         ok = super(base_action_rule, self).do_check(cr, uid, action, obj, 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_id'):
@@ -143,13 +177,19 @@ class base_action_rule(osv.osv):
         return ok
 
     def do_action(self, cr, uid, action, model_obj, obj, context={}):
-        res = super(base_action_rule, self).do_action(cr, uid, action, model_obj, obj, context=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).do_action(cr, uid, action, model_obj, obj, context=context)
         write = {}
-        
+
         if action.act_section_id:
             obj.section_id = action.act_section_id
-            write['section_id'] = action.act_section_id.id        
-        
+            write['section_id'] = action.act_section_id.id
+
         if hasattr(obj, 'email_cc') and action.act_email_cc:
             if '@' in (obj.email_cc or ''):
                 emails = obj.email_cc.split(",")
@@ -157,9 +197,10 @@ class base_action_rule(osv.osv):
                     write['email_cc'] = obj.email_cc+','+obj.act_email_cc
             else:
                 write['email_cc'] = obj.act_email_cc
-        
+
         model_obj.write(cr, uid, [obj.id], write, context)
         emails = []
+
         if hasattr(obj, 'email_from') and action.act_mail_to_partner:
             emails.append(obj.email_from)
         emails = filter(None, emails)
@@ -167,29 +208,44 @@ class base_action_rule(osv.osv):
             emails = list(set(emails))
             self.email_send(cr, uid, obj, emails, action.act_mail_body)
         return True
-   
-    
+
+
 base_action_rule()
 
 class base_action_rule_line(osv.osv):
+    """ Base Action Rule Line """
     _inherit = 'base.action.rule.line'
+    _description = 'Base Action Rule Line'
 
     def state_get(self, cr, uid, context={}):
-        res = super(base_action_rule_line, self).state_get(cr, uid, context=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_line, self).state_get(cr, uid, context=context)
         return res + [('escalate','Escalate')] + crm.AVAILABLE_STATES
 
     def priority_get(self, cr, uid, context={}):
-        res = super(base_action_rule_line, self).priority_get(cr, uid, context=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_line, self).priority_get(cr, uid, context=context)
         return res + crm.AVAILABLE_PRIORITIES
-    
-    _columns = {        
+
+    _columns = {
         'trg_section_id': fields.many2one('crm.case.section', 'Section'),
         'trg_max_history': fields.integer('Maximum Communication History'),
-        'trg_categ_id':  fields.many2one('crm.case.categ', 'Category'),        
+        '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 section to'),        
+        'act_section_id': fields.many2one('crm.case.section', 'Set section 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."),
     }
 
 base_action_rule_line()