From 6a5a267cfdf85bf8c6d99c6cefaf2a140adb812e Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Sat, 13 Jun 2026 11:37:48 +0200 Subject: [PATCH] Unlink open when Add physical lot --- modules/purchase_trade/lot.py | 79 ++++++++++++++----- .../view/lot_add_start_form.xml | 3 + 2 files changed, 62 insertions(+), 20 deletions(-) diff --git a/modules/purchase_trade/lot.py b/modules/purchase_trade/lot.py index 1de807e..3e31a7f 100755 --- a/modules/purchase_trade/lot.py +++ b/modules/purchase_trade/lot.py @@ -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" diff --git a/modules/purchase_trade/view/lot_add_start_form.xml b/modules/purchase_trade/view/lot_add_start_form.xml index 13fa6cc..bb95a5b 100755 --- a/modules/purchase_trade/view/lot_add_start_form.xml +++ b/modules/purchase_trade/view/lot_add_start_form.xml @@ -4,6 +4,9 @@