1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
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
24
import decimal_precision as dp
27
#this code must be in stock.py
28
class stock_production_lot(osv.osv):
30
_inherit = 'stock.production.lot'
33
def _calc_lot_area(self, l, h, w):
34
obj_uom = self.pool.get('product.uom')
35
r = obj_uom._calc_area(l,h)
37
r = obj_uom._calc_area(r,w)
41
def _calc_lot_factor(self, cr, uid, ids, name, arg, context=None):
48
# creates a UOM model to calculate lot factor
49
r = self.read(cr, uid, id, ['length', 'heigth', 'width'], context)
50
res[id] = self._calc_lot_area(r['length'], r['heigth'], r['width'])
51
# obj_uom = self.pool.get('product.uom')
52
# r = self.read(cr, uid, id, ['length','heigth','width'], context)
53
# res[id] = obj_uom._calc_area(r['length'],r['heigth'])
55
# res[id] = obj_uom._calc_area(res[id],r['width'])
59
def on_change_size(self, cr, uid, ids, length, heigth, width):
60
res = {'value':{'lot_factor':self._calc_lot_area(length, heigth, width)}}
65
'length': fields.float('Length (m)', digits_compute=dp.get_precision('Extra UOM data')),
66
'width': fields.float('Width (m)', digits_compute=dp.get_precision('Extra UOM data')),
67
'heigth': fields.float('Heigth (m)', digits_compute=dp.get_precision('Extra UOM data')),
68
# 'lot_location': fields.char('Location', size=10, translate=True), # don't use this field use wharehouse
69
'lot_factor': fields.function(_calc_lot_factor, method=True, type="float", string='Lot Factor', digits_compute=dp.get_precision('Product UoM')),
81
('length_gt_zero', 'CHECK (length>=0)', 'The length must be >= 0!'),
82
('width_gt_zero', 'CHECK (width>=0)', 'The width must be >= 0!'),
83
('heigth_gt_zero', 'CHECK (heigth>=0)', 'The heigth must be >= 0!'),
87
def name_get(self,cr, uid, ids, context):
90
# reads = self.read(cr, uid, ids, ['id','name', 'prefix', 'ref','length','heigth','width','lot_factor','move_ids'], context)
91
reads = self.read(cr, uid, ids, [], context)
92
# l = self.pool.get('stock.production.lot').browse(cr,uid,ids)
95
#TODO optimize with only one read for all ids, or maybe use "self" data
96
l = self.pool.get('stock.production.lot').browse(cr,uid,r['id'])
97
drv = l.product_id.stock_driver
99
name = '%s (%sx%s)' % (r['name'].strip(),r['length'],r['heigth'])
101
name = '%s (%sx%s)' % (r['name'].strip(),r['length'],r['heigth'])
103
name = '%s (%sx%sx%s)' % (r['name'].strip(),r['length'],r['heigth'],r['width'])
104
else: # call inherited name_get()
106
super_name = super(stock_production_lot,self).name_get(cr, uid, this_id, context)
107
name = super_name[0][-1]
108
res.append((r['id'], name))
110
stock_production_lot()
113
# En sale_order se debe incorporar una validacion que impida vender un lote parcial si el stock_driver es slab o block
115
#class sale_order(osv.osv):
116
# _inherit = 'sale.order.line'
118
# 'prodlot_id' : fields.many2one('stock.production.lot', 'Production lot', help="Production lot is used to put a serial number on the production"),
121
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: