Skip to content

Commit

Permalink
[FIX] sale_report_delivered: Decide when SUM valuation layers or sub …
Browse files Browse the repository at this point in the history
…lines

When the valuation layers were being grouped, the COALESCE function was acting on each one separately. Now, they are all processed at once.
  • Loading branch information
Shide committed Nov 5, 2024
1 parent c8e3a02 commit cc9d922
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions sale_report_delivered/reports/sale_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,32 @@ def _select(self):
sub.picking_id,
sum(signed_qty * unsigned_product_uom_qty) AS product_uom_qty,
sum(signed_qty * unsigned_price_subtotal) AS price_subtotal,
sum(COALESCE(-sub.amount_cost, signed_qty *
ROUND(sub.unsigned_purchase_price * unsigned_product_uom_qty,
sub.decimal_places))) AS amount_cost,
sum(signed_qty * unsigned_price_subtotal - COALESCE(-sub.amount_cost, signed_qty *
ROUND(sub.unsigned_purchase_price * unsigned_product_uom_qty,
sub.decimal_places))) AS margin,
CASE
WHEN BOOL_OR(sub.amount_cost is not NULL)
THEN sum(-sub.amount_cost)
ELSE sum(
signed_qty * ROUND(
sub.unsigned_purchase_price * unsigned_product_uom_qty,
sub.decimal_places
)
)
END AS amount_cost,
CASE
WHEN BOOL_OR(sub.amount_cost is not NULL)
THEN sum(
signed_qty * unsigned_price_subtotal + COALESCE(
sub.amount_cost, 0.0
)
)
ELSE sum(
signed_qty * unsigned_price_subtotal - (
signed_qty * ROUND(
sub.unsigned_purchase_price * unsigned_product_uom_qty,
sub.decimal_places
)
)
)
END AS margin,
0 AS margin_percent
"""
return select_str
Expand Down

0 comments on commit cc9d922

Please sign in to comment.