trytond-edocument_edifact/stock.py

98 lines
3.4 KiB
Python

# The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import fields, ModelSQL
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Id
from trytond.tools.multivalue import migrate_property
from trytond.modules.company.model import CompanyValueMixin
class Configuration(metaclass=PoolMeta):
__name__ = 'stock.configuration'
edocument_sequence = fields.MultiValue(
fields.Many2One('ir.sequence', 'Electronic Document Sequence',
required=True, domain=[
('sequence_type', '=', Id('edocument_edifact',
'sequence_type_edocument'))
]))
EDI_output_path = fields.MultiValue(fields.Char('EDI Output Path'))
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field == 'edocument_sequence':
return pool.get('stock.configuration.sequence')
elif field == 'EDI_output_path':
return pool.get('stock.configuration.edi_output_path')
return super(Configuration, cls).multivalue_model(field)
@classmethod
def default_edocument_sequence(cls, **pattern):
return cls.multivalue_model(
'edocument_sequence').default_edocument_sequence()
class ConfigurationSequence(metaclass=PoolMeta):
__name__ = 'stock.configuration.sequence'
edocument_sequence = fields.Many2One('ir.sequence',
'Electronic Document Sequence', required=True, domain=[
('sequence_type', '=', Id('edocument_edifact',
'sequence_type_edocument'))
])
@classmethod
def __register__(cls, module_name):
table_h = cls.__table_handler__(module_name)
exist = table_h.table_exist(cls._table)
if exist:
exist &= table_h.column_exist('edocument_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('edocument_sequence')
value_names.append('edocument_sequence')
super(ConfigurationSequence, cls)._migrate_property(field_names,
value_names, fields)
@classmethod
def default_edocument_sequence(cls):
pool = Pool()
ModelData = pool.get('ir.model.data')
try:
return ModelData.get_id('edocument_edifact', 'sequence_edocument')
except KeyError:
return None
class ConfigurationEDIOutputPath(ModelSQL, CompanyValueMixin):
"""Stock Configuration EDI Output Path"""
__name__ = 'stock.configuration.edi_output_path'
EDI_output_path = fields.Char('EDI Output Path')
@classmethod
def __register__(cls, module_name):
table_h = cls.__table_handler__(module_name)
exist = table_h.table_exist(cls._table)
super(ConfigurationEDIOutputPath, cls).__register__(module_name)
if not exist:
cls._migrate_property([], [], [])
@classmethod
def _migrate_property(cls, field_names, value_names, fields):
field_names.append('EDI_output_path')
value_names.append('EDI_output_path')
fields.append('company')
migrate_property('stock.configuration',
field_names, cls, value_names, fields=fields)