[FIX] account: invoice analysis product quantity
This rev. is related to 6641c61ce6
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
This commit is contained in:
parent
b36908b6f8
commit
c331e963cd
|
@ -132,15 +132,7 @@ class account_invoice_report(osv.osv):
|
|||
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,
|
||||
|
@ -160,11 +152,11 @@ class account_invoice_report(osv.osv):
|
|||
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,
|
||||
|
@ -196,17 +188,17 @@ class account_invoice_report(osv.osv):
|
|||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue