Example #1
0
File: sale.py Project: newmooncn/dm
 def to_state(self,cr,uid,ids,new_state,context=None):
     '''
     Why put this variable here, because if we put thie variable as one class level,
     then the translation can not be translate to current user languange, 
     since one class instance will be init only one time and the "_()" function will run one time
     but system may be used by different languange's users         
     ''' 
     EMAIL_ACTIONS = {'review':{'msg':_('sales order submitted, need your review'),'groups':['dmp_sale_workflow.group_sale_reviewer']},
                      'engineer':{'msg':_('sales confirmed, need engineering approval'),'groups':['dmp_engineer.group_engineer_user']},
                      'account':{'msg':_('engineering approved, need accounting approval'),'groups':['account.group_account_manager']},
                      'super':{'msg':_('accounting approved, need super approval'),'groups':['dmp_base.group_super_manager']},
                      'review2draft':{'msg':_('reviewer rejected, please do re-checking'),'groups':['base.group_sale_salesman']},
                      'super2engineer':{'msg':_('Super rejected, please do engineering re-checking'),'groups':['dmp_engineer.group_engineer_user']},
                      'super2account':{'msg':_('Super rejected, please do accounting re-checking'),'groups':['account.group_account_manager']},}
             
     assert len(ids) == 1, 'This option should only be used for a single id at a time'
     vals = {'state':new_state, 'reject_message':None}
     action = new_state
     #handle the super rejection
     old_state = self.read(cr, uid, ids[0], ['state'], context=context)['state']
     if old_state == 'review' and new_state == 'draft':
         action = 'review2draft'
     if old_state == 'super' and new_state == 'engineer':
         action = 'super2engineer'
     if old_state == 'super' and new_state == 'account':
         action = 'super2account'
     self.write(cr, uid, ids, vals, context=context)
     #send email to the user group that need do next action
     utils.email_notify(cr, uid, self._name, ids, EMAIL_ACTIONS, action, subject_fields = ['name'], email_to = [], 
                        context=context, object_desc=_(self._description))
Example #2
0
 def to_state(self,cr,uid,ids,new_state,context=None):
     '''
     Why put this variable here, because if we put the variable as one class level,
     then the translation can not be translate to current user languange, 
     since one class instance will be init only one time and the "_()" function will run one time
     but system may be used by different languange's users         
     ''' 
     EMAIL_ACTIONS = {'approve':{'msg':_('confirmed, need your approval'),'groups':['dmp_base.group_super_manager']},
                      'confirmed':{'msg':_('manager approved'),'groups':['creator']},
                      'ready':{'msg':_('ready'),'groups':['creator']},
                      'approve2draft':{'msg':_('rejected by manager, please do re-checking'),'groups':['creator']}}
             
     assert len(ids) == 1, 'This option should only be used for a single id at a time'
     vals = {'state':new_state, 'reject_message':None}
     action = new_state
     #handle the super rejection
     old_state = self.read(cr, uid, ids[0], ['state'], context=context)['state']
     if old_state == 'approve' and new_state == 'draft':
         action = 'approve2draft'
     self.write(cr, uid, ids, vals, context=context)
     #send email to the user group that need do next action
     utils.email_notify(cr, uid, self._name, ids, EMAIL_ACTIONS, action, subject_fields = ['name'], email_to = [], 
                        context=context, object_desc=_('Manufacturing Order'))
Example #3
0
    def _email_notify(self, cr, uid, ids, action, context=None):
        order = self.browse(cr, uid, ids[0], context=context)
        email_to = []
        #send to manager
        if action == 'confirmed' \
            and order.employee_id \
            and order.employee_id.parent_id \
            and order.employee_id.parent_id.user_id \
            and order.employee_id.parent_id.user_id.email:
            email_to.append(order.employee_id.parent_id.user_id.email)
        #send to super manager, manager's manager
        if action == 'first_validated' \
            and order.employee_id \
            and order.employee_id.parent_id:
            manager_id_emp = order.employee_id.parent_id
            if manager_id_emp.parent_id \
                and manager_id_emp.parent_id.user_id \
                and manager_id_emp.parent_id.user_id.email:
                email_to.append(manager_id_emp.parent_id.user_id.email)
            elif manager_id_emp.user_id \
                and manager_id_emp.user_id.email:
                email_to.append(manager_id_emp.user_id.email)
        #send to the employee on the leave, final approved or refused
        if order.employee_id.user_id \
            and order.employee_id.user_id.email:
            email_to.append(order.employee_id.user_id.email)

        subject_fields = ['employee_id.name', 'name']
        utils.email_notify(cr,
                           uid,
                           self._name,
                           ids,
                           self.EMAIL_ACTIONS,
                           action,
                           subject_fields=subject_fields,
                           email_to=email_to,
                           context=context)