[MERGE] new livechat web module chs
[odoo/odoo.git] / addons / project_retro_planning / project_retro_planning.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from datetime import date, timedelta, datetime
23 import time
24
25 from osv import fields, osv
26
27 class project_project(osv.osv):
28     _inherit = 'project.project'
29
30     def write(self, cr, uid, ids, vals, *args, **kwargs):
31         if isinstance(ids, (int, long)):
32             ids = [ids]
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']
40                 else:
41                     new_end_date = date(*time.strptime(vals['date'],'%Y-%m-%d')[:3])
42                 if prj.date:
43                     old_end_date = date(*time.strptime(prj.date,'%Y-%m-%d')[:3])
44                     for task in prj.tasks:
45                         if task.date_start:
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})
50                             else:
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)
53
54 project_project()
55
56 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: