[IMP] sale: include empty orders in sales report
- Purpose is to include orders that have no lines in the sales report for consistency - In report, 'Quotation' filter shows quotation which is in 'draft' or 'sent' stage. task-2122948 Closes- #42662 Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
This commit is contained in:
@@ -62,17 +62,17 @@ class SaleReport(models.Model):
|
|||||||
with_ = ("WITH %s" % with_clause) if with_clause else ""
|
with_ = ("WITH %s" % with_clause) if with_clause else ""
|
||||||
|
|
||||||
select_ = """
|
select_ = """
|
||||||
min(l.id) as id,
|
row_number() over (ORDER BY s.id) as id,
|
||||||
l.product_id as product_id,
|
l.product_id as product_id,
|
||||||
t.uom_id as product_uom,
|
t.uom_id as product_uom,
|
||||||
sum(l.product_uom_qty / u.factor * u2.factor) as product_uom_qty,
|
CASE WHEN l.product_id IS NOT NULL THEN sum(l.product_uom_qty / u.factor * u2.factor) ELSE 0 END as product_uom_qty,
|
||||||
sum(l.qty_delivered / u.factor * u2.factor) as qty_delivered,
|
CASE WHEN l.product_id IS NOT NULL THEN sum(l.qty_delivered / u.factor * u2.factor) ELSE 0 END as qty_delivered,
|
||||||
sum(l.qty_invoiced / u.factor * u2.factor) as qty_invoiced,
|
CASE WHEN l.product_id IS NOT NULL THEN sum(l.qty_invoiced / u.factor * u2.factor) ELSE 0 END as qty_invoiced,
|
||||||
sum(l.qty_to_invoice / u.factor * u2.factor) as qty_to_invoice,
|
CASE WHEN l.product_id IS NOT NULL THEN sum(l.qty_to_invoice / u.factor * u2.factor) ELSE 0 END as qty_to_invoice,
|
||||||
sum(l.price_total / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) as price_total,
|
CASE WHEN l.product_id IS NOT NULL THEN sum(l.price_total / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) ELSE 0 END as price_total,
|
||||||
sum(l.price_subtotal / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) as price_subtotal,
|
CASE WHEN l.product_id IS NOT NULL THEN sum(l.price_subtotal / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) ELSE 0 END as price_subtotal,
|
||||||
sum(l.untaxed_amount_to_invoice / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) as untaxed_amount_to_invoice,
|
CASE WHEN l.product_id IS NOT NULL THEN sum(l.untaxed_amount_to_invoice / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) ELSE 0 END as untaxed_amount_to_invoice,
|
||||||
sum(l.untaxed_amount_invoiced / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) as untaxed_amount_invoiced,
|
CASE WHEN l.product_id IS NOT NULL THEN sum(l.untaxed_amount_invoiced / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) ELSE 0 END as untaxed_amount_invoiced,
|
||||||
count(*) as nbr,
|
count(*) as nbr,
|
||||||
s.name as name,
|
s.name as name,
|
||||||
s.date_order as date,
|
s.date_order as date,
|
||||||
@@ -92,10 +92,10 @@ class SaleReport(models.Model):
|
|||||||
partner.country_id as country_id,
|
partner.country_id as country_id,
|
||||||
partner.industry_id as industry_id,
|
partner.industry_id as industry_id,
|
||||||
partner.commercial_partner_id as commercial_partner_id,
|
partner.commercial_partner_id as commercial_partner_id,
|
||||||
sum(p.weight * l.product_uom_qty / u.factor * u2.factor) as weight,
|
CASE WHEN l.product_id IS NOT NULL THEN sum(p.weight * l.product_uom_qty / u.factor * u2.factor) ELSE 0 END as weight,
|
||||||
sum(p.volume * l.product_uom_qty / u.factor * u2.factor) as volume,
|
CASE WHEN l.product_id IS NOT NULL THEN sum(p.volume * l.product_uom_qty / u.factor * u2.factor) ELSE 0 END as volume,
|
||||||
l.discount as discount,
|
l.discount as discount,
|
||||||
sum((l.price_unit * l.product_uom_qty * l.discount / 100.0 / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END)) as discount_amount,
|
CASE WHEN l.product_id IS NOT NULL THEN sum((l.price_unit * l.product_uom_qty * l.discount / 100.0 / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END))ELSE 0 END as discount_amount,
|
||||||
s.id as order_id
|
s.id as order_id
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ class SaleReport(models.Model):
|
|||||||
|
|
||||||
from_ = """
|
from_ = """
|
||||||
sale_order_line l
|
sale_order_line l
|
||||||
join sale_order s on (l.order_id=s.id)
|
right outer join sale_order s on (s.id=l.order_id)
|
||||||
join res_partner partner on s.partner_id = partner.id
|
join res_partner partner on s.partner_id = partner.id
|
||||||
left join product_product p on (l.product_id=p.id)
|
left join product_product p on (l.product_id=p.id)
|
||||||
left join product_template t on (p.product_tmpl_id=t.id)
|
left join product_template t on (p.product_tmpl_id=t.id)
|
||||||
@@ -139,7 +139,7 @@ class SaleReport(models.Model):
|
|||||||
s.id %s
|
s.id %s
|
||||||
""" % (groupby)
|
""" % (groupby)
|
||||||
|
|
||||||
return '%s (SELECT %s FROM %s WHERE l.product_id IS NOT NULL GROUP BY %s)' % (with_, select_, from_, groupby_)
|
return '%s (SELECT %s FROM %s GROUP BY %s)' % (with_, select_, from_, groupby_)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
# self._table = sale_report
|
# self._table = sale_report
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
<search string="Sales Analysis">
|
<search string="Sales Analysis">
|
||||||
<field name="date"/>
|
<field name="date"/>
|
||||||
<filter string="Date" name="year" invisible="1" date="date" default_period="this_year"/>
|
<filter string="Date" name="year" invisible="1" date="date" default_period="this_year"/>
|
||||||
<filter name="Quotations" string="Quotations" domain="[('state','=', 'draft')]"/>
|
<filter name="Quotations" string="Quotations" domain="[('state','in', ('draft', 'sent'))]"/>
|
||||||
<filter name="Sales" string="Sales Orders" domain="[('state','not in',('draft', 'cancel', 'sent'))]"/>
|
<filter name="Sales" string="Sales Orders" domain="[('state','not in',('draft', 'cancel', 'sent'))]"/>
|
||||||
<separator/>
|
<separator/>
|
||||||
<field name="user_id"/>
|
<field name="user_id"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user