[IMP]:sale,purchase:imroved SQL reports

bzr revid: apa@tinyerp.com-20100709100541-6mt5i6uc47zafp0j
This commit is contained in:
apa-tiny 2010-07-09 15:35:41 +05:30
parent ae59b69c36
commit 10d6fc19cc
4 changed files with 45 additions and 26 deletions

View File

@ -54,8 +54,8 @@ class purchase_report(osv.osv):
'validator' : fields.many2one('res.users', 'Validated By', readonly=True),
'company_id':fields.many2one('res.company', 'Company', readonly=True),
'user_id':fields.many2one('res.users', 'Responsible', readonly=True),
'delay':fields.float('Days to Validate', digits=(16,2), readonly=True, group_operator="avg"),
'delay_pass':fields.float('Days to Deliver', digits=(16,2), readonly=True, group_operator="avg"),
'delay':fields.float('Days to Validate', digits=(16,2), readonly=True),
'delay_pass':fields.float('Days to Deliver', digits=(16,2), readonly=True),
'quantity': fields.float('# of Products', readonly=True),
'price_total': fields.float('Total Price', readonly=True),
'price_average': fields.float('Average Price', readonly=True, group_operator="avg"),

View File

@ -39,8 +39,8 @@
<field name="price_total" sum="Total Price"/>
<field name="price_standard" sum="Products Value"/>
<field name="negociation" widget="progressbar"/>
<field name="delay" avg="Days to Validate"/>
<field name="delay_pass" avg="Days to Deliver"/>
<field name="delay" sum="Days to Validate"/>
<field name="delay_pass" sum="Days to Deliver"/>
</tree>
</field>
</record>
@ -146,6 +146,7 @@
<field name="res_model">purchase.report</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="view_id" ref="view_purchase_order_tree"></field>
<field name="context">{'search_default_month':1,'search_default_group_partner_id':1,'search_default_group_product_id': 1, 'search_default_orders': 1, 'group_by_no_leaf':1,'group_by':[]}</field>
</record>

View File

@ -74,7 +74,7 @@ class sale_report(osv.osv):
tools.drop_view_if_exists(cr, 'sale_report')
cr.execute("""
create or replace view sale_report as (
select el.*,
select el.*,
-- (select count(1) from sale_order_line where order_id = s.id) as nbr,
(select 1) as nbr,
s.date_order as date,
@ -86,28 +86,46 @@ class sale_report(osv.osv):
s.user_id as user_id,
s.shop_id as shop_id,
s.company_id as company_id,
extract(epoch from (s.date_confirm-s.create_date))/(24*60*60)::decimal(16,2) as delay,
extract(epoch from avg(date_trunc('day',s.date_confirm)-date_trunc('day',s.create_date)))/(24*60*60)::decimal(16,2) as delay,
s.state,
s.shipped,
s.shipped::integer as shipped_qty_1,
s.pricelist_id as pricelist_id,
s.project_id as analytic_account_id
from
sale_order s,
(
select l.id as id,
l.product_id as product_id,
u.name as uom_name,
sum(l.product_uom_qty * u.factor) as product_uom_qty,
sum(l.product_uom_qty*l.price_unit) as price_total,
(sum(l.product_uom_qty*l.price_unit)/sum(l.product_uom_qty * u.factor)*count(l.product_id))::decimal(16,2) as price_average,
pt.categ_id, l.order_id
from
sale_order_line l
left join product_uom u on (u.id=l.product_uom)
left join product_template pt on (pt.id=l.product_id)
group by l.id, l.order_id, l.product_id, u.name, pt.categ_id) el
where s.id = el.order_id
from
sale_order s,
(
select l.id as id,
l.product_id as product_id,
u.name as uom_name,
sum(l.product_uom_qty * u.factor) as product_uom_qty,
sum(l.product_uom_qty*l.price_unit) as price_total,
(sum(l.product_uom_qty*l.price_unit)/sum(l.product_uom_qty * u.factor)*count(l.product_id))::decimal(16,2) as price_average,
pt.categ_id, l.order_id
from
sale_order_line l
left join product_uom u on (u.id=l.product_uom)
left join product_template pt on (pt.id=l.product_id)
group by l.id, l.order_id, l.product_id, u.name, pt.categ_id) el
where s.id = el.order_id
group by el.id,
el.product_id,
el.uom_name,
el.product_uom_qty,
el.price_total,
el.price_average,
el.categ_id,
el.order_id,
s.date_order,
s.date_confirm,
s.partner_id,
s.user_id,
s.shop_id,
s.company_id,
s.state,
s.shipped,
s.pricelist_id,
s.project_id
)
""")
sale_report()

View File

@ -20,11 +20,11 @@
<field name="categ_id" invisible="1"/>
<field name="nbr" sum="# of Lines"/>
<field name="product_uom_qty" sum="# of Qty"/>
<field name="shipped_qty_1"/>
<field name="uom_name" invisible="context.get('set_visible',False)"/>
<field name="price_average" avg="Average Price"/>
<field name="shipped_qty_1" sum="Shipped Qty"/>
<field name="uom_name" invisible="not context.get('set_visible',False)"/>
<field name="price_average" sum="Average Price"/>
<field name="price_total" sum="Total Price"/>
<field name="delay" avg="Commitment Delay"/>
<field name="delay" sum="Commitment Delay"/>
<field name="state" invisible="1"/>
<field name="analytic_account_id" invisible="1"/>
</tree>