Th qt modification
This commit is contained in:
@@ -1530,8 +1530,6 @@ class Line(metaclass=PoolMeta):
|
||||
# alors il faut créer un nouveau lot_qt non shippé et non matché avec le delta
|
||||
# Si delta négatif alors on decrease si c'est possible le lot_qt non shippé non matché et s'il n'y en a pas on envoie un
|
||||
# message d'erreur 'Please unlink or unmatch lot'
|
||||
Lot = Pool().get('lot.lot')
|
||||
LotQt = Pool().get('lot.qt')
|
||||
old_values = {}
|
||||
|
||||
for records, values in zip(args[::2], args[1::2]):
|
||||
@@ -1558,46 +1556,63 @@ class Line(metaclass=PoolMeta):
|
||||
else Decimal(vlot.get_current_quantity_converted() or 0)
|
||||
)
|
||||
delta = new - baseline
|
||||
if delta > 0:
|
||||
new_qty = round(Decimal(vlot.get_current_quantity_converted() or 0) + delta, 5)
|
||||
vlot.set_current_quantity(new_qty, new_qty, 1)
|
||||
Lot.save([vlot])
|
||||
lqts = LotQt.search([
|
||||
('lot_p', '=', vlot.id),
|
||||
('lot_s', '=', None),
|
||||
('lot_shipment_in', '=', None),
|
||||
('lot_shipment_internal', '=', None),
|
||||
('lot_shipment_out', '=', None),
|
||||
])
|
||||
if lqts:
|
||||
lqt = lqts[0]
|
||||
lqt.lot_quantity = round(Decimal(lqt.lot_quantity or 0) + delta, 5)
|
||||
LotQt.save([lqt])
|
||||
else:
|
||||
lqt = LotQt()
|
||||
lqt.lot_p = vlot.id
|
||||
lqt.lot_s = None
|
||||
lqt.lot_quantity = round(delta, 5)
|
||||
lqt.lot_unit = line.unit
|
||||
LotQt.save([lqt])
|
||||
elif delta < 0:
|
||||
decrease = abs(delta)
|
||||
lqts = LotQt.search([
|
||||
('lot_p', '=', vlot.id),
|
||||
('lot_s', '=', None),
|
||||
('lot_shipment_in', '=', None),
|
||||
('lot_shipment_internal', '=', None),
|
||||
('lot_shipment_out', '=', None),
|
||||
])
|
||||
if (not lqts
|
||||
or Decimal(lqts[0].lot_quantity or 0) < decrease):
|
||||
raise UserError("Please unlink or unmatch lot")
|
||||
new_qty = round(Decimal(vlot.get_current_quantity_converted() or 0) - decrease, 5)
|
||||
vlot.set_current_quantity(new_qty, new_qty, 1)
|
||||
Lot.save([vlot])
|
||||
lqt = lqts[0]
|
||||
lqt.lot_quantity = round(Decimal(lqt.lot_quantity or 0) - decrease, 5)
|
||||
LotQt.save([lqt])
|
||||
if delta:
|
||||
physical_quantity = sum(
|
||||
Decimal(lot.get_current_quantity_converted() or 0)
|
||||
for lot in (line.lots or [])
|
||||
if lot.lot_type == 'physic')
|
||||
target_quantity = round(new - physical_quantity, 5)
|
||||
if target_quantity < 0:
|
||||
raise UserError("Please unlink or unmatch lot")
|
||||
cls._sync_open_lot_quantity(line, vlot, target_quantity)
|
||||
|
||||
@classmethod
|
||||
def _sync_open_lot_quantity(cls, line, vlot, target_quantity):
|
||||
Lot = Pool().get('lot.lot')
|
||||
LotQt = Pool().get('lot.qt')
|
||||
|
||||
free_domain = [
|
||||
('lot_p', '=', vlot.id),
|
||||
('lot_s', '=', None),
|
||||
('lot_shipment_in', '=', None),
|
||||
('lot_shipment_internal', '=', None),
|
||||
('lot_shipment_out', '=', None),
|
||||
]
|
||||
free_lqts = LotQt.search(free_domain)
|
||||
allocated_lqts = LotQt.search([
|
||||
('lot_p', '=', vlot.id),
|
||||
[
|
||||
'OR',
|
||||
('lot_s', '!=', None),
|
||||
('lot_shipment_in', '!=', None),
|
||||
('lot_shipment_internal', '!=', None),
|
||||
('lot_shipment_out', '!=', None),
|
||||
],
|
||||
])
|
||||
allocated_quantity = sum(
|
||||
Decimal(lqt.lot_quantity or 0) for lqt in allocated_lqts)
|
||||
free_quantity = round(target_quantity - allocated_quantity, 5)
|
||||
if free_quantity < 0:
|
||||
raise UserError("Please unlink or unmatch lot")
|
||||
|
||||
current_quantity = round(
|
||||
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])
|
||||
|
||||
if free_lqts:
|
||||
lqt = free_lqts[0]
|
||||
if Decimal(lqt.lot_quantity or 0) != free_quantity:
|
||||
lqt.lot_quantity = free_quantity
|
||||
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])
|
||||
|
||||
@classmethod
|
||||
def copy(cls, lines, default=None):
|
||||
|
||||
Reference in New Issue
Block a user