From 5c6098158ab0f82437aa24e947a66b78b21b6bd7 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 12 Sep 2024 13:58:27 +0700 Subject: push --- indoteknik_custom/models/stock_move.py | 44 +++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/stock_move.py') diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py index fe46bf65..6c44f8a6 100644 --- a/indoteknik_custom/models/stock_move.py +++ b/indoteknik_custom/models/stock_move.py @@ -1,5 +1,6 @@ from odoo import fields, models, api - +from odoo.tools.misc import format_date, OrderedSet +from odoo.exceptions import UserError class StockMove(models.Model): _inherit = 'stock.move' @@ -7,6 +8,47 @@ class StockMove(models.Model): line_no = fields.Integer('No', default=0) sale_id = fields.Many2one('sale.order', string='SO') + def _do_unreserve(self, product=None, quantity=None): + moves_to_unreserve = OrderedSet() + for move in self: + if move.state == 'cancel' or (move.state == 'done' and move.scrapped): + continue + elif move.state == 'done': + raise UserError(_("You cannot unreserve a stock move that has been set to 'Done'.")) + + 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: + # 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 + ml.write({'product_uom_qty': remaining_qty if remaining_qty > 0 else 0}) + quantity = 0 # Set to zero to prevent further unreserving in the same loop + elif ml.qty_done: + ml_to_update.add(ml.id) + 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) + + ml_to_unlink.unlink() + (moves_to_unreserve - moves_not_to_recompute)._recompute_state() + 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 -- cgit v1.2.3 From b473179e5adde097bc9ec43ee4566b850937f1ed Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 13 Sep 2024 10:25:03 +0700 Subject: unreserve --- indoteknik_custom/models/stock_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/stock_move.py') diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py index 6c44f8a6..cd061946 100644 --- a/indoteknik_custom/models/stock_move.py +++ b/indoteknik_custom/models/stock_move.py @@ -14,7 +14,7 @@ class StockMove(models.Model): if move.state == 'cancel' or (move.state == 'done' and move.scrapped): continue elif move.state == 'done': - raise UserError(_("You cannot unreserve a stock move that has been set to 'Done'.")) + raise UserError("You cannot unreserve a stock move that has been set to 'Done'.") if product and move.product_id != product: continue # Skip moves that don't match the specified product -- cgit v1.2.3 From b2f9da06ff526a005f7e71c85a4c626971b5c06b Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 23 Sep 2024 11:40:58 +0700 Subject: push --- indoteknik_custom/models/stock_move.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'indoteknik_custom/models/stock_move.py') 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 -- cgit v1.2.3 From 1f9d0136758531831ea6c7a90556c9a472ed8d40 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 23 Sep 2024 13:20:39 +0700 Subject: push --- indoteknik_custom/models/stock_move.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'indoteknik_custom/models/stock_move.py') diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py index 32ef312f..ac2e3cc0 100644 --- a/indoteknik_custom/models/stock_move.py +++ b/indoteknik_custom/models/stock_move.py @@ -8,7 +8,7 @@ class StockMove(models.Model): line_no = fields.Integer('No', default=0) sale_id = fields.Many2one('sale.order', string='SO') - def _do_unreserve(self, product=None, quantity=None): + def _do_unreserve(self, product=None, quantity=False): moves_to_unreserve = OrderedSet() for move in self: if move.state == 'cancel' or (move.state == 'done' and move.scrapped): @@ -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 is not None and quantity > 0: + if quantity 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,7 +49,6 @@ 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 -- cgit v1.2.3