@@ -76,21 +76,53 @@ def _get_stock_valuation_another(self):
7676 # de nombres de produits que d'entrepots dans l'excel
7777 product_qties = self .env ["stock.quant" ].read_group (
7878 [("location_id" , "child_of" , location_ids )],
79- ["product_id" , "quantity" ],
80- ["product_id" ],
79+ ["product_id" , "warehouse_id" , "quantity" ],
80+ ["product_id" , "warehouse_id" ],
81+ lazy = False ,
8182 )
82- product_ids = [x ["product_id" ][0 ] for x in product_qties ]
83+
84+ product_ids = list ({x ["product_id" ][0 ] for x in product_qties })
85+
8386 products = self .env ["product.product" ].browse (product_ids )
8487 prices = {
8588 x : x .variant_seller_ids and x .variant_seller_ids [0 ] or 0 for x in products
8689 }
8790 vals = defaultdict (list )
88- for prd_q in product_qties :
89- product = products .filtered (lambda s : s .id == prd_q ["product_id" ][0 ])
91+
92+ product_dict = {}
93+ for product in product_qties :
94+ if not product ["product_id" ][0 ] in product_dict :
95+ product_dict [product ["product_id" ][0 ]] = [
96+ product ["warehouse_id" ][0 ],
97+ product ["quantity" ],
98+ ]
99+ else :
100+ product_dict [product ["product_id" ][0 ]] += [
101+ product ["warehouse_id" ][0 ],
102+ product ["quantity" ],
103+ ]
104+
105+ for product_id , warehouse_quantities in product_dict .items ():
106+ product = products .filtered (lambda s : s .id == product_id )
107+ vals ["lien" ].append (
108+ f"{ base_url } /web#id={ product_id } &cids={ self .id } &action="
109+ f"{ self .env .ref ('product.product_normal_action_sell' ).id } &model="
110+ "product.product&view_type=form"
111+ )
90112 vals ["code" ].append (product .default_code )
91113 vals ["designation" ].append (product .name )
92- # TODO mettre une colonne qté par entrepot (x colonnes)
93- vals ["qté" ].append (round (prd_q ["quantity" ]))
114+ for i in range (0 , len (warehouse_quantities ), 2 ):
115+ warehouse_id = warehouse_quantities [i ]
116+ quantity = warehouse_quantities [i + 1 ]
117+ warehouse_id = self .env ["stock.warehouse" ].browse (warehouse_id )
118+ vals [f"qté_{ warehouse_id .name } " ].append (round (quantity ))
119+ if len (warehouse_quantities ) / 2 < len (self .valued_warehouse_ids ):
120+ warehouse_without_qty = self .valued_warehouse_ids .filtered (
121+ lambda r : r .id != warehouse_quantities [0 ]
122+ )
123+ for warehouse in warehouse_without_qty :
124+ vals [f"qté_{ warehouse .name } " ].append (0 )
125+
94126 # TODO quand la valeur est < cost_vs_purchase_threshold % de ce seuil
95127 # mettre une colonne 'check' à la valeur 1
96128 vals ["valeur" ].append (
@@ -99,15 +131,9 @@ def _get_stock_valuation_another(self):
99131 product .standard_price ,
100132 prices [product ] and prices [product ].price or 0 * coef / 100 ,
101133 )
102- * prd_q ["quantity" ]
134+ * product ["quantity" ]
103135 )
104136 )
105- # TODO mettre l'url en first column
106- vals ["lien" ].append (
107- f"{ base_url } /web#id={ prd_q ['product_id' ][0 ]} &cids={ self .id } &action="
108- f"{ self .env .ref ('product.product_normal_action_sell' ).id } &model="
109- "product.product&view_type=form"
110- )
111137 df = pl .from_dict (vals )
112138 mfile = io .BytesIO ()
113139 df .write_excel (workbook = mfile )
0 commit comments