Skip to content

Commit

Permalink
TA#63698 [FIX] stock_auto_assign_disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
majouda committed May 1, 2024
1 parent 6f04703 commit 8eac9fe
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 46 deletions.
49 changes: 6 additions & 43 deletions stock_auto_assign_disabled/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# © 2022 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo import models


class StockMove(models.Model):
Expand All @@ -15,53 +15,16 @@ def _action_assign(self):
)
should_disable = self._context.get("stock_auto_assign_disable")
if mode == "off" or not should_disable:
super()._action_assign()
return super(StockMove, self)._action_assign()
elif mode == "serial_lot":
self_filtered = self.filtered(
lambda x: x._should_process_auto_reservation()
)
super(StockMove, self_filtered)._action_assign()

def _should_process_auto_reservation(self):
return self.product_id.tracking not in ["serial", "lot"]

def _should_bypass_reservation(self):
self.ensure_one()
mode = (
self.env["ir.config_parameter"]
.sudo()
.get_param("stock_auto_assign_disabled.config", "off")
)
if mode == "all":
elif mode == "all":
return True
else:
return super()._should_bypass_reservation()

@api.depends("move_line_ids.product_qty")
def _compute_reserved_availability(self):
super()._compute_reserved_availability()
if any(self._ids):
for move in self:
mode = (
self.env["ir.config_parameter"]
.sudo()
.get_param("stock_auto_assign_disabled.config", "off")
)
if mode == "all":
move.reserved_availability = 0.0

return super(StockMove, self)._action_assign()

class StockMoveLine(models.Model):
_inherit = "stock.move.line"

def _should_bypass_reservation(self, location):
self.ensure_one()
mode = (
self.env["ir.config_parameter"]
.sudo()
.get_param("stock_auto_assign_disabled.config", "off")
)
if mode == "all":
return True
else:
return super()._should_bypass_reservation(location)
def _should_process_auto_reservation(self):
return self.product_id.tracking not in ["serial", "lot"]
2 changes: 2 additions & 0 deletions stock_auto_assign_disabled/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# © 2022 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_auto_assign
2 changes: 1 addition & 1 deletion stock_auto_assign_disabled/tests/test_auto_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ def test_scheduler_no_lot(self):
assert self.stock_move.reserved_availability == 5.0

def _run_scheduler(self, group, user):
group.sudo(user).run_scheduler()
group.with_user(user).run_scheduler()
6 changes: 5 additions & 1 deletion stock_auto_assign_disabled_jit/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

def _action_launch_stock_rule(self, previous_product_uom_qty=False):
super()._action_launch_stock_rule(previous_product_uom_qty=previous_product_uom_qty)
self_with_context = self.with_context(stock_auto_assign_disable=True)
res = super(SaleOrderLine, self_with_context)._action_launch_stock_rule(
previous_product_uom_qty=previous_product_uom_qty
)
return res
2 changes: 2 additions & 0 deletions stock_auto_assign_disabled_jit/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# © 2022 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_auto_assign
2 changes: 1 addition & 1 deletion stock_auto_assign_disabled_jit/tests/test_auto_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ def test_no_reservation(self):
assert self.order_line.move_ids.reserved_availability == 0

def _confirm_sale_order(self):
self.sale_order.sudo(self.user).action_confirm()
self.sale_order.with_user(self.user).action_confirm()

0 comments on commit 8eac9fe

Please sign in to comment.