1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
22 from osv import fields, osv
28 class project_work(osv.osv):
29 _inherit = "project.task.work"
30 _description = "Task Work"
31 def create(self, cr, uid, vals, *args, **kwargs):
33 obj = self.pool.get('hr.analytic.timesheet')
35 obj_task = self.pool.get('project.task').browse(cr, uid, vals['task_id'])
37 emp_obj = self.pool.get('hr.employee')
38 emp_id = emp_obj.search(cr, uid, [('user_id', '=', vals.get('user_id',uid))])
41 raise osv.except_osv(_('Bad Configuration !'),
42 _('No employee defined for this user. You must create one.'))
43 emp = self.pool.get('hr.employee').browse(cr, uid, emp_id[0])
44 if not emp.product_id:
45 raise osv.except_osv(_('Bad Configuration !'),
46 _('No product defined on the related employee.\nFill in the timesheet tab of the employee form.'))
48 if not emp.journal_id:
49 raise osv.except_osv(_('Bad Configuration !'),
50 _('No journal defined on the related employee.\nFill in the timesheet tab of the employee form.'))
52 a = emp.product_id.product_tmpl_id.property_account_expense.id
54 a = emp.product_id.categ_id.property_account_expense_categ.id
55 vals_line['general_account_id'] = a
56 vals_line['journal_id'] = emp.journal_id.id
58 vals_line['name']=obj_task.name + ': ' + vals['name']
59 vals_line['user_id']=vals['user_id']
60 vals_line['date']=vals['date'][:10]
61 vals_line['unit_amount']=vals['hours']
62 vals_line['account_id']=obj_task.project_id.category_id.id
63 vals_line['amount']=00.0
64 timeline_id=obj.create(cr, uid,vals_line,{})
66 vals_line['amount']=(-1) * vals['hours']*obj.browse(cr,uid,timeline_id).product_id.standard_price
67 obj.write(cr, uid,[timeline_id],vals_line,{})
68 vals['hr_analytic_timesheet_id']=timeline_id
69 return super(project_work,self).create(cr, uid, vals, *args, **kwargs)
71 def write(self, cr, uid, ids,vals,context={}):
74 task=self.pool.get('project.task.work').browse(cr,uid,ids)[0]
75 line_id=task.hr_analytic_timesheet_id
76 # in case,if a record is deleted from timesheet,but we change it from tasks!
77 list_avail_ids=self.pool.get('hr.analytic.timesheet').search(cr,uid,[])
78 if line_id in list_avail_ids:
79 obj = self.pool.get('hr.analytic.timesheet')
81 vals_line['name']=task.name+': '+vals['name']
83 vals_line['user_id']=vals['user_id']
85 vals_line['date']=vals['date'][:10]
87 vals_line['unit_amount']=vals['hours']
88 vals_line['amount']=(-1) * vals['hours'] * obj.browse(cr,uid,line_id).product_id.standard_price
89 obj.write(cr, uid,[line_id],vals_line,{})
91 return super(project_work,self).write(cr, uid, ids,vals,context)
93 def unlink(self, cr, uid, ids, *args, **kwargs):
94 timesheet_id=self.pool.get('project.task.work').browse(cr,uid,ids)[0].hr_analytic_timesheet_id
95 # delete entry from timesheet too while deleting entry to task.
96 list_avail_ids=self.pool.get('hr.analytic.timesheet').search(cr,uid,[])
97 if timesheet_id in list_avail_ids:
98 obj = self.pool.get('hr.analytic.timesheet').unlink(cr,uid,[timesheet_id],*args)
100 return super(project_work,self).unlink(cr, uid, ids,*args, **kwargs)
103 'hr_analytic_timesheet_id':fields.integer('Related Timeline Id')
109 class project_project(osv.osv):
110 _inherit = "project.project"
111 def name_get(self, cr, user, ids, context=None):
113 for project in self.browse(cr, user, ids, context):
114 if project.category_id and project.category_id.code:
115 result.append((project.id, '['+(project.category_id.code or '')+'] '+project.name))
117 result.append((project.id, '[?] '+project.name))