New trunk
[odoo/odoo.git] / addons / product_expiry / product_expiry.py
1 ##############################################################################
2 #
3 # Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
4 #
5 # $Id$
6 #
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
12 # Service Company
13 #
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27 #
28 ##############################################################################
29
30 import datetime
31 from osv import fields,osv
32 import pooler
33
34 class stock_production_lot(osv.osv):
35         _name = 'stock.production.lot'
36         _inherit = 'stock.production.lot'
37
38         def _get_date(dtype):
39                 def calc_date(self, cr, uid, context={}):
40                         if context.get('product_id', False):
41                                 product = pooler.get_pool(cr.dbname).get('product.product').browse(cr, uid, [context['product_id']])[0]
42                                 duree = getattr(product, dtype) or 0
43                                 date = datetime.datetime.today() + datetime.timedelta(days=duree)
44                                 return date.strftime('%Y-%m-%d %H:%M:%S')
45                         else:
46                                 return False
47                 return calc_date
48
49         _columns = {
50                 'dlc': fields.datetime('Product usetime'),
51                 'dluo': fields.datetime('DLUO'),
52                 'removal_date': fields.datetime('Removal date'),
53                 'alert_date': fields.datetime('Alert date'),
54         }
55
56         _defaults = {
57                 'dlc': _get_date('life_time'),
58                 'dluo': _get_date('use_time'),
59                 'removal_date': _get_date('removal_time'),
60                 'alert_date': _get_date('alert_time'),
61         }
62 stock_production_lot()
63
64 class product_product(osv.osv):
65         _inherit = 'product.product'
66         _name = 'product.product'
67         _columns = {
68                 'life_time': fields.integer('Product lifetime'),
69                 'use_time': fields.integer('Product usetime'),
70                 'removal_time': fields.integer('Product removal time'),
71                 'alert_time': fields.integer('Product alert time'),
72         }
73 product_product()