122 lines
4.2 KiB
Python
122 lines
4.2 KiB
Python
# The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
from trytond.model import ModelSQL, fields
|
|
from trytond.pool import PoolMeta, Pool
|
|
from trytond.pyson import Eval
|
|
from trytond.tools.multivalue import migrate_property
|
|
from trytond.modules.company.model import CompanyValueMixin
|
|
from trytond import backend
|
|
|
|
__all__ = ['Configuration', 'ConfigurationSequence',
|
|
'ConfigurationULProductionType']
|
|
|
|
|
|
class Configuration(metaclass=PoolMeta):
|
|
__name__ = 'stock.configuration'
|
|
|
|
unit_load_sequence = fields.MultiValue(
|
|
fields.Many2One('ir.sequence', 'Load unit Sequence', required=True,
|
|
domain=[('code', '=', 'stock.unit_load'),
|
|
('company', 'in',
|
|
[Eval('context', {}).get(
|
|
'company', -1), None])]))
|
|
ul_production_type = fields.MultiValue(
|
|
fields.Selection([('location', 'Location')],
|
|
'UL Production type', required=True))
|
|
pallet_category = fields.Many2One('product.category', 'Pallet Category')
|
|
case_category = fields.Many2One('product.category', 'Case Category')
|
|
|
|
@classmethod
|
|
def multivalue_model(cls, field):
|
|
pool = Pool()
|
|
if field == 'unit_load_sequence':
|
|
return pool.get('stock.configuration.sequence')
|
|
return super(Configuration, cls).multivalue_model(field)
|
|
|
|
@classmethod
|
|
def default_unit_load_sequence(cls, **pattern):
|
|
return cls.multivalue_model(
|
|
'unit_load_sequence').default_unit_load_sequence()
|
|
|
|
@classmethod
|
|
def default_ul_production_type(cls, **pattern):
|
|
return cls.multivalue_model(
|
|
'ul_production_type').default_ul_production_type()
|
|
|
|
@classmethod
|
|
def write(cls, *args):
|
|
UnitLoad = Pool().get('stock.unit_load')
|
|
super().write(*args)
|
|
UnitLoad._product_category_cache.clear()
|
|
|
|
|
|
class ConfigurationSequence(metaclass=PoolMeta):
|
|
__name__ = 'stock.configuration.sequence'
|
|
|
|
unit_load_sequence = fields.Many2One('ir.sequence',
|
|
'Load unit Sequence', required=True,
|
|
domain=[('code', '=', 'stock.unit_load'),
|
|
('company', 'in',
|
|
[Eval('context', {}).get(
|
|
'company', -1), None])])
|
|
|
|
@classmethod
|
|
def __register__(cls, module_name):
|
|
TableHandler = backend.get('TableHandler')
|
|
exist = TableHandler.table_exist(cls._table)
|
|
if exist:
|
|
table = TableHandler(cls, module_name)
|
|
exist &= table.column_exist('unit_load_sequence')
|
|
|
|
super(ConfigurationSequence, cls).__register__(module_name)
|
|
|
|
if not exist:
|
|
# Re-migration
|
|
cls._migrate_property([], [], [])
|
|
|
|
@classmethod
|
|
def _migrate_property(cls, field_names, value_names, fields):
|
|
field_names.append('unit_load_sequence')
|
|
value_names.append('unit_load_sequence')
|
|
super(ConfigurationSequence, cls)._migrate_property(field_names,
|
|
value_names, fields)
|
|
|
|
@classmethod
|
|
def default_unit_load_sequence(cls):
|
|
pool = Pool()
|
|
ModelData = pool.get('ir.model.data')
|
|
try:
|
|
return ModelData.get_id('stock_unit_load', 'sequence_unit_load')
|
|
except KeyError:
|
|
return None
|
|
|
|
|
|
class ConfigurationULProductionType(ModelSQL, CompanyValueMixin):
|
|
"Stock Configuration UL Production Type"
|
|
__name__ = 'stock.configuration.ul_production_type'
|
|
|
|
ul_production_type = fields.Selection([('location', 'Location')],
|
|
'UL Production type', required=True)
|
|
|
|
@classmethod
|
|
def __register__(cls, module_name):
|
|
TableHandler = backend.get('TableHandler')
|
|
exist = TableHandler.table_exist(cls._table)
|
|
|
|
super(ConfigurationULProductionType, cls).__register__(module_name)
|
|
|
|
if not exist:
|
|
cls._migrate_property([], [], [])
|
|
|
|
@classmethod
|
|
def _migrate_property(cls, field_names, value_names, fields):
|
|
field_names.append('ul_production_type')
|
|
value_names.append('ul_production_type')
|
|
fields.append('company')
|
|
migrate_property('stock.configuration',
|
|
field_names, cls, value_names, fields=fields)
|
|
|
|
@classmethod
|
|
def default_ul_production_type(cls):
|
|
return 'location'
|