Bug create contract
This commit is contained in:
@@ -334,6 +334,16 @@ class ContractFactory:
|
|||||||
with Transaction().set_context(
|
with Transaction().set_context(
|
||||||
_purchase_trade_skip_quantity_consistency=True):
|
_purchase_trade_skip_quantity_consistency=True):
|
||||||
lot.save()
|
lot.save()
|
||||||
|
logger.info(
|
||||||
|
"CREATE_CONTRACT_LOT_SAVED type=%s line=%s lot=%s qty=%s "
|
||||||
|
"source_lot=%s source_lqt=%s shipment=%s",
|
||||||
|
type_,
|
||||||
|
getattr(line, 'id', None),
|
||||||
|
getattr(lot, 'id', None),
|
||||||
|
getattr(lot, 'lot_quantity', None),
|
||||||
|
getattr(source.get('lot'), 'id', None),
|
||||||
|
getattr(source.get('lqt'), 'id', None),
|
||||||
|
source.get('shipment_origin'))
|
||||||
|
|
||||||
vlot = source['lot']
|
vlot = source['lot']
|
||||||
shipment_origin = source.get('shipment_origin')
|
shipment_origin = source.get('shipment_origin')
|
||||||
@@ -342,6 +352,14 @@ class ContractFactory:
|
|||||||
if type_ == 'Purchase':
|
if type_ == 'Purchase':
|
||||||
if cls._attach_or_split_source_lot_qt(source, lot, type_):
|
if cls._attach_or_split_source_lot_qt(source, lot, type_):
|
||||||
return
|
return
|
||||||
|
logger.info(
|
||||||
|
"CREATE_CONTRACT_LOT_FALLBACK type=%s new_lot=%s "
|
||||||
|
"source_lot=%s qty=%s shipment=%s",
|
||||||
|
type_,
|
||||||
|
getattr(lot, 'id', None),
|
||||||
|
getattr(vlot, 'id', None),
|
||||||
|
qt,
|
||||||
|
shipment_origin)
|
||||||
if not lot.updateVirtualPart(qt, shipment_origin, vlot):
|
if not lot.updateVirtualPart(qt, shipment_origin, vlot):
|
||||||
lot.createVirtualPart(qt, shipment_origin, vlot)
|
lot.createVirtualPart(qt, shipment_origin, vlot)
|
||||||
|
|
||||||
@@ -350,6 +368,14 @@ class ContractFactory:
|
|||||||
else:
|
else:
|
||||||
if cls._attach_or_split_source_lot_qt(source, lot, type_):
|
if cls._attach_or_split_source_lot_qt(source, lot, type_):
|
||||||
return
|
return
|
||||||
|
logger.info(
|
||||||
|
"CREATE_CONTRACT_LOT_FALLBACK type=%s new_lot=%s "
|
||||||
|
"source_lot=%s qty=%s shipment=%s",
|
||||||
|
type_,
|
||||||
|
getattr(lot, 'id', None),
|
||||||
|
getattr(vlot, 'id', None),
|
||||||
|
qt,
|
||||||
|
shipment_origin)
|
||||||
if not vlot.updateVirtualPart(qt, shipment_origin, lot):
|
if not vlot.updateVirtualPart(qt, shipment_origin, lot):
|
||||||
vlot.createVirtualPart(qt, shipment_origin, lot)
|
vlot.createVirtualPart(qt, shipment_origin, lot)
|
||||||
|
|
||||||
@@ -367,12 +393,35 @@ class ContractFactory:
|
|||||||
if not source_lqt:
|
if not source_lqt:
|
||||||
source_lqt = cls._find_source_lot_qt(source, type_)
|
source_lqt = cls._find_source_lot_qt(source, type_)
|
||||||
if not source_lqt:
|
if not source_lqt:
|
||||||
|
logger.info(
|
||||||
|
"CREATE_CONTRACT_ATTACH_SKIP no source_lqt type=%s "
|
||||||
|
"new_lot=%s source_lot=%s qty=%s shipment=%s",
|
||||||
|
type_,
|
||||||
|
getattr(new_virtual_lot, 'id', None),
|
||||||
|
getattr(source.get('lot'), 'id', None),
|
||||||
|
quantity,
|
||||||
|
source.get('shipment_origin'))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
remaining = cls._normalize_quantity(source_lqt.lot_quantity) - quantity
|
remaining = cls._normalize_quantity(source_lqt.lot_quantity) - quantity
|
||||||
if remaining < 0:
|
if remaining < 0:
|
||||||
|
logger.info(
|
||||||
|
"CREATE_CONTRACT_ATTACH_SKIP insufficient source_lqt=%s "
|
||||||
|
"available=%s qty=%s",
|
||||||
|
getattr(source_lqt, 'id', None),
|
||||||
|
getattr(source_lqt, 'lot_quantity', None),
|
||||||
|
quantity)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
"CREATE_CONTRACT_ATTACH type=%s source_lqt=%s new_lot=%s "
|
||||||
|
"source_lot=%s qty=%s remaining=%s",
|
||||||
|
type_,
|
||||||
|
getattr(source_lqt, 'id', None),
|
||||||
|
getattr(new_virtual_lot, 'id', None),
|
||||||
|
getattr(source.get('lot'), 'id', None),
|
||||||
|
quantity,
|
||||||
|
remaining)
|
||||||
if remaining:
|
if remaining:
|
||||||
matched_lqt = LotQt()
|
matched_lqt = LotQt()
|
||||||
matched_lqt.lot_p = (
|
matched_lqt.lot_p = (
|
||||||
@@ -423,10 +472,34 @@ class ContractFactory:
|
|||||||
cls._add_shipment_domain(domain, source.get('shipment_origin'))
|
cls._add_shipment_domain(domain, source.get('shipment_origin'))
|
||||||
domain.append(('lot_quantity', '!=', 0))
|
domain.append(('lot_quantity', '!=', 0))
|
||||||
lqts = LotQt.search(domain)
|
lqts = LotQt.search(domain)
|
||||||
|
if not lqts and source.get('shipment_origin'):
|
||||||
|
domain = domain[:2] + [
|
||||||
|
('lot_quantity', '!=', 0),
|
||||||
|
]
|
||||||
|
lqts = LotQt.search(domain)
|
||||||
quantity = cls._normalize_quantity(source['quantity'])
|
quantity = cls._normalize_quantity(source['quantity'])
|
||||||
|
for lqt in lqts:
|
||||||
|
if cls._normalize_quantity(lqt.lot_quantity) == quantity:
|
||||||
|
return lqt
|
||||||
for lqt in lqts:
|
for lqt in lqts:
|
||||||
if cls._normalize_quantity(lqt.lot_quantity) >= quantity:
|
if cls._normalize_quantity(lqt.lot_quantity) >= quantity:
|
||||||
return lqt
|
return lqt
|
||||||
|
logger.info(
|
||||||
|
"CREATE_CONTRACT_FIND_SOURCE_LQT_EMPTY type=%s lot=%s qty=%s "
|
||||||
|
"shipment=%s candidates=%s",
|
||||||
|
type_,
|
||||||
|
getattr(lot, 'id', None),
|
||||||
|
quantity,
|
||||||
|
source.get('shipment_origin'),
|
||||||
|
[
|
||||||
|
(
|
||||||
|
getattr(lqt, 'id', None),
|
||||||
|
getattr(lqt, 'lot_quantity', None),
|
||||||
|
getattr(getattr(lqt, 'lot_p', None), 'id', None),
|
||||||
|
getattr(getattr(lqt, 'lot_s', None), 'id', None),
|
||||||
|
)
|
||||||
|
for lqt in lqts
|
||||||
|
])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user