diff options
| -rw-r--r-- | indoteknik_custom/models/approval_unreserve.py | 42 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_move.py | 9 |
2 files changed, 27 insertions, 24 deletions
diff --git a/indoteknik_custom/models/approval_unreserve.py b/indoteknik_custom/models/approval_unreserve.py index 72e3ff51..00fd1555 100644 --- a/indoteknik_custom/models/approval_unreserve.py +++ b/indoteknik_custom/models/approval_unreserve.py @@ -86,28 +86,30 @@ class ApprovalUnreserve(models.Model): move = stock_move_obj.browse(line.move_id.id) move._do_unreserve(product=line.product_id, quantity=line.unreserve_qty) + line.dest_picking_id.action_assign() + # Step 2: Update existing stock move in dest_picking_id - if line.dest_picking_id: - dest_move = stock_move_obj.search([ - ('picking_id', '=', line.dest_picking_id.id), - ('product_id', '=', line.product_id.id), - ('state', 'not in', ['cancel', 'done']) # Only draft or assigned moves can be updated - ], limit=1) - - if dest_move: - # Add the unreserved quantity to the existing stock move - dest_move.write({ - 'product_uom_qty': dest_move.product_uom_qty + line.unreserve_qty - }) + # if line.dest_picking_id: + # dest_move = stock_move_obj.search([ + # ('picking_id', '=', line.dest_picking_id.id), + # ('product_id', '=', line.product_id.id), + # ('state', 'not in', ['cancel', 'done']) # Only draft or assigned moves can be updated + # ], limit=1) + + # if dest_move: + # # Add the unreserved quantity to the existing stock move + # dest_move.write({ + # 'product_uom_qty': dest_move.product_uom_qty + line.unreserve_qty + # }) - # If the move is in draft state, confirm it and reserve the product - if dest_move.state == 'draft': - dest_move._action_confirm() - dest_move._action_assign() # Reserve the product - - else: - # If no move is found, raise an error or handle accordingly - raise UserError(f"No stock move found for product {line.product_id.display_name} in the destination picking.") + # # If the move is in draft state, confirm it and reserve the product + # if dest_move.state == 'draft': + # dest_move._action_confirm() + # dest_move._action_assign() # Reserve the product + + # else: + # # If no move is found, raise an error or handle accordingly + # raise UserError(f"No stock move found for product {line.product_id.display_name} in the destination picking.") class ApprovalUnreserveLine(models.Model): _name = 'approval.unreserve.line' diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py index cd061946..32ef312f 100644 --- a/indoteknik_custom/models/stock_move.py +++ b/indoteknik_custom/models/stock_move.py @@ -19,17 +19,17 @@ class StockMove(models.Model): if product and move.product_id != product: continue # Skip moves that don't match the specified product moves_to_unreserve.add(move.id) - + moves_to_unreserve = self.env['stock.move'].browse(moves_to_unreserve) ml_to_update, ml_to_unlink = OrderedSet(), OrderedSet() moves_not_to_recompute = OrderedSet() - + for ml in moves_to_unreserve.move_line_ids: if product and ml.product_id != product: continue # Only affect the specified product - if quantity > 0: + if quantity is not None and quantity > 0: # Only reduce by the specified quantity if it is greater than zero ml_to_update.add(ml.id) remaining_qty = ml.product_uom_qty - quantity @@ -40,7 +40,7 @@ class StockMove(models.Model): else: ml_to_unlink.add(ml.id) moves_not_to_recompute.add(ml.move_id.id) - + ml_to_update, ml_to_unlink = self.env['stock.move.line'].browse(ml_to_update), self.env['stock.move.line'].browse(ml_to_unlink) moves_not_to_recompute = self.env['stock.move'].browse(moves_not_to_recompute) @@ -49,6 +49,7 @@ class StockMove(models.Model): return True + def _prepare_account_move_line_from_mr(self, po_line, qty, move=False): po_line.ensure_one() aml_currency = move and move.currency_id or po_line.currency_id |
