Skip to content

Commit

Permalink
[UPD] change following code review
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudelva committed Aug 9, 2024
1 parent b979984 commit 8210887
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 49 deletions.
1 change: 1 addition & 0 deletions account_stock_situation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Contributors

* Akretion
* David BEAL <david.beal@akretion.com>
* Mathieu DELVA <mathieu.delva@akretion.com>

Maintainers
~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion account_stock_situation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import company
from . import config_settings
from . import stock_quant
63 changes: 23 additions & 40 deletions account_stock_situation/models/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ResCompany(models.Model):

def _set_account_stock_valuation(self, company_string_id):
self = self.env.ref(company_string_id)
value, attach = self._get_stock_valuation_another()
value, attach = self._get_stock_valuation()
for mfield in (
"account_stock_id",
"account_purchase_stock_id",
Expand Down Expand Up @@ -65,42 +65,34 @@ def _set_account_stock_valuation(self, company_string_id):
)
attach.res_id = move.id

def _get_stock_valuation_another(self):
def _get_stock_valuation(self):
self.ensure_one()
coef = self.cost_vs_purchase_threshold
base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url")
if tools.config.get("running_env") == "dev":
base_url = "http://anothercorp.localhost/"
location_ids = [x.lot_stock_id.id for x in self.valued_warehouse_ids]
# TODO conserver un group par emplacement : donc autant de colonnes
# de nombres de produits que d'entrepots dans l'excel
product_qties = self.env["stock.quant"].read_group(

stock_quant_ids = self.env["stock.quant"].search(
[("location_id", "child_of", location_ids)],
["product_id", "warehouse_id", "quantity"],
["product_id", "warehouse_id"],
lazy=False,
)

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
}
products = self.env["product.product"].browse(stock_quant_ids.product_id.ids)
vals = defaultdict(list)

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"],
for stock_quant in stock_quant_ids:
if stock_quant.product_id.id not in product_dict:
product_dict[stock_quant.product_id.id] = [
stock_quant.warehouse_id,
stock_quant.quantity,
]
else:
product_dict[product["product_id"][0]] += [
product["warehouse_id"][0],
product["quantity"],
]
if stock_quant.warehouse_id in product_dict[stock_quant.product_id.id]:
product_dict[stock_quant.product_id.id][1] += stock_quant.quantity
else:
product_dict[stock_quant.product_id.id] += [
stock_quant.warehouse_id,
stock_quant.quantity,
]

for product_id, warehouse_quantities in product_dict.items():
product = products.filtered(lambda s: s.id == product_id)
Expand All @@ -111,33 +103,24 @@ def _get_stock_valuation_another(self):
)
vals["code"].append(product.default_code)
vals["designation"].append(product.name)

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))
vals[f"qty_{warehouse_id.code}"].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]
warehouse_quantities[i].id
for i in range(0, len(warehouse_quantities), 2)
]
)
for warehouse in warehouse_without_qty:
vals[f"qté_{warehouse.name}"].append(0)
vals[f"qty_{warehouse.code}"].append(0)

vals["value"].append(round(product.standard_price))

# TODO quand la valeur est < cost_vs_purchase_threshold % de ce seuil
# mettre une colonne 'check' à la valeur 1
vals["valeur"].append(
round(
max(
product.standard_price,
prices[product] and prices[product].price or 0 * coef / 100,
)
* product["quantity"]
)
)
df = pl.from_dict(vals)
mfile = io.BytesIO()
df.write_excel(workbook=mfile)
Expand Down
7 changes: 0 additions & 7 deletions account_stock_situation/models/stock_quant.py

This file was deleted.

1 change: 1 addition & 0 deletions account_stock_situation/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* Akretion
* David BEAL <david.beal@akretion.com>
* Mathieu DELVA <mathieu.delva@akretion.com>
1 change: 1 addition & 0 deletions account_stock_situation/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<dt>Akretion</dt>
<dd><ul class="first last">
<li>David BEAL &lt;<a class="reference external" href="mailto:david.beal&#64;akretion.com">david.beal&#64;akretion.com</a>&gt;</li>
<li>Mathieu DELVA &lt;<a class="reference external" href="mailto:mathieu.delva&#64;akretion.com">mathieu.delva&#64;akretion.com</a>&gt;</li>
</ul>
</dd>
</dl>
Expand Down
2 changes: 1 addition & 1 deletion account_stock_situation/views/action.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<odoo noupdate="1">

<record id="stock_account_valuation_main_company" model="ir.cron">
<field name="name">Stock Valorisation</field>
<field name="name">Stock Situation</field>
<field name="model_id" ref="base.model_res_company" />
<field name="state">code</field>
<field
Expand Down

0 comments on commit 8210887

Please sign in to comment.