Implementar control por superfície
This commit is contained in:
parent
7f7df712e5
commit
1c6c99ce8c
43
stock.py
43
stock.py
|
@ -33,14 +33,6 @@ class Location:
|
|||
states={'invisible': Not(Equal(Eval('type'), 'storage')),
|
||||
'required': Bool(Eval('control_space'))},
|
||||
depends=['type', 'control_space'])
|
||||
space_measure_unit = fields.Function(
|
||||
fields.Many2One('product.uom', 'Space UOM',
|
||||
domain=[('category', 'in', [Id('product', 'uom_cat_surface'),
|
||||
Id('product', 'uom_cat_length')])],
|
||||
states={'invisible': Not(Equal(Eval('type'), 'storage')),
|
||||
'required': Bool(Eval('control_space'))},
|
||||
depends=['type', 'control_space']),
|
||||
'on_change_with_space_measure_unit')
|
||||
overload_behavior = fields.Selection([('warn', 'Warn'),
|
||||
('stop', 'Stop')],
|
||||
'Overload behavior',
|
||||
|
@ -59,7 +51,7 @@ class Location:
|
|||
states={'invisible': Not(Equal(Eval('type'), 'storage')),
|
||||
'required': Bool(Eval('control_space'))},
|
||||
depends=['type', 'control_space']),
|
||||
'on_change_with_space_measure_unit')
|
||||
'on_change_with_space_unit')
|
||||
space_unit_digits = fields.Function(fields.Integer('Space Digits'),
|
||||
'on_change_with_space_unit_digits')
|
||||
|
||||
|
@ -74,7 +66,7 @@ class Location:
|
|||
if cls.width.states.get('required'):
|
||||
cls.width.states['required'] |= And(Bool(Eval('control_space')), Equal(Eval('space_measure'), 'surface'))
|
||||
else:
|
||||
cls.width.states['required'] = And(Bool(Eval('control_space')), Equal(Eval('space_measure'),'surface'))
|
||||
cls.width.states['required'] = And(Bool(Eval('control_space')), Equal(Eval('space_measure'), 'surface'))
|
||||
cls.width.depends.extend(['control_space', 'space_measure'])
|
||||
|
||||
@staticmethod
|
||||
|
@ -104,10 +96,10 @@ class Location:
|
|||
return {}
|
||||
return {'space_measure': 'length',
|
||||
'overload_behavior': 'warn',
|
||||
'space_measure_unit': self.on_change_with_space_measure_unit()}
|
||||
'space_unit': self.on_change_with_space_unit()}
|
||||
|
||||
@fields.depends('space_measure')
|
||||
def on_change_with_space_measure_unit(self, name=None):
|
||||
def on_change_with_space_unit(self, name=None):
|
||||
pool = Pool()
|
||||
Modeldata = pool.get('ir.model.data')
|
||||
|
||||
|
@ -128,13 +120,12 @@ class Location:
|
|||
def _set_space_measure(cls, locations):
|
||||
to_update = set()
|
||||
for location in locations:
|
||||
if location.control_space:
|
||||
if location.parent:
|
||||
to_update.add(location.parent)
|
||||
if to_update:
|
||||
cls.write(list(to_update), {
|
||||
'space_measure': location.space_measure})
|
||||
to_update.clear()
|
||||
if location.parent and location.parent.space_measure != location.space_measure:
|
||||
to_update.add(location.parent)
|
||||
if to_update:
|
||||
cls.write(list(to_update), {
|
||||
'space_measure': location.space_measure})
|
||||
to_update.clear()
|
||||
|
||||
def storage_try(self, date, extra_space=float(0)):
|
||||
""" Determines if storing in location at date is possible"""
|
||||
|
@ -148,9 +139,11 @@ class Location:
|
|||
ModelData = pool.get('ir.model.data')
|
||||
meter = UOM(ModelData.get_id('product', 'uom_meter'))
|
||||
|
||||
if not self.check_space():
|
||||
return 0
|
||||
if self.type in ['view', 'warehouse']:
|
||||
if not self.control_space:
|
||||
if self.type not in ['view', 'warehouse', 'storage']:
|
||||
return 0
|
||||
if self.type == 'storage' and not any(c.control_space for c in self.childs):
|
||||
return 0
|
||||
space = 0
|
||||
for c in self.childs:
|
||||
space += c.get_space()
|
||||
|
@ -190,7 +183,11 @@ class Location:
|
|||
return self.get_space() - space
|
||||
|
||||
def check_space(self):
|
||||
return self.control_space or (self.type in ['view', 'warehouse'] and self.childs)
|
||||
if self.control_space:
|
||||
return True
|
||||
if self.type in ['view', 'warehouse'] and self.childs:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class Move:
|
||||
|
|
Loading…
Reference in New Issue