Unlink open when Add physical lot

This commit is contained in:
2026-06-13 11:37:48 +02:00
parent 5c9f437945
commit 6a5a267cfd
2 changed files with 62 additions and 20 deletions

View File

@@ -1591,6 +1591,36 @@ class LotQt(
cls.create([cls._planned_scheduled_values(
physical_lot, quantity, quantity_lot_s, shipment_origin)])
@classmethod
def unlink_transport_remainder(cls, lqt):
if not lqt or not lqt.has_shipment():
return []
quantity = Decimal(str(lqt.lot_quantity or 0))
if quantity <= 0:
return []
mode = 'both'
if not lqt.lot_p:
lot = lqt.lot_s
mode = 'only sale'
else:
lot = lqt.lot_p
if not lot:
return []
lot.updateVirtualPart(
-quantity, lqt.lot_shipment_origin, lqt.lot_s, mode)
if lqt.is_planned_transport():
cls.restore_planned_open_quantity(lqt, quantity)
elif not lot.updateVirtualPart(quantity, None, lqt.lot_s, mode):
lot.createVirtualPart(quantity, None, lqt.lot_s, mode)
affected_lines = []
if lqt.lot_p and lqt.lot_p.line:
affected_lines.append(lqt.lot_p.line)
if lqt.lot_s and lqt.lot_s.sale_line:
affected_lines.append(lqt.lot_s.sale_line)
return affected_lines
def isVirtualP(self):
if self.lot_p:
Lot = Pool().get('lot.lot')
@@ -1791,7 +1821,7 @@ class LotQt(
qt_p = left_qt
@classmethod
def add_physical_lots(cls,lqt,vlots):
def add_physical_lots(cls, lqt, vlots, unlink_remainder=False):
Purchase = Pool().get('purchase.purchase')
LotQt = Pool().get('lot.qt')
Lot = Pool().get('lot.lot')
@@ -1825,6 +1855,8 @@ class LotQt(
#create move for lots
Purchase._process_shipment([purchase],lots)
affected_lines = []
if unlink_remainder:
affected_lines.extend(cls.unlink_transport_remainder(lqt))
if lqt.lot_p and lqt.lot_p.line:
affected_lines.append(lqt.lot_p.line)
if lqt.lot_s and lqt.lot_s.sale_line:
@@ -4241,33 +4273,40 @@ class LotAdding(Wizard):
sh_out = lqt.lot_shipment_out.id if lqt.lot_shipment_out else None
else:
raise UserError("Trying to add physical lots to physical lot!")
return {
'unit': unit,
'quantity': quantity,
'shipment_in':sh_in,
'shipment_internal':sh_int,
'shipment_out':sh_out,
}
return {
'unit': unit,
'quantity': quantity,
'unlink_remainder': True,
'shipment_in':sh_in,
'shipment_internal':sh_int,
'shipment_out':sh_out,
}
def transition_adding(self):
if self.records:
LotQt = Pool().get('lot.qt')
lqt = LotQt(self.records[0].id - 10000000)
LotQt.add_physical_lots(lqt,self.add.lots)
return 'end'
if self.records:
LotQt = Pool().get('lot.qt')
lqt = LotQt(self.records[0].id - 10000000)
LotQt.add_physical_lots(
lqt, self.add.lots, self.add.unlink_remainder)
return 'end'
def end(self):
return 'reload'
class LotAddLot(ModelView):
"Add physical lots"
__name__ = "lot.add.lot"
unit = fields.Many2One('product.uom',"Unit",readonly=True)
quantity = fields.Numeric("Quantity available",digits='unit',readonly=True)
shipment_in = fields.Many2One('stock.shipment.in',"Shipment In",states={'invisible': ~Eval('shipment_in')})
shipment_internal = fields.Many2One('stock.shipment.internal',"Shipment Internal",states={'invisible': ~Eval('shipment_internal')})
shipment_out = fields.Many2One('stock.shipment.out',"Shipment Out",states={'invisible': ~Eval('shipment_out')})
lots = fields.One2Many('lot.add.line','lal',"Lots")
__name__ = "lot.add.lot"
unit = fields.Many2One('product.uom',"Unit",readonly=True)
quantity = fields.Numeric("Quantity available",digits='unit',readonly=True)
unlink_remainder = fields.Boolean("Unlink remaining quantity")
shipment_in = fields.Many2One('stock.shipment.in',"Shipment In",states={'invisible': ~Eval('shipment_in')})
shipment_internal = fields.Many2One('stock.shipment.internal',"Shipment Internal",states={'invisible': ~Eval('shipment_internal')})
shipment_out = fields.Many2One('stock.shipment.out',"Shipment Out",states={'invisible': ~Eval('shipment_out')})
lots = fields.One2Many('lot.add.line','lal',"Lots")
@classmethod
def default_unlink_remainder(cls):
return True
class LotAddLine(ModelView):
"Lots"

View File

@@ -4,6 +4,9 @@
<label name="unit"/>
<field name="unit"/>
<newline/>
<label name="unlink_remainder"/>
<field name="unlink_remainder"/>
<newline/>
<label name="shipment_in"/>
<field name="shipment_in"/>
<label name="shipment_internal"/>