Mejoras en la obtención de espacio y espacio disponible

This commit is contained in:
Sergio Morillo 2014-07-28 18:54:10 +02:00
parent 74e8ef8d3e
commit ec2f410e92
2 changed files with 34 additions and 9 deletions

View File

@ -46,12 +46,24 @@ class Product:
products = Product.search([('occupy_space', '=', True)])
return [p.id for p in products] or []
def get_space(self, quantity):
def get_space(self, quantity, uom=None):
pool = Pool()
UOM = pool.get('product.uom')
ModelData = pool.get('ir.model.data')
meter = UOM(ModelData.get_id('product', 'uom_meter'))
if not getattr(self, 'occupy_space', False):
return float(0)
return quantity * self.length * self.length_uom.factor
qty = UOM.compute_qty(uom if uom else self.default_uom,
quantity, self.default_uom)
return UOM.compute_qty(self.length_uom, self.length, meter) * qty
def get_quantity_from_space(self, space):
pool = Pool()
UOM = pool.get('product.uom')
ModelData = pool.get('ir.model.data')
meter = UOM(ModelData.get_id('product', 'uom_meter'))
if not getattr(self, 'occupy_space', False):
return space
return int(space / (self.length * self.length_uom.factor))
return int(space / UOM.compute_qty(self.length_uom, self.length, meter))

View File

@ -39,6 +39,7 @@ class Location:
states={'required': Bool(Eval('control_space')),
'invisible': Not(Equal(Eval('type'), 'storage'))},
depends=['type', 'control_space'])
available_space = fields.Function(fields.Float('Quantity'), 'get_available_space')
@classmethod
def __setup__(cls):
@ -81,25 +82,37 @@ class Location:
def storage_try(self, date, extra_space=float(0)):
""" Determines if store in the location at date is possible"""
return (self.get_available_space(date) - extra_space) >= 0
with Transaction().set_context(stock_date_end=date):
return (self.get_available_space() - extra_space) >= 0
def get_space(self):
""" Location space calculation"""
pool = Pool()
UOM = pool.get('product.uom')
ModelData = pool.get('ir.model.data')
meter = UOM(ModelData.get_id('product', 'uom_meter'))
if not getattr(self, 'control_space', False):
return 0
return getattr(self, 'length', float(0)) * self.length_uom.factor if self.length_uom else 0
return UOM.compute_qty(self.length_uom, getattr(self, 'length', float(0)), meter)
def get_available_space(self, date):
def get_available_space(self, name=None):
""" Available space in a location at date"""
pool = Pool()
Product = pool.get('product.product')
Date_ = pool.get('ir.date')
if not self.control_space:
return 0
context = {'forecast': True}
if not Transaction().context.get('stock_date_end'):
context['stock_date_end'] = Date_.today()
else:
context['stock_date_end'] = Transaction().context['stock_date_end']
product_ids = Product.get_products_occupy_space()
with Transaction().set_context(stock_date_end=date,
forecast=True):
with Transaction().set_context(context):
pbl = Product.products_by_location(location_ids=[self.id],
product_ids=product_ids,
grouping=('product', ))
@ -211,7 +224,7 @@ class Move:
# if moves are not persisted we must to include them in space computing
if not getattr(m, 'id', None):
product = Product(m.product.id)
qty = product.get_space(m.quantity)
qty = product.get_space(m.quantity, m.uom)
if m.from_location.control_space:
locations[key_from] = locations[key_from] - qty
if m.to_location.control_space: