Skip to content

Commit

Permalink
[IMP] _get_stock_valuation_another function to add the quantity in st…
Browse files Browse the repository at this point in the history
…ock by warehouse
  • Loading branch information
mathieudelva committed Aug 9, 2024
1 parent e9a1f45 commit b979984
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 20 deletions.
7 changes: 4 additions & 3 deletions account_move_adyen_import/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down
1 change: 1 addition & 0 deletions account_stock_situation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import company
from . import config_settings
from . import stock_quant
58 changes: 44 additions & 14 deletions account_stock_situation/models/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,57 @@ def _get_stock_valuation_another(self):
# de nombres de produits que d'entrepots dans l'excel
product_qties = self.env["stock.quant"].read_group(
[("location_id", "child_of", location_ids)],
["product_id", "quantity"],
["product_id"],
["product_id", "warehouse_id", "quantity"],
["product_id", "warehouse_id"],
lazy=False,
)
product_ids = [x["product_id"][0] for x in product_qties]

product_ids = list({x["product_id"][0] for x in product_qties})

products = self.env["product.product"].browse(product_ids)
prices = {
x: x.variant_seller_ids and x.variant_seller_ids[0] or 0 for x in products
}
vals = defaultdict(list)
for prd_q in product_qties:
product = products.filtered(lambda s: s.id == prd_q["product_id"][0])

product_dict = {}
for product in product_qties:
if not product["product_id"][0] in product_dict:
product_dict[product["product_id"][0]] = [
product["warehouse_id"][0],
product["quantity"],
]
else:
product_dict[product["product_id"][0]] += [
product["warehouse_id"][0],
product["quantity"],
]

for product_id, warehouse_quantities in product_dict.items():
product = products.filtered(lambda s: s.id == product_id)
vals["lien"].append(
f"{base_url}/web#id={product_id}&cids={self.id}&action="
f"{self.env.ref('product.product_normal_action_sell').id}&model="
"product.product&view_type=form"
)
vals["code"].append(product.default_code)
vals["designation"].append(product.name)
# TODO mettre une colonne qté par entrepot (x colonnes)
vals["qté"].append(round(prd_q["quantity"]))
for i in range(0, len(warehouse_quantities), 2):
warehouse_id = warehouse_quantities[i]
quantity = warehouse_quantities[i + 1]
warehouse_id = self.env["stock.warehouse"].browse(warehouse_id)
vals[f"qté_{warehouse_id.name}"].append(round(quantity))
if len(warehouse_quantities) / 2 < len(self.valued_warehouse_ids):
warehouse_without_qty = self.valued_warehouse_ids.filtered(
lambda r: r.id
not in [
warehouse_quantities[i]
for i in range(0, len(warehouse_quantities), 2)
]
)
for warehouse in warehouse_without_qty:
vals[f"qté_{warehouse.name}"].append(0)

# TODO quand la valeur est < cost_vs_purchase_threshold % de ce seuil
# mettre une colonne 'check' à la valeur 1
vals["valeur"].append(
Expand All @@ -99,15 +135,9 @@ def _get_stock_valuation_another(self):
product.standard_price,
prices[product] and prices[product].price or 0 * coef / 100,
)
* prd_q["quantity"]
* product["quantity"]
)
)
# TODO mettre l'url en first column
vals["lien"].append(
f"{base_url}/web#id={prd_q['product_id'][0]}&cids={self.id}&action="
f"{self.env.ref('product.product_normal_action_sell').id}&model="
"product.product&view_type=form"
)
df = pl.from_dict(vals)
mfile = io.BytesIO()
df.write_excel(workbook=mfile)
Expand Down
7 changes: 7 additions & 0 deletions account_stock_situation/models/stock_quant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class StockQuant(models.Model):
_inherit = "stock.quant"

warehouse_id = fields.Many2one(store=True, index=True)
7 changes: 4 additions & 3 deletions account_stock_situation/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down

0 comments on commit b979984

Please sign in to comment.