Allow set template path. Fix lot segments reader.
This commit refs #23487.
This commit is contained in:
parent
74d503eb54
commit
078ff85beb
|
@ -18,6 +18,10 @@ msgctxt "field:stock.configuration,template_order_response_edi:"
|
||||||
msgid "Template EDI Used for Response"
|
msgid "Template EDI Used for Response"
|
||||||
msgstr "Plantilla EDI usada para la Respuesta"
|
msgstr "Plantilla EDI usada para la Respuesta"
|
||||||
|
|
||||||
|
msgctxt "help:stock.configuration,template_order_response_edi:"
|
||||||
|
msgid "Path of the YAML file."
|
||||||
|
msgstr "Ruta del fichero YAML."
|
||||||
|
|
||||||
msgctxt "field:stock.move,edi_description:"
|
msgctxt "field:stock.move,edi_description:"
|
||||||
msgid "EDI Description"
|
msgid "EDI Description"
|
||||||
msgstr "Descripción EDI"
|
msgstr "Descripción EDI"
|
||||||
|
|
84
shipment.py
84
shipment.py
|
@ -64,6 +64,9 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def import_edi_input(cls, response, template):
|
def import_edi_input(cls, response, template):
|
||||||
|
pool = Pool()
|
||||||
|
ProductCode = pool.get('product.code')
|
||||||
|
Move = pool.get('stock.move')
|
||||||
|
|
||||||
def get_new_move():
|
def get_new_move():
|
||||||
move = None
|
move = None
|
||||||
|
@ -90,31 +93,33 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
|
||||||
return move
|
return move
|
||||||
|
|
||||||
def manage_lots():
|
def manage_lots():
|
||||||
if hasattr(Move, 'lot'):
|
if (hasattr(Move, 'lot')
|
||||||
|
and move.product.lot_is_required(move.from_location,
|
||||||
|
move.to_location)
|
||||||
|
and values.get('lot')):
|
||||||
Lot = pool.get('stock.lot')
|
Lot = pool.get('stock.lot')
|
||||||
|
|
||||||
lot, = Lot.search([
|
lot, = Lot.search([
|
||||||
('number', '=', values.get('lot')),
|
('number', '=', values.get('lot')),
|
||||||
('product', '=', move.product)
|
('product', '=', move.product)
|
||||||
], limit=1) or [None]
|
], limit=1) or [None]
|
||||||
if lot:
|
|
||||||
expiry_date = values.get('expiry_date')
|
expiration_date_exist = hasattr(Lot, 'expiration_date')
|
||||||
if expiry_date and lot.expiry_date:
|
if lot and expiration_date_exist:
|
||||||
if expiry_date < lot.expiry_date:
|
expiration_date = values.get('expiration_date')
|
||||||
lot.expiry_date = expiry_date
|
if (expiration_date and lot.expiration_date
|
||||||
else:
|
and expiration_date < lot.expiration_date):
|
||||||
today = datetime.today().date()
|
lot.expiration_date = expiration_date
|
||||||
|
elif not lot:
|
||||||
lot = Lot()
|
lot = Lot()
|
||||||
lot.number = values.get('lot') or today.isoformat()
|
lot.number = values.get('lot')
|
||||||
lot.product = product
|
lot.product = product
|
||||||
lot.expiry_date = values.get('expiry_date')
|
if expiration_date_exist:
|
||||||
|
lot.expiration_date = values.get('expiration_date')
|
||||||
lot.save()
|
lot.save()
|
||||||
for move_ in moves_:
|
for move_ in moves_:
|
||||||
move_.lot = lot
|
move_.lot = lot
|
||||||
|
|
||||||
pool = Pool()
|
|
||||||
ProductCode = pool.get('product.code')
|
|
||||||
Move = pool.get('stock.move')
|
|
||||||
|
|
||||||
total_errors = []
|
total_errors = []
|
||||||
control_chars = cls.set_control_chars(
|
control_chars = cls.set_control_chars(
|
||||||
template.get('control_chars', {}))
|
template.get('control_chars', {}))
|
||||||
|
@ -132,7 +137,7 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
|
||||||
if not unh or unh.elements[1][0] != 'DESADV':
|
if not unh or unh.elements[1][0] != 'DESADV':
|
||||||
return DO_NOTHING, NO_ERRORS
|
return DO_NOTHING, NO_ERRORS
|
||||||
rffs = [x for x in message.get_segments('RFF')]
|
rffs = [x for x in message.get_segments('RFF')]
|
||||||
rff, = [x for x in rffs if x.elements[0][0] == 'ON'] or [None]
|
rff, = [x for x in rffs if x.elements[0][0] == 'ON'][:1] or [None]
|
||||||
reference, = [x for x in rffs if x.elements[0][0] == 'DQ'] or [None]
|
reference, = [x for x in rffs if x.elements[0][0] == 'DQ'] or [None]
|
||||||
template_rff = template_header.get('RFF')
|
template_rff = template_header.get('RFF')
|
||||||
purchase, errors = cls._process_RFF(rff, template_rff, control_chars)
|
purchase, errors = cls._process_RFF(rff, template_rff, control_chars)
|
||||||
|
@ -350,17 +355,24 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
|
||||||
return {'description': description}, NO_ERRORS
|
return {'description': description}, NO_ERRORS
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@with_segment_check
|
|
||||||
def _process_PCILIN(cls, segment, template):
|
def _process_PCILIN(cls, segment, template):
|
||||||
elements_lenght = len(segment.elements)
|
return DO_NOTHING, NO_ERRORS
|
||||||
expiry_date = (cls.get_datetime_obj_from_edi_date(
|
|
||||||
segment.elements[1]) if elements_lenght > 1 else None)
|
@classmethod
|
||||||
lot = segment.elements[7] if elements_lenght > 6 else None
|
def _process_DTMLIN(cls, segment, template):
|
||||||
result = {
|
if segment.elements[0][0] != '36':
|
||||||
'expiry_date': expiry_date.date() if expiry_date else None,
|
return DO_NOTHING, NO_ERRORS
|
||||||
'lot': lot
|
expiration_date = cls.get_datetime_obj_from_edi_date(
|
||||||
}
|
segment.elements[0][2])
|
||||||
return result, NO_ERRORS
|
expiration_date = (expiration_date and expiration_date.date()
|
||||||
|
or expiration_date)
|
||||||
|
return {'expiration_date': expiration_date}, NO_ERRORS
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _process_GINLIN(cls, segment, template):
|
||||||
|
if segment.elements[0] != 'BX':
|
||||||
|
return DO_NOTHING, NO_ERRORS
|
||||||
|
return {'lot': segment.elements[1]}, NO_ERRORS
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _process_CPSLIN(cls, segment, template):
|
def _process_CPSLIN(cls, segment, template):
|
||||||
|
@ -370,15 +382,22 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
|
||||||
def create_edi_shipments(cls):
|
def create_edi_shipments(cls):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Configuration = pool.get('stock.configuration')
|
Configuration = pool.get('stock.configuration')
|
||||||
|
|
||||||
configuration = Configuration(1)
|
configuration = Configuration(1)
|
||||||
source_path = os.path.abspath(configuration.inbox_path_edi or
|
source_path = os.path.abspath(configuration.inbox_path_edi
|
||||||
DEFAULT_FILES_LOCATION)
|
or DEFAULT_FILES_LOCATION)
|
||||||
errors_path = os.path.abspath(configuration.errors_path_edi
|
errors_path = os.path.abspath(configuration.errors_path_edi
|
||||||
or DEFAULT_FILES_LOCATION)
|
or DEFAULT_FILES_LOCATION)
|
||||||
template_name = (configuration.template_order_response_edi
|
|
||||||
or DEFAULT_TEMPLATE)
|
if not configuration.template_order_response_edi:
|
||||||
template_path = os.path.join(os.path.join(MODULE_PATH, 'templates'),
|
template_name = (configuration.template_order_response_edi
|
||||||
template_name)
|
or DEFAULT_TEMPLATE)
|
||||||
|
template_path = os.path.join(os.path.join(MODULE_PATH,
|
||||||
|
'templates'), template_name)
|
||||||
|
else:
|
||||||
|
template_path = configuration.template_order_response_edi
|
||||||
|
template_name = template_path.split('/')[-1]
|
||||||
|
|
||||||
template = EdiTemplate(template_name, template_path)
|
template = EdiTemplate(template_name, template_path)
|
||||||
return cls.process_edi_inputs(source_path, errors_path, template)
|
return cls.process_edi_inputs(source_path, errors_path, template)
|
||||||
|
|
||||||
|
@ -393,4 +412,5 @@ class StockConfiguration(metaclass=PoolMeta):
|
||||||
|
|
||||||
inbox_path_edi = fields.Char('Inbox Path EDI')
|
inbox_path_edi = fields.Char('Inbox Path EDI')
|
||||||
errors_path_edi = fields.Char('Errors Path')
|
errors_path_edi = fields.Char('Errors Path')
|
||||||
template_order_response_edi = fields.Char('Template EDI Used for Response')
|
template_order_response_edi = fields.Char('Template EDI Used for Response',
|
||||||
|
help='Path of the YAML file.')
|
||||||
|
|
Loading…
Reference in New Issue