-
-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] stock_location_orderpoint_source_relocate
Fix quantity to replenish in case of source relocation
- Loading branch information
Showing
3 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import stock_location_orderpoint | ||
from . import stock_move |
43 changes: 43 additions & 0 deletions
43
stock_location_orderpoint_source_relocate/models/stock_location_orderpoint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters