2018-05-02 13:50:39 +02:00
|
|
|
# The COPYRIGHT file at the top level of
|
|
|
|
# this repository contains the full copyright notices and license terms.
|
2018-07-24 11:24:26 +02:00
|
|
|
from trytond.model import fields, ModelSQL
|
|
|
|
from trytond.pool import PoolMeta, Pool
|
|
|
|
from trytond.tools.multivalue import migrate_property
|
|
|
|
from trytond.modules.company.model import CompanyValueMixin
|
|
|
|
from trytond import backend
|
2018-05-02 13:50:39 +02:00
|
|
|
|
2018-07-24 11:24:26 +02:00
|
|
|
__all__ = ['Configuration', 'ConfigurationSequence', 'UnitLoad',
|
|
|
|
'ConfigurationEDIOutputPath']
|
2018-05-02 13:50:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Configuration:
|
|
|
|
__metaclass__ = PoolMeta
|
|
|
|
__name__ = 'stock.configuration'
|
2018-07-24 11:24:26 +02:00
|
|
|
|
|
|
|
edocument_sequence = fields.MultiValue(
|
2018-05-08 09:19:02 +02:00
|
|
|
fields.Many2One('ir.sequence', 'Electronic Document Sequence',
|
|
|
|
required=True))
|
2018-07-24 11:24:26 +02:00
|
|
|
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')
|
2018-09-27 14:10:26 +02:00
|
|
|
elif field == 'EDI_output_path':
|
|
|
|
return pool.get('stock.configuration.edi_output_path')
|
2018-07-24 11:24:26 +02:00
|
|
|
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:
|
|
|
|
__name__ = 'stock.configuration.sequence'
|
|
|
|
__metaclass__ = PoolMeta
|
|
|
|
|
|
|
|
edocument_sequence = fields.Many2One('ir.sequence',
|
|
|
|
'Electronic Document Sequence', required=True)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def __register__(cls, module_name):
|
|
|
|
TableHandler = backend.get('TableHandler')
|
|
|
|
exist = TableHandler.table_exist(cls._table)
|
2018-09-25 22:46:26 +02:00
|
|
|
if exist:
|
|
|
|
table = TableHandler(cls, module_name)
|
|
|
|
exist &= table.column_exist('edocument_sequence')
|
2018-07-24 11:24:26 +02:00
|
|
|
|
|
|
|
super(ConfigurationSequence, cls).__register__(module_name)
|
|
|
|
|
|
|
|
if not exist:
|
2018-09-25 22:46:26 +02:00
|
|
|
# Re-migration
|
2018-07-24 11:24:26 +02:00
|
|
|
cls._migrate_property([], [], [])
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def _migrate_property(cls, field_names, value_names, fields):
|
|
|
|
field_names.append('edocument_sequence')
|
|
|
|
value_names.append('edocument_sequence')
|
2018-09-25 22:46:26 +02:00
|
|
|
super(ConfigurationSequence, cls)._migrate_property(field_names,
|
|
|
|
value_names, fields)
|
2018-07-24 11:24:26 +02:00
|
|
|
|
|
|
|
@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"""
|
2018-07-24 17:03:15 +02:00
|
|
|
__name__ = 'stock.configuration.edi_output_path'
|
2018-07-24 11:24:26 +02:00
|
|
|
|
|
|
|
EDI_output_path = fields.Char('EDI Output Path')
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def __register__(cls, module_name):
|
|
|
|
TableHandler = backend.get('TableHandler')
|
|
|
|
exist = TableHandler.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)
|
2018-05-02 13:50:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
class UnitLoad:
|
|
|
|
__metaclass__ = PoolMeta
|
|
|
|
__name__ = 'stock.unit_load'
|
|
|
|
|
|
|
|
def get_best_before(self):
|
2018-06-25 18:02:40 +02:00
|
|
|
return ''
|
2018-05-02 13:50:39 +02:00
|
|
|
|
|
|
|
def get_sscc(self):
|
|
|
|
if self.shipment_out:
|
2018-05-08 09:19:02 +02:00
|
|
|
edi_codes = [identifier.code for identifier in
|
|
|
|
self.shipment_out.company.party.identifiers
|
|
|
|
if identifier.type == 'EDI_sender']
|
2018-05-02 13:50:39 +02:00
|
|
|
edi_code = edi_codes[0][:6] if edi_codes else '000000'
|
|
|
|
code = '00' + edi_code + self.code[-9:].zfill(len(self.code[-9:])-9)
|
|
|
|
return code + str(self._sscc_control_digit(code))
|
2018-06-25 18:02:40 +02:00
|
|
|
return ''
|
2018-05-02 13:50:39 +02:00
|
|
|
|
|
|
|
def get_grai(self):
|
2018-06-26 09:16:50 +02:00
|
|
|
return ''
|
2018-05-02 13:50:39 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _sscc_control_digit(num):
|
|
|
|
nums = (int(c) for c in num)
|
|
|
|
multipliers = [3, 1]
|
|
|
|
return 10 - sum((digit * multipliers[index % 2]
|
2018-05-08 09:19:02 +02:00
|
|
|
for index, digit in enumerate(nums))) % 10
|