Remove lots

This commit is contained in:
2026-05-06 09:40:53 +02:00
parent bfa874da43
commit d4da45344c

View File

@@ -2129,12 +2129,17 @@ class LotShippingStart(ModelView):
def default_shipment(cls):
return 'in'
class QtWarning(UserWarning):
pass
class LotMatching(Wizard):
"Matching"
__name__ = "lot.matching"
class QtWarning(UserWarning):
pass
class LotRemoveWarning(UserWarning):
pass
class LotMatching(Wizard):
"Matching"
__name__ = "lot.matching"
start = StateTransition()
@@ -2620,31 +2625,55 @@ class LotImportLot(ModelView):
lp.append(val)
return lp
class LotRemove(Wizard):
"Remove lots"
__name__ = "lot.remove"
start = StateTransition()
def transition_start(self):
Lot = Pool().get('lot.lot')
Move = Pool().get('stock.move')
PL = Pool().get('purchase.line')
for r in self.records:
if r.id > 10000000 :
raise UserError("Trying to remove open lots!")
if r.r_lot_s:
raise UserError("Trying to remove matched lots!")
if r.r_lot_shipment_in or r.r_lot_shipment_internal or r.r_lot_shipment_out:
raise UserError("Trying to remove shipped lots!")
lot = Lot(r.id)
#delete move first if exist
if lot.move:
Move.delete([lot.move])
if not lot.updateVirtualPart(lot.get_current_quantity_converted(),None,None):
lot.createVirtualPart(lot.get_current_quantity_converted(),None,None)
Lot.delete([lot])
return 'end'
class LotRemove(Wizard):
"Remove lots"
__name__ = "lot.remove"
start = StateTransition()
@staticmethod
def _remove_warning_message(lot):
messages = []
if lot.sale_line:
messages.append("matched")
if (lot.lot_shipment_in or lot.lot_shipment_internal
or lot.lot_shipment_out):
messages.append("shipped")
if messages:
return (
"This physical lot is %s. By clicking yes, the physical lot "
"and its draft stock move will be deleted and the quantity "
"will be restored as open quantity."
% " and ".join(messages))
return None
def transition_start(self):
Lot = Pool().get('lot.lot')
Move = Pool().get('stock.move')
Warning = Pool().get('res.user.warning')
for r in self.records:
if r.id > 10000000 :
raise UserError("Trying to remove open lots!")
lot = Lot(r.id)
if lot.move and lot.move.state != 'draft':
raise UserError(
"Trying to remove a lot with a stock move that is not "
"draft!")
warning_message = self._remove_warning_message(lot)
if warning_message:
warning_name = Warning.format("Remove physical lot", [lot])
if Warning.check(warning_name):
raise LotRemoveWarning(warning_name, warning_message)
quantity = lot.get_current_quantity_converted()
shipment_origin = lot.lot_shipment_origin
lot_s = lot.getVlot_s() if lot.sale_line else None
#delete move first if exist
if lot.move:
Move.delete([lot.move])
if not lot.updateVirtualPart(quantity, shipment_origin, lot_s):
lot.createVirtualPart(quantity, shipment_origin, lot_s)
Lot.delete([lot])
return 'end'
def end(self):
return 'reload'