Skip to content

Commit

Permalink
[FIX] account: invoice analysis product quantity
Browse files Browse the repository at this point in the history
This rev. is related to 6641c61

During the above revision, a new jointure has been added
with product_uom, on product template uom_id
The join link was wrong, it was:
 - LEFT JOIN product_uom u2 ON u.id = pt.uom_id
and it must be:
 - LEFT JOIN product_uom u2 ON u2.id = pt.uom_id

 as the alias 'u' is the previous jointure, not this new one.

Besides, the uom_name is now the name
of the product uom of this second jointure
As the uom is now the product default uom
instead of the category reference uom

The groupby clause has been adapted, as the selection was slightly altered
Besides, grouping by u.uom_type, u.category_id was pointless
  • Loading branch information
beledouxdenis committed Feb 4, 2015
1 parent b36908b commit c331e96
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions addons/account/report/account_invoice_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,7 @@ def _sub_select(self):
SELECT min(ail.id) AS id,
ai.date_invoice AS date,
ail.product_id, ai.partner_id, ai.payment_term, ai.period_id,
CASE
WHEN u.uom_type::text <> 'reference'::text
THEN ( SELECT product_uom.name
FROM product_uom
WHERE product_uom.uom_type::text = 'reference'::text
AND product_uom.active
AND product_uom.category_id = u.category_id LIMIT 1)
ELSE u.name
END AS uom_name,
u2.name AS uom_name,
ai.currency_id, ai.journal_id, ai.fiscal_position, ai.user_id, ai.company_id,
count(ail.*) AS nbr,
ai.type, ai.state, pt.categ_id, ai.date_due, ai.account_id, ail.account_id AS account_line_id,
Expand All @@ -160,11 +152,11 @@ def _sub_select(self):
THEN SUM(- ail.price_subtotal)
ELSE SUM(ail.price_subtotal)
END / CASE
WHEN SUM(ail.quantity / u.factor) <> 0::numeric
WHEN SUM(ail.quantity / u.factor * u2.factor) <> 0::numeric
THEN CASE
WHEN ai.type::text = ANY (ARRAY['out_refund'::character varying::text, 'in_invoice'::character varying::text])
THEN SUM((- ail.quantity) / u.factor)
ELSE SUM(ail.quantity / u.factor)
THEN SUM((- ail.quantity) / u.factor * u2.factor)
ELSE SUM(ail.quantity / u.factor * u2.factor)
END
ELSE 1::numeric
END AS price_average,
Expand Down Expand Up @@ -196,17 +188,17 @@ def _from(self):
LEFT JOIN product_product pr ON pr.id = ail.product_id
left JOIN product_template pt ON pt.id = pr.product_tmpl_id
LEFT JOIN product_uom u ON u.id = ail.uos_id
LEFT JOIN product_uom u2 ON u.id = pt.uom_id
LEFT JOIN product_uom u2 ON u2.id = pt.uom_id
"""
return from_str

def _group_by(self):
group_by_str = """
GROUP BY ail.product_id, ai.date_invoice, ai.id,
ai.partner_id, ai.payment_term, ai.period_id, u.name, ai.currency_id, ai.journal_id,
ai.partner_id, ai.payment_term, ai.period_id, u2.name, u2.id, ai.currency_id, ai.journal_id,
ai.fiscal_position, ai.user_id, ai.company_id, ai.type, ai.state, pt.categ_id,
ai.date_due, ai.account_id, ail.account_id, ai.partner_bank_id, ai.residual,
ai.amount_total, u.uom_type, u.category_id, ai.commercial_partner_id, partner.country_id
ai.amount_total, ai.commercial_partner_id, partner.country_id
"""
return group_by_str

Expand Down

0 comments on commit c331e96

Please sign in to comment.