diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-04-17 17:06:30 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-04-17 17:06:30 +0700 |
| commit | fcb65326ffd7daf6136a97b53cca5493964d94aa (patch) | |
| tree | 1e73ae6962828a5bc7047301825b73c33b3cb922 | |
| parent | de6450a17a85c063fe49705991098116efccae75 (diff) | |
push
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 85428aa0..f04b0e79 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1559,6 +1559,34 @@ class CheckProduct(models.Model): else: raise UserError("Product tidak ditemukan") + def unlink(self): + # Get all affected pickings before deletion + pickings = self.mapped('picking_id') + + # Store product_ids that will be deleted + deleted_product_ids = self.mapped('product_id') + + # Perform the deletion + result = super(CheckProduct, self).unlink() + + # After deletion, update moves for affected pickings + for picking in pickings: + # For products that were completely removed (no remaining check.product lines) + remaining_product_ids = picking.check_product_lines.mapped('product_id') + removed_product_ids = deleted_product_ids - remaining_product_ids + + # Set quantity_done to 0 for moves of completely removed products + moves_to_reset = picking.move_ids_without_package.filtered( + lambda move: move.product_id in removed_product_ids + ) + for move in moves_to_reset: + move.quantity_done = 0.0 + + # Also sync remaining products in case their totals changed + self._sync_check_product_to_moves(picking) + + return result + @api.depends('quantity') def _compute_status(self): for record in self: |
