← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~jb.eficent/department-mgmt/department-mgmt-bugfix-1296055 into lp:department-mgmt

 

JB (eficent.com) has proposed merging lp:~jb.eficent/department-mgmt/department-mgmt-bugfix-1296055 into lp:department-mgmt.

Requested reviews:
  Department Core Editors (department-core-editors)

For more details, see:
https://code.launchpad.net/~jb.eficent/department-mgmt/department-mgmt-bugfix-1296055/+merge/212286

When the user_id is changed in crm.lead the application determines the section (sales team) and based on that, the department that the sales team is assigned to. If the sales team does not have an associated department the department of the employee of the salesperson is used.
See: http://www.eficent.com/openerp_en/department-management-in-openerp/

Thanks for your work!
-- 
https://code.launchpad.net/~jb.eficent/department-mgmt/department-mgmt-bugfix-1296055/+merge/212286
Your team Department Core Editors is requested to review the proposed merge of lp:~jb.eficent/department-mgmt/department-mgmt-bugfix-1296055 into lp:department-mgmt.
=== modified file 'crm_department/crm.py'
--- crm_department/crm.py	2013-05-13 08:34:13 +0000
+++ crm_department/crm.py	2014-03-22 14:11:18 +0000
@@ -3,6 +3,7 @@
 #
 #    Author: Joël Grand-guillaume (Camptocamp)
 #    Contributor: Yannick Vaucher (Camptocamp)
+#    Contributor: Eficent
 #    Copyright 2011 Camptocamp SA
 #
 #    This program is free software: you can redistribute it and/or modify
@@ -56,6 +57,28 @@
 
         return {'value': res}
 
+    def on_change_user(self, cr, uid, ids, user_id, context=None):
+        print "on_change_user"
+        """ Updates res dictionary with the department corresponding to the section """
+        if context is None:
+            context = {}
+        res = {}
+        if user_id:
+            section_ids = self.pool.get('crm.case.section').search(cr, uid, ['|', ('user_id', '=', user_id), ('member_ids', '=', user_id)], context=context)
+            for section_id in section_ids:
+                res.update({'section_id': section_id})
+                section = self.pool.get('crm.case.section').browse(cr, uid, section_id, context=context)
+                if section.department_id.id:
+                    res.update({'department_id': section.department_id.id})
+                else:
+                    employee_ids = self.pool.get('hr.employee').search(cr, uid, [('user_id','=',user_id)], context=context)
+                    for employee_id in employee_ids:
+                        employee = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context)
+                        if employee.department_id.id:
+                            res.update({'department_id': employee.department_id.id})                            
+                
+        return {'value': res}
+    
     _columns = {
         'department_id': fields.many2one('hr.department', 'Department'),
         }


Follow ups