[MERGE] branch merged with lp:~openerp-dev/openobject-addons/trunk-dev-addons3
[odoo/odoo.git] / addons / sale_order_dates / sale.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 osv import fields, osv
23 import time
24 from mx import DateTime
25 class sale_order_dates(osv.osv):
26     _inherit = 'sale.order'
27     _name = 'sale.order'
28
29     def _get_effective_date(self, cr, uid, ids, name, arg, context={}):
30         res = {}
31         dates_list = []
32         for order in self.browse(cr, uid, ids):
33             dates_list = []
34             for pick in order.picking_ids:
35                 dates_list.append(pick.date)
36             if dates_list:
37                 res[order.id] = min(dates_list)
38             else:
39                 res[order.id] =False
40             return res
41
42     def _get_commitment_date(self, cr, uid, ids, name, arg, context={}):
43         res = {}
44         dates_list = []
45         for order in self.browse(cr, uid, ids):
46             dates_list = []
47             for line in order.order_line:
48                 dt=DateTime.strptime(order.date_order, '%Y-%m-%d') + DateTime.RelativeDateTime(days=line.delay or 0.0)
49                 dt_s = dt.strftime('%Y-%m-%d')
50                 dates_list.append(dt_s)
51             if dates_list:
52                 res[order.id] = min(dates_list)
53             return res
54
55     _columns = {
56         'commitment_date': fields.function(_get_commitment_date, method=True,store=True, type='date', string='Commitment Date'),
57         'requested_date': fields.date('Requested Date'),
58         'effective_date': fields.function(_get_effective_date, method=True, type='date', store=True,string='Effective Date'),
59     }
60 sale_order_dates()
61 """
62  - date_commitment: min(fields.function using delay on SO lines +
63           date_order)
64         - date_requested: fields.date
65         - Effective date: fields.function the first picking done.
66 """
67
68
69 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: