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 ##############################################################################
24 from openerp.osv import fields, osv
26 class stock_production_lot(osv.osv):
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 = openerp.registry(cr.dbname)['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') or False
48 'life_date': fields.datetime('End of Life Date',
49 help='This is the date on which the goods with this Serial Number may become dangerous and must not be consumed.'),
50 'use_date': fields.datetime('Best before Date',
51 help='This is the date on which the goods with this Serial Number start deteriorating, without being dangerous yet.'),
52 'removal_date': fields.datetime('Removal Date',
53 help='This is the date on which the goods with this Serial Number should be removed from the stock.'),
54 'alert_date': fields.datetime('Alert Date',
55 help="This is the date on which an alert should be notified about the goods with this Serial Number."),
57 # Assign dates according to products data
58 def create(self, cr, uid, vals, context=None):
59 newid = super(stock_production_lot, self).create(cr, uid, vals, context=context)
60 obj = self.browse(cr, uid, newid, context=context)
62 for f in ('life_date', 'use_date', 'removal_date', 'alert_date'):
63 if not getattr(obj, f):
65 context = dict(context or {})
66 context['product_id'] = obj.product_id.id
67 self.write(cr, uid, [obj.id], self.default_get(cr, uid, towrite, context=context))
71 'life_date': _get_date('life_time'),
72 'use_date': _get_date('use_time'),
73 'removal_date': _get_date('removal_time'),
74 'alert_date': _get_date('alert_time'),
78 class stock_quant(osv.osv):
79 _inherit = 'stock.quant'
81 def _get_quants(self, cr, uid, ids, context=None):
82 return self.pool.get('stock.quant').search(cr, uid, [('lot_id', 'in', ids)], context=context)
85 'removal_date': fields.related('lot_id', 'removal_date', type='datetime', string='Removal Date',
87 'stock.quant': (lambda self, cr, uid, ids, ctx: ids, ['lot_id'], 20),
88 'stock.production.lot': (_get_quants, ['removal_date'], 20),
92 def apply_removal_strategy(self, cr, uid, location, product, qty, domain, removal_strategy, context=None):
93 if removal_strategy == 'fefo':
94 order = 'removal_date, in_date, id'
95 return self._quants_get_order(cr, uid, location, product, qty, domain, order, context=context)
96 return super(stock_quant, self).apply_removal_strategy(cr, uid, location, product, qty, domain, removal_strategy, context=context)
99 class product_product(osv.osv):
100 _inherit = 'product.template'
102 'life_time': fields.integer('Product Life Time',
103 help='When a new a Serial Number is issued, this is the number of days before the goods may become dangerous and must not be consumed.'),
104 'use_time': fields.integer('Product Use Time',
105 help='When a new a Serial Number is issued, this is the number of days before the goods starts deteriorating, without being dangerous yet.'),
106 'removal_time': fields.integer('Product Removal Time',
107 help='When a new a Serial Number is issued, this is the number of days before the goods should be removed from the stock.'),
108 'alert_time': fields.integer('Product Alert Time',
109 help='When a new a Serial Number is issued, this is the number of days before an alert should be notified.'),
111 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: