1 ##############################################################################
3 # OpenERP, Open Source Management Solution
4 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 ##############################################################################
22 from osv import fields, osv
25 class stock_production_lot(osv.osv):
26 _name = 'stock.production.lot'
27 _inherit = 'stock.production.lot'
30 """Return a function to compute the limit date for this type"""
31 def calc_date(self, cr, uid, context=None):
32 """Compute the limit date for a given date"""
35 if not context.get('product_id', False):
38 product = pooler.get_pool(cr.dbname).get('product.product').browse(
39 cr, uid, context['product_id'])
40 duration = getattr(product, dtype)
41 # set date to False when no expiry time specified on the product
42 date = duration and (datetime.datetime.today()
43 + datetime.timedelta(days=duration))
44 return date and date.strftime('%Y-%m-%d %H:%M:%S')
48 'life_date': fields.datetime('End of Life Date',
49 help='The date the lot may become dangerous and should not be consumed.'),
50 'use_date': fields.datetime('Best before Date',
51 help='The date the lot starts deteriorating without becoming dangerous.'),
52 'removal_date': fields.datetime('Removal Date',
53 help='The date the lot should be removed.'),
54 'alert_date': fields.datetime('Alert Date'),
56 # Assign dates according to products data
57 def create(self, cr, uid, vals, context=None):
58 newid = super(stock_production_lot, self).create(cr, uid, vals, context=context)
59 obj = self.browse(cr, uid, newid, context=context)
61 for f in ('life_date','use_date','removal_date','alert_date'):
62 if not getattr(obj, f):
64 context = context or {}
65 context['product_id'] = obj.product_id.id
66 self.write(cr, uid, [obj.id], self.default_get(cr, uid, towrite, context=context))
70 'life_date': _get_date('life_time'),
71 'use_date': _get_date('use_time'),
72 'removal_date': _get_date('removal_time'),
73 'alert_date': _get_date('alert_time'),
75 stock_production_lot()
77 class product_product(osv.osv):
78 _inherit = 'product.product'
79 _name = 'product.product'
81 'life_time': fields.integer('Product lifetime',
82 help='The number of days before a production lot may become dangerous and should not be consumed.'),
83 'use_time': fields.integer('Product usetime',
84 help='The number of days before a production lot starts deteriorating without becoming dangerous.'),
85 'removal_time': fields.integer('Product removal time',
86 help='The number of days before a production lot should be removed.'),
87 'alert_time': fields.integer('Product alert time'),
90 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: