bug check qt

This commit is contained in:
2026-05-14 12:24:16 +02:00
parent b4d944b10c
commit 3c788d4764
3 changed files with 39 additions and 7 deletions

View File

@@ -912,7 +912,9 @@ class Lot(metaclass=PoolMeta):
fl.lot = lot.id
FeeLots.save([fl])
cls.assert_lots_quantity_consistency(virtual_lots_to_check)
if not Transaction().context.get(
'_purchase_trade_skip_quantity_consistency'):
cls.assert_lots_quantity_consistency(virtual_lots_to_check)
def createVirtualPart(self,qt=0,sh=None,lot_s=None,mode='both'):
lqt = LotQt()

View File

@@ -1729,6 +1729,15 @@ class Line(metaclass=PoolMeta):
allocated_quantity = sum(
Decimal(lqt.lot_quantity or 0) for lqt in allocated_lqts)
free_quantity = round(target_quantity - allocated_quantity, 5)
logger.info(
"PURCHASE_QTY_SYNC line=%s vlot=%s target=%s allocated=%s "
"free=%s free_lqts=%s",
getattr(line, 'id', None),
getattr(vlot, 'id', None),
target_quantity,
allocated_quantity,
free_quantity,
[getattr(lqt, 'id', None) for lqt in free_lqts])
if free_quantity < 0:
raise UserError("Please unlink or unmatch lot")
@@ -1736,20 +1745,26 @@ class Line(metaclass=PoolMeta):
Decimal(vlot.get_current_quantity_converted() or 0), 5)
if current_quantity != target_quantity:
vlot.set_current_quantity(target_quantity, target_quantity, 1)
Lot.save([vlot])
with Transaction().set_context(
_purchase_trade_skip_quantity_consistency=True):
Lot.save([vlot])
if free_lqts:
lqt = free_lqts[0]
if Decimal(lqt.lot_quantity or 0) != free_quantity:
lqt.lot_quantity = free_quantity
LotQt.save([lqt])
with Transaction().set_context(
_purchase_trade_skip_quantity_consistency=True):
LotQt.save([lqt])
elif free_quantity > 0:
lqt = LotQt()
lqt.lot_p = vlot.id
lqt.lot_s = None
lqt.lot_quantity = free_quantity
lqt.lot_unit = line.unit
LotQt.save([lqt])
with Transaction().set_context(
_purchase_trade_skip_quantity_consistency=True):
LotQt.save([lqt])
@classmethod
def copy(cls, lines, default=None):

View File

@@ -1843,6 +1843,15 @@ class SaleLine(metaclass=PoolMeta):
allocated_quantity = sum(
Decimal(lqt.lot_quantity or 0) for lqt in allocated_lqts)
free_quantity = round(target_quantity - allocated_quantity, 5)
logger.info(
"SALE_QTY_SYNC line=%s vlot=%s target=%s allocated=%s "
"free=%s free_lqts=%s",
getattr(line, 'id', None),
getattr(vlot, 'id', None),
target_quantity,
allocated_quantity,
free_quantity,
[getattr(lqt, 'id', None) for lqt in free_lqts])
if free_quantity < 0:
raise UserError("Please unlink or unmatch lot")
@@ -1850,20 +1859,26 @@ class SaleLine(metaclass=PoolMeta):
Decimal(vlot.get_current_quantity_converted() or 0), 5)
if current_quantity != target_quantity:
vlot.set_current_quantity(target_quantity, target_quantity, 1)
Lot.save([vlot])
with Transaction().set_context(
_purchase_trade_skip_quantity_consistency=True):
Lot.save([vlot])
if free_lqts:
lqt = free_lqts[0]
if Decimal(lqt.lot_quantity or 0) != free_quantity:
lqt.lot_quantity = free_quantity
LotQt.save([lqt])
with Transaction().set_context(
_purchase_trade_skip_quantity_consistency=True):
LotQt.save([lqt])
elif free_quantity > 0:
lqt = LotQt()
lqt.lot_p = None
lqt.lot_s = vlot.id
lqt.lot_quantity = free_quantity
lqt.lot_unit = line.unit
LotQt.save([lqt])
with Transaction().set_context(
_purchase_trade_skip_quantity_consistency=True):
LotQt.save([lqt])
@classmethod
def delete(cls, lines):