2008-08-24 14:45:43 +00:00
|
|
|
# -*- encoding: utf-8 -*-
|
2008-11-03 19:18:56 +00:00
|
|
|
##############################################################################
|
|
|
|
#
|
2008-12-16 20:47:32 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2009-01-04 22:12:50 +00:00
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
2008-11-03 19:18:56 +00:00
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
2008-08-24 14:45:43 +00:00
|
|
|
from osv import fields, osv
|
|
|
|
import time
|
|
|
|
import datetime
|
|
|
|
import pooler
|
2009-01-23 17:14:29 +00:00
|
|
|
import tools
|
2009-03-06 22:18:24 +00:00
|
|
|
from tools.translate import _
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class project_work(osv.osv):
|
|
|
|
_inherit = "project.task.work"
|
|
|
|
_description = "Task Work"
|
|
|
|
def create(self, cr, uid, vals, *args, **kwargs):
|
|
|
|
|
|
|
|
obj = self.pool.get('hr.analytic.timesheet')
|
2009-01-06 13:02:10 +00:00
|
|
|
vals_line = {}
|
2008-08-24 14:45:43 +00:00
|
|
|
obj_task = self.pool.get('project.task').browse(cr, uid, vals['task_id'])
|
|
|
|
|
2008-12-16 20:47:32 +00:00
|
|
|
emp_obj = self.pool.get('hr.employee')
|
2009-01-06 13:02:10 +00:00
|
|
|
emp_id = emp_obj.search(cr, uid, [('user_id', '=', vals.get('user_id', uid))])
|
2008-12-16 20:47:32 +00:00
|
|
|
|
|
|
|
if not emp_id:
|
|
|
|
raise osv.except_osv(_('Bad Configuration !'),
|
|
|
|
_('No employee defined for this user. You must create one.'))
|
|
|
|
emp = self.pool.get('hr.employee').browse(cr, uid, emp_id[0])
|
|
|
|
if not emp.product_id:
|
|
|
|
raise osv.except_osv(_('Bad Configuration !'),
|
|
|
|
_('No product defined on the related employee.\nFill in the timesheet tab of the employee form.'))
|
|
|
|
|
|
|
|
if not emp.journal_id:
|
|
|
|
raise osv.except_osv(_('Bad Configuration !'),
|
|
|
|
_('No journal defined on the related employee.\nFill in the timesheet tab of the employee form.'))
|
|
|
|
|
|
|
|
a = emp.product_id.product_tmpl_id.property_account_expense.id
|
|
|
|
if not a:
|
|
|
|
a = emp.product_id.categ_id.property_account_expense_categ.id
|
|
|
|
|
2009-01-23 17:14:29 +00:00
|
|
|
vals_line['name'] = '%s: %s' % (tools.ustr(obj_task.name), tools.ustr(vals['name']) or '/')
|
2009-01-06 13:02:10 +00:00
|
|
|
vals_line['user_id'] = vals['user_id']
|
|
|
|
vals_line['date'] = vals['date'][:10]
|
|
|
|
vals_line['unit_amount'] = vals['hours']
|
2009-04-15 14:03:32 +00:00
|
|
|
acc_id = obj_task.project_id.category_id.id
|
|
|
|
vals_line['account_id'] = acc_id
|
|
|
|
res = obj.on_change_account_id(cr, uid, False, acc_id)
|
2009-04-06 17:19:57 +00:00
|
|
|
if res.get('value'):
|
|
|
|
vals_line.update(res['value'])
|
|
|
|
vals_line['general_account_id'] = a
|
|
|
|
vals_line['journal_id'] = emp.journal_id.id
|
2009-01-06 13:02:10 +00:00
|
|
|
vals_line['amount'] = 00.0
|
|
|
|
timeline_id = obj.create(cr, uid, vals_line, {})
|
|
|
|
|
|
|
|
vals_line['amount'] = (-1) * vals['hours'] * obj.browse(cr, uid, timeline_id).product_id.standard_price
|
|
|
|
obj.write(cr, uid,[timeline_id], vals_line, {})
|
|
|
|
vals['hr_analytic_timesheet_id'] = timeline_id
|
2008-08-24 14:45:43 +00:00
|
|
|
return super(project_work,self).create(cr, uid, vals, *args, **kwargs)
|
|
|
|
|
2009-01-06 13:02:10 +00:00
|
|
|
def write(self, cr, uid, ids, vals, context=None):
|
|
|
|
vals_line = {}
|
2008-08-24 14:45:43 +00:00
|
|
|
|
2009-01-06 13:02:10 +00:00
|
|
|
task = self.pool.get('project.task.work').browse(cr, uid, ids)[0]
|
|
|
|
line_id = task.hr_analytic_timesheet_id
|
2008-08-24 14:45:43 +00:00
|
|
|
# in case,if a record is deleted from timesheet,but we change it from tasks!
|
2009-01-06 13:02:10 +00:00
|
|
|
list_avail_ids = self.pool.get('hr.analytic.timesheet').search(cr, uid, [])
|
2008-08-24 14:45:43 +00:00
|
|
|
if line_id in list_avail_ids:
|
|
|
|
obj = self.pool.get('hr.analytic.timesheet')
|
2008-09-24 08:46:41 +00:00
|
|
|
if 'name' in vals:
|
2009-10-12 12:33:10 +00:00
|
|
|
vals_line['name'] = '%s: %s' % (tools.ustr(task.task_id.name), tools.ustr(vals['name']) or '/')
|
2008-09-24 08:46:41 +00:00
|
|
|
if 'user_id' in vals:
|
2009-01-06 13:02:10 +00:00
|
|
|
vals_line['user_id'] = vals['user_id']
|
2008-09-24 08:46:41 +00:00
|
|
|
if 'date' in vals:
|
2009-01-06 13:02:10 +00:00
|
|
|
vals_line['date'] = vals['date'][:10]
|
2008-09-24 08:46:41 +00:00
|
|
|
if 'hours' in vals:
|
2009-01-06 13:02:10 +00:00
|
|
|
vals_line['unit_amount'] = vals['hours']
|
|
|
|
vals_line['amount'] = (-1) * vals['hours'] * obj.browse(cr, uid, line_id).product_id.standard_price
|
|
|
|
obj.write(cr, uid, [line_id], vals_line, {})
|
2008-08-24 14:45:43 +00:00
|
|
|
|
2009-01-06 13:02:10 +00:00
|
|
|
return super(project_work,self).write(cr, uid, ids, vals, context)
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
|
|
def unlink(self, cr, uid, ids, *args, **kwargs):
|
2009-01-06 13:02:10 +00:00
|
|
|
timesheet_id = self.pool.get('project.task.work').browse(cr, uid, ids)[0].hr_analytic_timesheet_id
|
2009-03-20 05:38:39 +00:00
|
|
|
# delete entry from timesheet too while deleting entry to task.
|
2009-01-06 13:02:10 +00:00
|
|
|
list_avail_ids = self.pool.get('hr.analytic.timesheet').search(cr, uid, [])
|
2008-08-24 14:45:43 +00:00
|
|
|
if timesheet_id in list_avail_ids:
|
2009-01-21 11:21:21 +00:00
|
|
|
obj = self.pool.get('hr.analytic.timesheet').unlink(cr, uid, [timesheet_id], *args, **kwargs)
|
2008-08-24 14:45:43 +00:00
|
|
|
|
2009-01-06 13:02:10 +00:00
|
|
|
return super(project_work,self).unlink(cr, uid, ids, *args, **kwargs)
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
|
|
_columns={
|
|
|
|
'hr_analytic_timesheet_id':fields.integer('Related Timeline Id')
|
|
|
|
}
|
|
|
|
|
|
|
|
project_work()
|
2008-09-24 09:18:06 +00:00
|
|
|
|
|
|
|
class project_project(osv.osv):
|
|
|
|
_inherit = "project.project"
|
|
|
|
def name_get(self, cr, user, ids, context=None):
|
|
|
|
result = []
|
|
|
|
for project in self.browse(cr, user, ids, context):
|
2009-01-06 13:02:10 +00:00
|
|
|
name = "[%s] %s" % (project.category_id and project.category_id.code or '?', project.name)
|
|
|
|
result.append((project.id, name))
|
2008-09-24 09:18:06 +00:00
|
|
|
return result
|
|
|
|
project_project()
|
2008-08-24 14:45:43 +00:00
|
|
|
|
2009-01-06 13:02:10 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|