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 _inherit = 'stock.production.lot'
29 """Return a function to compute the limit date for this type"""
30 def calc_date(self, cr, uid, context=None):
31 """Compute the limit date for a given date"""
34 if not context.get('product_id', False):
37 product = pooler.get_pool(cr.dbname).get('product.product').browse(
38 cr, uid, context['product_id'])
39 duration = getattr(product, dtype)
40 # set date to False when no expiry time specified on the product
41 date = duration and (datetime.datetime.today()
42 + datetime.timedelta(days=duration))
43 return date and date.strftime('%Y-%m-%d %H:%M:%S') or False
47 'life_date': fields.datetime('End of Life Date',
48 help='The date the lot may become dangerous and should not be consumed.'),
49 'use_date': fields.datetime('Best before Date',
50 help='The date the lot starts deteriorating without becoming dangerous.'),
51 'removal_date': fields.datetime('Removal Date',
52 help='The date the lot should be removed.'),
53 'alert_date': fields.datetime('Alert Date', help="The date signifying an alert to notify about the production lot."),
55 # Assign dates according to products data
56 def create(self, cr, uid, vals, context=None):
57 newid = super(stock_production_lot, self).create(cr, uid, vals, context=context)
58 obj = self.browse(cr, uid, newid, context=context)
60 for f in ('life_date','use_date','removal_date','alert_date'):
61 if not getattr(obj, f):
63 context = context or {}
64 context['product_id'] = obj.product_id.id
65 self.write(cr, uid, [obj.id], self.default_get(cr, uid, towrite, context=context))
69 'life_date': _get_date('life_time'),
70 'use_date': _get_date('use_time'),
71 'removal_date': _get_date('removal_time'),
72 'alert_date': _get_date('alert_time'),
74 stock_production_lot()
76 class product_product(osv.osv):
77 _inherit = 'product.product'
79 'life_time': fields.integer('Product Life Time',
80 help='The number of days before a production lot may become dangerous and should not be consumed.'),
81 'use_time': fields.integer('Product Use Time',
82 help='The number of days before a production lot starts deteriorating without becoming dangerous.'),
83 'removal_time': fields.integer('Product Removal Time',
84 help='The number of days before a production lot should be removed.'),
85 'alert_time': fields.integer('Product Alert Time', help="The number of days after which, needs an alert to notify about the production lot."),
88 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: