22# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33from collections import defaultdict
44
5- from odoo import fields , models
5+ from odoo import api , fields , models
66from odoo .tools import float_compare
77from odoo .tools .safe_eval import safe_eval
88
@@ -14,36 +14,38 @@ class ProductProduct(models.Model):
1414 _inherit = "product.product"
1515
1616 quantity_to_replenish = fields .Float (
17- compute = "_compute_available_quantities " ,
17+ compute = "_compute_replenishment_quantities " ,
1818 search = "_search_quantity_to_replenish" ,
19+ prefetch = False ,
1920 help = "This is the quantity to replenish following the location orderpoints." ,
2021 )
2122 quantity_in_replenishments = fields .Float (
22- compute = "_compute_available_quantities " ,
23+ compute = "_compute_replenishment_quantities " ,
2324 search = "_search_quantity_in_replenishments" ,
25+ prefetch = False ,
2426 help = "This is the quantity currently in replenishments following the "
2527 "location orderpoints." ,
2628 )
2729
28- def _compute_available_quantities_dict (self ):
29- """
30- Retrieve all replenishment quantities for the selected products
31- and locations.
32- """
33- res , stock_dict = super ()._compute_available_quantities_dict ()
34- location_domain = self ._get_domain_location_for_locations ()
35- locations = self .env ["stock.location" ].search (location_domain )
30+ @api .depends_context ("location" )
31+ def _compute_replenishment_quantities (self ):
3632 orderpoint_obj = self .env ["stock.location.orderpoint" ]
3733 if orderpoint_obj .check_access_rights ("read" , raise_exception = False ):
34+ orderpoint_obj = self .env ["stock.location.orderpoint" ]
35+ location_domain = self ._get_domain_location_for_locations ()
36+ locations = self .env ["stock.location" ].search (location_domain )
3837 orderpoint_domain = orderpoint_obj ._prepare_orderpoint_domain_location (
3938 locations .ids
4039 )
4140 orderpoints = orderpoint_obj .search (orderpoint_domain )
4241 else :
43- for product in self :
44- res [product .id ]["quantity_to_replenish" ] = 0
45- res [product .id ]["quantity_in_replenishments" ] = 0
46- return res , stock_dict
42+ self .update (
43+ {
44+ "quantity_to_replenish" : 0.0 ,
45+ "quantity_in_replenishments" : 0.0 ,
46+ }
47+ )
48+ return
4749
4850 # Merge both source locations and destination locations
4951 location_ids = set (
@@ -84,14 +86,18 @@ def _compute_available_quantities_dict(self):
8486 )
8587 > 0
8688 ):
89+ # We take the maximum value from all the concerned orderpoints
90+ # for the product
8791 qties_replenished_for_location [product ] += qty_to_replenish
88- res [product .id ][
89- "quantity_in_replenishments"
90- ] = quantities_in_replenishments [product .id ]
91- res [product .id ]["quantity_to_replenish" ] = qties_replenished_for_location [
92- product
93- ]
94- return res , stock_dict
92+ product .update (
93+ {
94+ "quantity_in_replenishments" : quantities_in_replenishments [
95+ product .id
96+ ],
97+ "quantity_to_replenish" : qties_replenished_for_location [product ],
98+ }
99+ )
100+ return
95101
96102 def _get_search_quantity_to_replenish_domain (self ):
97103 return [("type" , "=" , "product" )]
0 commit comments