Allow receive more of one edi supplier shipment per purchase.
This commit refs #21782.
This commit is contained in:
parent
2aed9905f4
commit
63668be67c
44
shipment.py
44
shipment.py
|
@ -75,9 +75,7 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
|
|||
move.state = 'draft'
|
||||
move.company = purchase.company
|
||||
move.currency = purchase.currency
|
||||
move.planned_date = shipment.planned_date
|
||||
move.unit_price = product.list_price
|
||||
move.edi_description = values.get('description')
|
||||
move.shipment = shipment
|
||||
if (quantity or 0) >= 0:
|
||||
move.from_location = purchase.party.supplier_location.id
|
||||
|
@ -110,7 +108,8 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
|
|||
lot.product = product
|
||||
lot.expiry_date = values.get('expiry_date')
|
||||
lot.save()
|
||||
move.lot = lot
|
||||
for move_ in moves_:
|
||||
move_.lot = lot
|
||||
|
||||
pool = Pool()
|
||||
ProductCode = pool.get('product.code')
|
||||
|
@ -147,12 +146,12 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
|
|||
shipment.on_change_supplier()
|
||||
shipment.warehouse = purchase.warehouse
|
||||
shipment.reference = reference.elements[0][2] if reference else None
|
||||
shipment.moves = [m for m in purchase.moves if not m.shipment]
|
||||
available_moves = [m for m in purchase.moves if not m.shipment]
|
||||
|
||||
dtms = [d for d in message.get_segments('DTM')]
|
||||
template_dtm = template_header.get('DTM')
|
||||
effective_date, planned_date, despatch_date, errors = cls._process_DTMs(dtms,
|
||||
template_dtm, control_chars)
|
||||
effective_date, planned_date, despatch_date, errors = \
|
||||
cls._process_DTMs(dtms, template_dtm, control_chars)
|
||||
if errors:
|
||||
total_errors += errors
|
||||
shipment.effective_date = effective_date
|
||||
|
@ -182,7 +181,7 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
|
|||
shipment.save()
|
||||
|
||||
scannable_codes = ProductCode.search([
|
||||
('product', 'in', [l.product.id for l in shipment.moves])
|
||||
('product', 'in', [l.product.id for l in available_moves])
|
||||
])
|
||||
scannable_products = {pc.number: pc.product for pc in scannable_codes}
|
||||
to_save = []
|
||||
|
@ -213,9 +212,10 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
|
|||
product = scannable_products.get(values.get('product'))
|
||||
quantity = values.get('quantity')
|
||||
matching_moves = None
|
||||
moves_ = []
|
||||
if product:
|
||||
matching_moves = [
|
||||
m for m in shipment.moves if m.product == product]
|
||||
m for m in available_moves if m.product == product]
|
||||
if matching_moves:
|
||||
move = matching_moves[0]
|
||||
else:
|
||||
|
@ -228,14 +228,26 @@ class ShipmentIn(EdifactMixin, metaclass=PoolMeta):
|
|||
continue
|
||||
product = product_code.product
|
||||
move = get_new_move()
|
||||
move.quantity = quantity
|
||||
move.edi_quantity = quantity
|
||||
move.edi_description = values.get('description')
|
||||
move_amount = values.get('amount', None)
|
||||
if move_amount:
|
||||
move.unit_price = move_amount / quantity
|
||||
manage_lots()
|
||||
to_save.append(move)
|
||||
if getattr(move, 'purchase') and move.quantity != quantity:
|
||||
diff = move.quantity - quantity
|
||||
if diff > 0:
|
||||
new_move, = Move.copy([move], {'quantity': abs(diff)})
|
||||
move.quantity = quantity
|
||||
else:
|
||||
new_move = get_new_move()
|
||||
new_move.quantity = abs(diff)
|
||||
moves_.append(new_move)
|
||||
move.shipment = shipment
|
||||
moves_.append(move)
|
||||
for move_ in moves_:
|
||||
move_.planned_date = shipment.planned_date
|
||||
move_.edi_quantity = quantity # proportional or original?
|
||||
move_.edi_description = values.get('description')
|
||||
move_amount = values.get('amount', None)
|
||||
if move_amount:
|
||||
move_.unit_price = move_amount / quantity
|
||||
manage_lots()
|
||||
to_save.extend(moves_)
|
||||
|
||||
if to_save:
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue