Allow set template path. Fix lot segments reader.

This commit refs #23487.
This commit is contained in:
José Antonio Díaz Miralles 2022-06-30 09:15:01 +02:00
parent 74d503eb54
commit 078ff85beb
2 changed files with 56 additions and 32 deletions

View File

@ -18,6 +18,10 @@ msgctxt "field:stock.configuration,template_order_response_edi:"
msgid "Template EDI Used for Response"
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:"
msgid "EDI Description"
msgstr "Descripción EDI"

View File

@ -64,6 +64,9 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
@classmethod
def import_edi_input(cls, response, template):
pool = Pool()
ProductCode = pool.get('product.code')
Move = pool.get('stock.move')
def get_new_move():
move = None
@ -90,31 +93,33 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
return move
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, = Lot.search([
('number', '=', values.get('lot')),
('product', '=', move.product)
], limit=1) or [None]
if lot:
expiry_date = values.get('expiry_date')
if expiry_date and lot.expiry_date:
if expiry_date < lot.expiry_date:
lot.expiry_date = expiry_date
else:
today = datetime.today().date()
expiration_date_exist = hasattr(Lot, 'expiration_date')
if lot and expiration_date_exist:
expiration_date = values.get('expiration_date')
if (expiration_date and lot.expiration_date
and expiration_date < lot.expiration_date):
lot.expiration_date = expiration_date
elif not lot:
lot = Lot()
lot.number = values.get('lot') or today.isoformat()
lot.number = values.get('lot')
lot.product = product
lot.expiry_date = values.get('expiry_date')
if expiration_date_exist:
lot.expiration_date = values.get('expiration_date')
lot.save()
for move_ in moves_:
move_.lot = lot
pool = Pool()
ProductCode = pool.get('product.code')
Move = pool.get('stock.move')
total_errors = []
control_chars = cls.set_control_chars(
template.get('control_chars', {}))
@ -132,7 +137,7 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
if not unh or unh.elements[1][0] != 'DESADV':
return DO_NOTHING, NO_ERRORS
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]
template_rff = template_header.get('RFF')
purchase, errors = cls._process_RFF(rff, template_rff, control_chars)
@ -350,17 +355,24 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
return {'description': description}, NO_ERRORS
@classmethod
@with_segment_check
def _process_PCILIN(cls, segment, template):
elements_lenght = len(segment.elements)
expiry_date = (cls.get_datetime_obj_from_edi_date(
segment.elements[1]) if elements_lenght > 1 else None)
lot = segment.elements[7] if elements_lenght > 6 else None
result = {
'expiry_date': expiry_date.date() if expiry_date else None,
'lot': lot
}
return result, NO_ERRORS
return DO_NOTHING, NO_ERRORS
@classmethod
def _process_DTMLIN(cls, segment, template):
if segment.elements[0][0] != '36':
return DO_NOTHING, NO_ERRORS
expiration_date = cls.get_datetime_obj_from_edi_date(
segment.elements[0][2])
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
def _process_CPSLIN(cls, segment, template):
@ -370,15 +382,22 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
def create_edi_shipments(cls):
pool = Pool()
Configuration = pool.get('stock.configuration')
configuration = Configuration(1)
source_path = os.path.abspath(configuration.inbox_path_edi or
DEFAULT_FILES_LOCATION)
source_path = os.path.abspath(configuration.inbox_path_edi
or DEFAULT_FILES_LOCATION)
errors_path = os.path.abspath(configuration.errors_path_edi
or DEFAULT_FILES_LOCATION)
template_name = (configuration.template_order_response_edi
or DEFAULT_TEMPLATE)
template_path = os.path.join(os.path.join(MODULE_PATH, 'templates'),
template_name)
if not configuration.template_order_response_edi:
template_name = (configuration.template_order_response_edi
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)
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')
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.')