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 ##############################################################################
23 from datetime import datetime
24 from dateutil.relativedelta import relativedelta
26 from osv import fields, osv
28 class sale_order_dates(osv.osv):
29 _inherit = 'sale.order'
32 def _get_effective_date(self, cr, uid, ids, name, arg, context={}):
35 for order in self.browse(cr, uid, ids):
37 for pick in order.picking_ids:
38 dates_list.append(pick.date)
40 res[order.id] = min(dates_list)
45 def _get_commitment_date(self, cr, uid, ids, name, arg, context={}):
48 for order in self.browse(cr, uid, ids):
50 for line in order.order_line:
51 dt = datetime.strptime(order.date_order, '%Y-%m-%d') + relativedelta(days=line.delay or 0.0)
52 dt_s = dt.strftime('%Y-%m-%d')
53 dates_list.append(dt_s)
55 res[order.id] = min(dates_list)
59 'commitment_date': fields.function(_get_commitment_date, method=True,store=True, type='date', string='Commitment Date', help="Date on which delivery of products is to be made"),
60 'requested_date': fields.date('Requested Date', help="Date on which customer has requested for sales"),
61 'effective_date': fields.function(_get_effective_date, method=True, type='date', store=True,string='Effective Date',help="Date on which picking is created"),
66 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: