Skip to content

Commit 6b4adfd

Browse files
committed
[IMP] _get_stock_valuation_another function to add the quantity in stock by warehouse
1 parent e9a1f45 commit 6b4adfd

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

account_move_adyen_import/static/description/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger (goodger@python.org)
11-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {

account_stock_situation/models/company.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

account_stock_situation/static/description/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger (goodger@python.org)
11-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {

0 commit comments

Comments
 (0)