@@ -71,13 +71,11 @@ def _get_stock_valuation(self):
7171 if tools .config .get ("running_env" ) == "dev" :
7272 base_url = "http://anothercorp.localhost/"
7373 location_ids = [x .lot_stock_id .id for x in self .valued_warehouse_ids ]
74-
7574 stock_quant_ids = self .env ["stock.quant" ].search (
7675 [("location_id" , "child_of" , location_ids )],
7776 )
7877 products = self .env ["product.product" ].browse (stock_quant_ids .product_id .ids )
7978 vals = defaultdict (list )
80-
8179 product_dict = {}
8280 for stock_quant in stock_quant_ids :
8381 if stock_quant .product_id .id not in product_dict :
@@ -86,14 +84,16 @@ def _get_stock_valuation(self):
8684 stock_quant .quantity ,
8785 ]
8886 else :
89- if stock_quant .warehouse_id in product_dict [stock_quant .product_id .id ]:
87+ if (
88+ stock_quant .warehouse_id
89+ in product_dict .get (stock_quant .product_id .id )[0 ]
90+ ):
9091 product_dict [stock_quant .product_id .id ][1 ] += stock_quant .quantity
9192 else :
9293 product_dict [stock_quant .product_id .id ] += [
9394 stock_quant .warehouse_id ,
9495 stock_quant .quantity ,
9596 ]
96-
9797 for product_id , warehouse_quantities in product_dict .items ():
9898 product = products .filtered (lambda s : s .id == product_id )
9999 vals ["link" ].append (
@@ -103,7 +103,6 @@ def _get_stock_valuation(self):
103103 )
104104 vals ["code" ].append (product .default_code )
105105 vals ["designation" ].append (product .name )
106-
107106 for i in range (0 , len (warehouse_quantities ), 2 ):
108107 warehouse_id = warehouse_quantities [i ]
109108 quantity = warehouse_quantities [i + 1 ]
@@ -120,7 +119,6 @@ def _get_stock_valuation(self):
120119 vals [f"qty_{ warehouse .code } " ].append (0 )
121120
122121 vals ["value" ].append (round (product .standard_price ))
123-
124122 df = pl .from_dict (vals )
125123 mfile = io .BytesIO ()
126124 df .write_excel (workbook = mfile )
@@ -132,4 +130,4 @@ def _get_stock_valuation(self):
132130 "datas" : base64 .b64encode (mfile .getvalue ()),
133131 }
134132 )
135- return sum (vals ["valeur " ]), attach
133+ return sum (vals ["value " ]), attach
0 commit comments