Bharat Devnani (Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-708730-bde into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #708730 in OpenERP Addons: "[6.0.1] HR-Timesheets: Field "Department" is 
not pre-populated"
  https://bugs.launchpad.net/openobject-addons/+bug/708730

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-708730-bde/+merge/64658

Hello Sir,

i have applied the default value for department when user opens timesheet, and 
onchange method is also applied for department when Employee (user) is changed.

Warm Regards,
Devnani Bharat R.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-708730-bde/+merge/64658
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-708730-bde.
=== modified file 'hr_timesheet_sheet/hr_timesheet_sheet.py'
--- hr_timesheet_sheet/hr_timesheet_sheet.py	2011-04-20 16:16:56 +0000
+++ hr_timesheet_sheet/hr_timesheet_sheet.py	2011-06-15 10:16:00 +0000
@@ -321,9 +321,15 @@
             return time.strftime('%Y-12-31')
         return time.strftime('%Y-%m-%d')
 
-    def _default_employee(self,cr, uid, context=None):
+    def _default_employee(self, cr, uid, context=None):
         emp_ids = self.pool.get('hr.employee').search(cr, uid, [('user_id','=',uid)], context=context)
         return emp_ids and emp_ids[0] or False
+    
+    def _default_department(self, cr, uid, context=None):
+        emp_id = self._default_employee(cr, uid, context)
+        if emp_id:
+            return self.pool.get('hr.employee').read(cr, uid, [emp_id], context)[0]['department_id']
+        return False
 
     _defaults = {
         'date_from' : _default_date_from,
@@ -331,6 +337,7 @@
         'date_to' : _default_date_to,
         'state': 'new',
         'employee_id': _default_employee,
+        'department_id': _default_department,
         'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr_timesheet_sheet.sheet', context=c)
     }
 
@@ -382,6 +389,12 @@
                 raise osv.except_osv(_('Invalid action !'), _('Cannot delete Sheet(s) which have attendance entries encoded !'))
         return super(hr_timesheet_sheet, self).unlink(cr, uid, ids, context=context)
 
+    def onchange_department_id(self, cr, uid, ids, employee_id, context=None):
+        department_id = False
+        if employee_id:
+            department_id = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context).department_id.id or False
+        return {'value': {'department_id': department_id}}
+
 hr_timesheet_sheet()
 
 

=== modified file 'hr_timesheet_sheet/hr_timesheet_sheet_view.xml'
--- hr_timesheet_sheet/hr_timesheet_sheet_view.xml	2011-04-07 09:27:30 +0000
+++ hr_timesheet_sheet/hr_timesheet_sheet_view.xml	2011-06-15 10:16:00 +0000
@@ -66,7 +66,7 @@
                         <field name="company_id" select="1" groups="base.group_multi_company"/>
                         <field name="department_id" groups="base.group_extended"/>
                         <newline/>
-                        <field name="employee_id"/>
+                        <field name="employee_id" on_change="onchange_department_id(employee_id)"/>
                         <field name="user_id" invisible="1"/>
                         <field name="date_from"/>
                         <field name="date_to"/>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to