Fix a bug with expiration_date migration. Change the way that create new lots from EDI shipment import files to permit edit/change that new lot.

This commit is contained in:
Bernat Brunet 2020-10-28 23:41:39 +01:00
parent ddb1f0881c
commit c02e7b0ee4
2 changed files with 32 additions and 15 deletions

View file

@ -48,13 +48,25 @@ class Move(metaclass=PoolMeta):
default.setdefault('edi_description') default.setdefault('edi_description')
return super(Move, cls).copy(records, default=default) return super(Move, cls).copy(records, default=default)
def _get_new_lot(self, values, expiration):
pool = Pool()
Lot = pool.get('stock.lot')
today = datetime.today().date()
lot = Lot()
lot.number = values.get('lot') or today.isoformat()
lot.product = self.product
if ((not expiration or expiration != 'none')
and values.get('expiration_date', False)):
lot.expiration_date = values.get('expiration_date')
return lot
class ShipmentIn(EdifactMixin, metaclass=PoolMeta): class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
__name__ = 'stock.shipment.in' __name__ = 'stock.shipment.in'
@classmethod @classmethod
def import_edi_input(cls, response, template): def import_edi_input(cls, response, template):
def get_new_move(): def get_new_move():
move = None move = None
if product: if product:
@ -85,6 +97,7 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
pool = Pool() pool = Pool()
ProductCode = pool.get('product.code') ProductCode = pool.get('product.code')
Template = pool.get('product.template')
Move = pool.get('stock.move') Move = pool.get('stock.move')
Lot = pool.get('stock.lot') Lot = pool.get('stock.lot')
@ -190,25 +203,27 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
move = get_new_move() move = get_new_move()
move.edi_quantity = quantity move.edi_quantity = quantity
move.edi_description = values.get('description') move.edi_description = values.get('description')
if hasattr(Move, 'lot'): if hasattr(Template, 'lot_required') and product.lot_required:
expiration = None
if hasattr(Template, 'expiration_state'):
expiration = product.expiration_state
lots = Lot.search([ lots = Lot.search([
('number', '=', values.get('lot')), ('number', '=', values.get('lot')),
('product', '=', move.product) ('product', '=', move.product)
], limit=1) ], limit=1)
if lots: if lots:
lot, = lots lot, = lots
expiry_date = values.get('expiry_date') if ((not expiration or expiration != 'none')
if expiry_date and lot.expiry_date: and values.get('expiration_date', False)):
if expiry_date < lot.expiry_date: expiration_date = values.get('expiration_date')
lot.expiry_date = expiry_date if expiration_date and lot.expiration_date:
if expiration_date < lot.expiration_date:
lot.expiration_date = expiration_date
else: else:
today = datetime.today().date() lot = move._get_new_lot(values, expiration)
lot = Lot() if lot:
lot.number = values.get('lot') or today.isoformat() lot.save()
lot.product = product move.lot = lot
lot.expiry_date = values.get('expiry_date')
lot.save()
move.lot = lot
to_save.append(move) to_save.append(move)
if to_save: if to_save:
@ -280,11 +295,12 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
@with_segment_check @with_segment_check
def _process_PCILIN(cls, segment, template): def _process_PCILIN(cls, segment, template):
elements_lenght = len(segment.elements) elements_lenght = len(segment.elements)
expiry_date = (cls.get_datetime_obj_from_edi_date( expiration_date = (cls.get_datetime_obj_from_edi_date(
segment.elements[1]) if elements_lenght > 1 else None) segment.elements[1]) if elements_lenght > 1 else None)
lot = segment.elements[7] if elements_lenght > 6 else None lot = segment.elements[7] if elements_lenght > 6 else None
result = { result = {
'expiry_date': expiry_date.date() if expiry_date else None, 'expiration_date': (expiration_date.date() if expiration_date
else None),
'lot': lot 'lot': lot
} }
return result, NO_ERRORS return result, NO_ERRORS

View file

@ -7,5 +7,6 @@ depends:
stock_scanner stock_scanner
extras_depend: extras_depend:
stock_lot stock_lot
stock_lot_sled
xml: xml:
shipment.xml shipment.xml