Skip to content

Commit

Permalink
[FIX] stock_average_daily_sale: Don't rely on tuples as id
Browse files Browse the repository at this point in the history
As for x reason, some products appear more than one time in the report,
id generated by the concatenation of product_id and warehouse_id is
irrelevant (as duplicate values possible). Use row_number() instead
  • Loading branch information
rousseldenis committed Oct 11, 2023
1 parent a1dcdd6 commit 90c0aff
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions stock_average_daily_sale/models/stock_average_daily_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ def _create_materialized_view(self):
averages AS(
SELECT
concat(warehouse_id, product_id)::integer as id,
row_number() over (order by product_id) as id,
concat(warehouse_id, product_id)::integer as window_id,
product_id,
warehouse_id,
(avg(product_uom_qty) FILTER
Expand Down Expand Up @@ -295,7 +296,7 @@ def _create_materialized_view(self):
(cfg.number_days_qty_in_stock * average_qty_by_sale)
) as recommended_qty
FROM averages t
JOIN daily_standard_deviation ds on ds.id= t.id
JOIN daily_standard_deviation ds on ds.id= t.window_id
JOIN stock_average_daily_sale_config cfg on cfg.id = t.config_id
JOIN stock_qty sqty on sqty.pp_id = t.product_id AND t.warehouse_id = sqty.warehouse_id
JOIN product_product pp on pp.id = t.product_id
Expand Down

0 comments on commit 90c0aff

Please sign in to comment.