Skip to content

Commit 8210887

Browse files
committed
[UPD] change following code review
1 parent b979984 commit 8210887

File tree

7 files changed

+27
-49
lines changed

7 files changed

+27
-49
lines changed

account_stock_situation/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Contributors
5757

5858
* Akretion
5959
* David BEAL <david.beal@akretion.com>
60+
* Mathieu DELVA <mathieu.delva@akretion.com>
6061

6162
Maintainers
6263
~~~~~~~~~~~
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
from . import company
22
from . import config_settings
3-
from . import stock_quant

account_stock_situation/models/company.py

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ResCompany(models.Model):
2222

2323
def _set_account_stock_valuation(self, company_string_id):
2424
self = self.env.ref(company_string_id)
25-
value, attach = self._get_stock_valuation_another()
25+
value, attach = self._get_stock_valuation()
2626
for mfield in (
2727
"account_stock_id",
2828
"account_purchase_stock_id",
@@ -65,42 +65,34 @@ def _set_account_stock_valuation(self, company_string_id):
6565
)
6666
attach.res_id = move.id
6767

68-
def _get_stock_valuation_another(self):
68+
def _get_stock_valuation(self):
6969
self.ensure_one()
70-
coef = self.cost_vs_purchase_threshold
7170
base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url")
7271
if tools.config.get("running_env") == "dev":
7372
base_url = "http://anothercorp.localhost/"
7473
location_ids = [x.lot_stock_id.id for x in self.valued_warehouse_ids]
75-
# TODO conserver un group par emplacement : donc autant de colonnes
76-
# de nombres de produits que d'entrepots dans l'excel
77-
product_qties = self.env["stock.quant"].read_group(
74+
75+
stock_quant_ids = self.env["stock.quant"].search(
7876
[("location_id", "child_of", location_ids)],
79-
["product_id", "warehouse_id", "quantity"],
80-
["product_id", "warehouse_id"],
81-
lazy=False,
8277
)
83-
84-
product_ids = list({x["product_id"][0] for x in product_qties})
85-
86-
products = self.env["product.product"].browse(product_ids)
87-
prices = {
88-
x: x.variant_seller_ids and x.variant_seller_ids[0] or 0 for x in products
89-
}
78+
products = self.env["product.product"].browse(stock_quant_ids.product_id.ids)
9079
vals = defaultdict(list)
9180

9281
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"],
82+
for stock_quant in stock_quant_ids:
83+
if stock_quant.product_id.id not in product_dict:
84+
product_dict[stock_quant.product_id.id] = [
85+
stock_quant.warehouse_id,
86+
stock_quant.quantity,
9887
]
9988
else:
100-
product_dict[product["product_id"][0]] += [
101-
product["warehouse_id"][0],
102-
product["quantity"],
103-
]
89+
if stock_quant.warehouse_id in product_dict[stock_quant.product_id.id]:
90+
product_dict[stock_quant.product_id.id][1] += stock_quant.quantity
91+
else:
92+
product_dict[stock_quant.product_id.id] += [
93+
stock_quant.warehouse_id,
94+
stock_quant.quantity,
95+
]
10496

10597
for product_id, warehouse_quantities in product_dict.items():
10698
product = products.filtered(lambda s: s.id == product_id)
@@ -111,33 +103,24 @@ def _get_stock_valuation_another(self):
111103
)
112104
vals["code"].append(product.default_code)
113105
vals["designation"].append(product.name)
106+
114107
for i in range(0, len(warehouse_quantities), 2):
115108
warehouse_id = warehouse_quantities[i]
116109
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))
110+
vals[f"qty_{warehouse_id.code}"].append(round(quantity))
119111
if len(warehouse_quantities) / 2 < len(self.valued_warehouse_ids):
120112
warehouse_without_qty = self.valued_warehouse_ids.filtered(
121113
lambda r: r.id
122114
not in [
123-
warehouse_quantities[i]
115+
warehouse_quantities[i].id
124116
for i in range(0, len(warehouse_quantities), 2)
125117
]
126118
)
127119
for warehouse in warehouse_without_qty:
128-
vals[f"qté_{warehouse.name}"].append(0)
120+
vals[f"qty_{warehouse.code}"].append(0)
121+
122+
vals["value"].append(round(product.standard_price))
129123

130-
# TODO quand la valeur est < cost_vs_purchase_threshold % de ce seuil
131-
# mettre une colonne 'check' à la valeur 1
132-
vals["valeur"].append(
133-
round(
134-
max(
135-
product.standard_price,
136-
prices[product] and prices[product].price or 0 * coef / 100,
137-
)
138-
* product["quantity"]
139-
)
140-
)
141124
df = pl.from_dict(vals)
142125
mfile = io.BytesIO()
143126
df.write_excel(workbook=mfile)

account_stock_situation/models/stock_quant.py

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
* Akretion
22
* David BEAL <david.beal@akretion.com>
3+
* Mathieu DELVA <mathieu.delva@akretion.com>

account_stock_situation/static/description/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
411411
<dt>Akretion</dt>
412412
<dd><ul class="first last">
413413
<li>David BEAL &lt;<a class="reference external" href="mailto:david.beal&#64;akretion.com">david.beal&#64;akretion.com</a>&gt;</li>
414+
<li>Mathieu DELVA &lt;<a class="reference external" href="mailto:mathieu.delva&#64;akretion.com">mathieu.delva&#64;akretion.com</a>&gt;</li>
414415
</ul>
415416
</dd>
416417
</dl>

account_stock_situation/views/action.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<odoo noupdate="1">
33

44
<record id="stock_account_valuation_main_company" model="ir.cron">
5-
<field name="name">Stock Valorisation</field>
5+
<field name="name">Stock Situation</field>
66
<field name="model_id" ref="base.model_res_company" />
77
<field name="state">code</field>
88
<field

0 commit comments

Comments
 (0)