1 ##############################################################################
3 # Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ##############################################################################
31 from osv import fields
35 class hr_employee(osv.osv):
37 _inherit = "hr.employee"
39 'product_id': fields.many2one('product.product', 'Product'),
40 'journal_id': fields.many2one('account.analytic.journal', 'Analytic Journal')
45 class hr_analytic_timesheet(osv.osv):
46 _name = "hr.analytic.timesheet"
47 _table = 'hr_analytic_timesheet'
48 _inherits = {'account.analytic.line': 'line_id'}
50 'line_id' : fields.many2one('account.analytic.line', 'Analytic line', ondelete='cascade'),
53 def unlink(self, cr, uid, ids, context={}):
55 for obj in self.browse(cr, uid, ids, context):
56 toremove[obj.line_id.id] = True
57 self.pool.get('account.analytic.line').unlink(cr, uid, toremove.keys(), context)
58 return super(hr_analytic_timesheet, self).unlink(cr, uid, ids, context)
60 def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount, unit, context={}):
61 return self.pool.get('account.analytic.line').on_change_unit_amount(cr, uid, id, prod_id, unit_amount,unit, context)
63 def _getEmployeeProduct(self, cr, uid, context):
64 emp_obj = self.pool.get('hr.employee')
65 emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
67 emp=emp_obj.browse(cr, uid, emp_id[0], context)
69 return emp.product_id.id
72 def _getEmployeeUnit(self, cr, uid, context):
73 emp_obj = self.pool.get('hr.employee')
74 emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
76 emp=emp_obj.browse(cr, uid, emp_id[0], context)
78 return emp.product_id.uom_id.id
81 def _getGeneralAccount(self, cr, uid, context):
82 emp_obj = self.pool.get('hr.employee')
83 emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
85 emp = self.pool.get('hr.employee').browse(cr, uid, emp_id[0], context=context)
86 if bool(emp.product_id):
87 a = emp.product_id.product_tmpl_id.property_account_income
89 a = emp.product_id.categ_id.property_account_income_categ
93 def _getAnalyticJournal(self, cr, uid, context):
94 emp_obj = self.pool.get('hr.employee')
95 emp_id = emp_obj.search(cr, uid, [('user_id', '=', uid)])
97 emp = self.pool.get('hr.employee').browse(cr, uid, emp_id[0], context=context)
99 return emp.journal_id.id
104 'product_uom_id' : _getEmployeeUnit,
105 'product_id' : _getEmployeeProduct,
106 'general_account_id' : _getGeneralAccount,
107 'journal_id' : _getAnalyticJournal,
108 'user_id' : lambda obj, cr, uid, ctx : uid,
111 def on_change_account_id(self, cr, uid, ids, account_id):
115 account = self.pool.get('account.analytic.account').read(cr, uid, [account_id], ['name'])[0]['name']
116 user = self.pool.get('res.users').read(cr, uid, [uid], ['name'])[0]['name']
117 return {'value' : {'name' : '%s (%s)' % (account, user)}}
118 hr_analytic_timesheet()