1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from datetime import date, timedelta, datetime
25 from osv import fields, osv
27 class project_project(osv.osv):
28 _inherit = 'project.project'
30 def write(self, cr, uid, ids, vals, *args, **kwargs):
31 if isinstance(ids, (int, long)):
33 if vals.get('date', False):
34 data_project = self.browse(cr, uid, ids)
35 for prj in data_project:
36 if isinstance(vals['date'], datetime):
37 new_end_date = vals['date'].date()
38 elif isinstance(vals['date'], date):
39 new_end_date = vals['date']
41 new_end_date = date(*time.strptime(vals['date'],'%Y-%m-%d')[:3])
43 old_end_date = date(*time.strptime(prj.date,'%Y-%m-%d')[:3])
44 for task in prj.tasks:
46 start_dt = (date(*time.strptime(str(task.date_start),'%Y-%m-%d %H:%M:%S')[:3])+(new_end_date-old_end_date)).strftime('%Y-%m-%d %H:%M:%S')
47 if task.date_deadline:
48 deadline_dt = (datetime(*time.strptime(str(task.date_deadline),'%Y-%m-%d')[:3])+(new_end_date-old_end_date)).strftime('%Y-%m-%d')
49 self.pool.get('project.task').write(cr, uid, [task.id], {'date_start':start_dt, 'date_deadline':deadline_dt})
51 self.pool.get('project.task').write(cr, uid, [task.id], {'date_start':start_dt})
52 return super(project_project,self).write(cr, uid, ids, vals, *args, **kwargs)
56 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: