[FIX] stock_location_orderpoint

Check orderpoints also for non relocated moves
Fix quantity to replenish in case of partial source relocation
This commit is contained in:
Jacques-Etienne Baudoux
2023-09-19 16:19:04 +02:00
parent 823c177d96
commit 15b7ac745d
8 changed files with 146 additions and 46 deletions

View File

@@ -1 +1,2 @@
from . import stock_location_orderpoint
from . import stock_move

View File

@@ -0,0 +1,43 @@
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, models
from odoo.tools import float_round
class StockLocationOrderpoint(models.Model):
_inherit = "stock.location.orderpoint"
@api.model
def _compute_quantities_dict(self, locations, products):
qties = super()._compute_quantities_dict(locations, products)
# With the source relocation, we could have stock on the location that
# is reserved by moves with a source location on the parent location.
# Those moves are not considered by the standard virtual available
# stock.
Move = self.env["stock.move"].with_context(active_test=False)
for location, location_dict in qties.items():
products = products.with_context(location=location.id)
_, _, domain_move_out_loc = products._get_domain_locations()
domain_move_out_loc_todo = [
(
"state",
"in",
("waiting", "confirmed", "assigned", "partially_available"),
)
] + domain_move_out_loc
for product, qty in location_dict.items():
moves = Move.search(
domain_move_out_loc_todo + [("product_id", "=", product.id)],
order="id",
)
rounding = product.uom_id.rounding
unreserved_availability = float_round(
qty["outgoing_qty"] - sum(m.reserved_availability for m in moves),
precision_rounding=rounding,
)
qty["virtual_available"] = float_round(
qty["free_qty"] + qty["incoming_qty"] - unreserved_availability,
precision_rounding=rounding,
)
return qties

View File

@@ -1,4 +1,5 @@
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
@@ -6,17 +7,12 @@ from odoo import models
class StockMove(models.Model):
_inherit = "stock.move"
def _action_assign(self, *args, **kwargs):
def _action_assign(self):
self = self.with_context(skip_auto_replenishment=True)
res = super()._action_assign(*args, **kwargs)
self = self.with_context(skip_auto_replenishment=False)
return res
super()._action_assign()
def _apply_source_relocate_rule(self, *args, **kwargs):
relocated = super()._apply_source_relocate_rule(*args, **kwargs)
if not relocated:
return relocated
relocated.with_context(
skip_auto_replenishment=False
)._prepare_auto_replenishment_for_waiting_moves()
return relocated
def _apply_source_relocate(self):
res = super()._apply_source_relocate()
res = res.with_context(skip_auto_replenishment=False)
res._prepare_auto_replenishment_for_waiting_moves()
return res