Commit parcial de cambios
This commit is contained in:
parent
f6355b6bc4
commit
7f7df712e5
|
@ -25,9 +25,9 @@ msgctxt "field:stock.location,overload_behavior:"
|
|||
msgid "Overload behavior"
|
||||
msgstr "Acción sobrecarga espacio"
|
||||
|
||||
msgctxt "field:stock.location,storage_direction:"
|
||||
msgid "Storage direction"
|
||||
msgstr "Dirección almacenaje"
|
||||
msgctxt "field:stock.location,space_measure:"
|
||||
msgid "Space measure"
|
||||
msgstr "Medida espacio"
|
||||
|
||||
msgctxt "help:product.template,occupy_space:"
|
||||
msgid "Determines if product occupies space in storage locations"
|
||||
|
@ -58,10 +58,10 @@ msgctxt "selection:stock.location,overload_behavior:"
|
|||
msgid "Warn"
|
||||
msgstr "Avisar"
|
||||
|
||||
msgctxt "selection:stock.location,storage_direction:"
|
||||
msgid ""
|
||||
msgstr ""
|
||||
msgctxt "selection:stock.location,space_measure:"
|
||||
msgid "Length"
|
||||
msgstr "Longitud"
|
||||
|
||||
msgctxt "selection:stock.location,storage_direction:"
|
||||
msgid "Longitudinal"
|
||||
msgstr "Longitudinal"
|
||||
msgctxt "selection:stock.location,space_measure:"
|
||||
msgid "Surface"
|
||||
msgstr "Superfície"
|
||||
|
|
113
stock.py
113
stock.py
|
@ -2,7 +2,7 @@
|
|||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.pyson import Eval, Equal, Not, Bool
|
||||
from trytond.pyson import Eval, Equal, Not, Bool, Id, And
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['Configuration', 'Location', 'Move']
|
||||
|
@ -28,12 +28,19 @@ class Location:
|
|||
help='Enables storage space control',
|
||||
states={'invisible': Not(Equal(Eval('type'), 'storage'))},
|
||||
depends=['type'])
|
||||
storage_direction = fields.Selection([('longitudinal', 'Longitudinal')],
|
||||
'Storage direction',
|
||||
states={'invisible': Not(Equal(Eval('type'), 'storage')),
|
||||
'required': Bool(Eval('control_space')),
|
||||
'readonly': Bool(True)},
|
||||
depends=['type', 'control_space'])
|
||||
space_measure = fields.Selection([('length', 'Length'),
|
||||
('surface', 'Surface')], 'Space measure',
|
||||
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',
|
||||
|
@ -41,16 +48,38 @@ 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')
|
||||
available_space = fields.Function(fields.Float('Available space at date'), 'get_available_space')
|
||||
space = fields.Function(fields.Float('Space capacity',
|
||||
digits=(16, Eval('width_digits', 2))),
|
||||
'get_space')
|
||||
space_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')
|
||||
space_unit_digits = fields.Function(fields.Integer('Space Digits'),
|
||||
'on_change_with_space_unit_digits')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Location, cls).__setup__()
|
||||
cls._extend_measure_field('length')
|
||||
if cls.length.states.get('required'):
|
||||
cls.length.states['required'] |= Bool(Eval('control_space'))
|
||||
else:
|
||||
cls.length.states['required'] = Bool(Eval('control_space'))
|
||||
cls.length.depends.append('control_space')
|
||||
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.depends.extend(['control_space', 'space_measure'])
|
||||
|
||||
@staticmethod
|
||||
def default_storage_direction():
|
||||
return 'longitudinal'
|
||||
def default_space_measure():
|
||||
return 'length'
|
||||
|
||||
@staticmethod
|
||||
def default_control_space():
|
||||
|
@ -60,31 +89,59 @@ class Location:
|
|||
def default_overload_behavior():
|
||||
return 'warn'
|
||||
|
||||
@classmethod
|
||||
def _extend_measure_field(cls, field):
|
||||
f = getattr(cls, field, None)
|
||||
if not f:
|
||||
return
|
||||
req = Bool(Eval('control_space'))
|
||||
if not f.states.get('required'):
|
||||
f.states['required'] = req
|
||||
else:
|
||||
f.states['required'] = f.states['required'] | req
|
||||
f.depends.append('control_space')
|
||||
@fields.depends('height_uom')
|
||||
def on_change_with_space_unit_digits(self, name=None):
|
||||
return (self.space_unit.digits if self.space_unit
|
||||
else self.default_space_unit_digits())
|
||||
|
||||
@staticmethod
|
||||
def default_space_unit_digits():
|
||||
return 2
|
||||
|
||||
@fields.depends('control_space')
|
||||
def on_change_control_space(self):
|
||||
if not self.control_space:
|
||||
return {}
|
||||
return {'storage_direction': 'longitudinal',
|
||||
'overload_behavior': 'warn'}
|
||||
return {'space_measure': 'length',
|
||||
'overload_behavior': 'warn',
|
||||
'space_measure_unit': self.on_change_with_space_measure_unit()}
|
||||
|
||||
@fields.depends('space_measure')
|
||||
def on_change_with_space_measure_unit(self, name=None):
|
||||
pool = Pool()
|
||||
Modeldata = pool.get('ir.model.data')
|
||||
|
||||
if self.space_measure == 'length':
|
||||
return Modeldata.get_id('product', 'uom_meter')
|
||||
if self.space_measure == 'surface':
|
||||
return Modeldata.get_id('product', 'uom_square_meter')
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
super(Location, cls).write(*args)
|
||||
locations = sum(args[::2], [])
|
||||
cls._set_space_measure(locations)
|
||||
|
||||
#todo: control children configuration
|
||||
@classmethod
|
||||
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()
|
||||
|
||||
def storage_try(self, date, extra_space=float(0)):
|
||||
""" Determines if storing in location at date is possible"""
|
||||
with Transaction().set_context(stock_date_end=date):
|
||||
return (self.get_available_space() - extra_space) >= 0
|
||||
|
||||
def get_space(self):
|
||||
def get_space(self, name=None):
|
||||
""" Location space calculation"""
|
||||
pool = Pool()
|
||||
UOM = pool.get('product.uom')
|
||||
|
@ -98,7 +155,11 @@ class Location:
|
|||
for c in self.childs:
|
||||
space += c.get_space()
|
||||
return space
|
||||
return UOM.compute_qty(self.length_uom, getattr(self, 'length', float(0)), meter)
|
||||
value = UOM.compute_qty(self.length_uom, getattr(self, 'length', float(0)), meter)
|
||||
if self.space_measure == 'surface':
|
||||
other_value = UOM.compute_qty(self.width_uom, getattr(self, 'width', float(0)), meter)
|
||||
value *= other_value if other_value else 1
|
||||
return value
|
||||
|
||||
def get_available_space(self, name=None):
|
||||
""" Available space in a location at date"""
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<!-- This file is part stock_lot_quantity_location module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/label[@name='length']" position="before">
|
||||
<label name="control_space"/>
|
||||
<xpath expr="/form/notebook/page[@id='measurements']/label[@name='length']" position="before">
|
||||
<label name="control_space"/>
|
||||
<field name="control_space"/>
|
||||
<label name="storage_direction"/>
|
||||
<field name="storage_direction"/>
|
||||
<label name="space_measure"/>
|
||||
<field name="space_measure"/>
|
||||
<label name="overload_behavior"/>
|
||||
<field name="overload_behavior"/>
|
||||
<newline/>
|
||||
|
|
Loading…
Reference in New Issue