[IMP]:stock:Improved SQL view report.(Picking)

bzr revid: apa@tinyerp.com-20100422125153-qtnyphc0i6ea2o2x
This commit is contained in:
aag(OpenERP),apa(OpenERP)
2010-04-22 18:21:53 +05:30
committed by apa-tiny
parent 87a4b80114
commit 17342f5d3b
2 changed files with 68 additions and 69 deletions
+33 -20
View File
@@ -26,38 +26,51 @@ class report_stock_picking(osv.osv):
_description = "Stock Picking Report"
_auto = False
_columns = {
'name': fields.char('Year',size=64,required=False, readonly=True),
'year': fields.char('Year',size=64,required=False, readonly=True),
'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
'day': fields.char('Day', size=128, readonly=True),
'reference': fields.char('Reference', size=64, select=True),
'nbr': fields.integer('# of Orders', readonly=True),
'nbr': fields.integer('# of Lines', readonly=True),
'partner_id':fields.many2one('res.partner', 'Partner', readonly=True),
'product_id': fields.many2one('product.product', 'Product', readonly=True),
'product_qty': fields.float('# of Products', readonly=True),
'date': fields.date('Date', readonly=True),
'avg_days_to_deliver': fields.float('Avg Days to Deliver', digits=(16,2), readonly=True, group_operator="avg",
help="Number of Avg Days to deliver"),
'origin': fields.char('Origin', size=64),
'order_date':fields.date('Order Date'),
'state': fields.selection([('draft', 'Draft'),('auto', 'Waiting'),('confirmed', 'Confirmed'),('assigned', 'Available'),('done', 'Done'),('cancel', 'Cancelled')], 'State'),
'type': fields.selection([('out', 'Sending Goods'), ('in', 'Getting Goods'), ('internal', 'Internal'), ('delivery', 'Delivery')], 'Shipping Type', required=True),
'address_id': fields.many2one('res.partner.address', 'Partner'),
'expected_date': fields.date('Expected Date'),
}
def init(self, cr):
tools.drop_view_if_exists(cr, 'report_stock_picking')
cr.execute("""
create or replace view report_stock_picking as (
select
min(c.id) as id,
to_char(c.create_date, 'YYYY') as name,
to_char(c.create_date, 'MM') as month,
c.name as reference,
c.origin,
c.state,
c.type,
c.address_id,
to_date(to_char(c.date, 'MM-dd-YYYY'),'MM-dd-YYYY') as order_date,
to_date(to_char(c.min_date, 'MM-dd-YYYY'),'MM-dd-YYYY') as expected_date,
count(*) as nbr
from
stock_picking c
group by to_char(c.create_date, 'YYYY'), to_char(c.create_date, 'MM'),c.name,c.origin,c.date,c.state,c.type,c.address_id,c.min_date
min(sm.id) as id,
to_char(sp.create_date, 'YYYY') as year,
to_char(sp.create_date, 'MM') as month,
to_char(sp.create_date, 'YYYY-MM-DD') as day,
sp.address_id as partner_id,
to_date(to_char(sp.create_date, 'MM-dd-YYYY'),'MM-dd-YYYY') as date,
count(sm.id) as nbr,
sm.product_id,
sum(sm.product_qty) as product_qty,
sp.type,
sp.name as reference,
sp.origin,
avg(extract('epoch' from (sp.date_done-sp.create_date)))/(3600*24) as avg_days_to_deliver,
sp.state
from stock_move as sm
left join stock_picking as sp ON (sm.picking_id=sp.id)
group by sp.type,
sp.create_date,
sm.product_id,
sp.address_id,
sp.name,
sp.origin,
sp.state
)""")
report_stock_picking()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -11,32 +11,22 @@
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Picking">
<field name="reference" />
<field name="address_id" />
<field name="origin" />
<field name="order_date" />
<field name="type" />
<field name="nbr" string="#Picking" />
<field name="year" invisible="1"/>
<field name="month" invisible="1"/>
<field name="day" invisible="1"/>
<field name="date" invisible="1"/>
<field name="reference" invisible="1"/>
<field name="partner_id" invisible="1"/>
<field name="product_id" invisible="1"/>
<field name="origin" invisible="1"/>
<field name="type" invisible="1"/>
<field name="state" invisible="1"/>
<field name="order_date" invisible="1"/>
<field name="expected_date" invisible="1"/>
<field name="name" invisible="1"/>
<field name="month" invisible="1"/>
<field name="product_qty" sum="# of Products" />
<field name="nbr" sum="# of Lines" />
<field name="avg_days_to_deliver" sum='Avg Days to Deliver'/>
</tree>
</field>
</record>
<record id="view_report_report_stock_picking_form" model="ir.ui.view">
<field name="name">report.stock.picking.form</field>
<field name="model">report.stock.picking</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Picking">
<field name="name" />
<field name="month"/>
<field name="reference" />
</form>
</field>
</record>
<record id="view_report_report_stock_picking_graph" model="ir.ui.view">
<field name="name">report.stock.picking.graph</field>
@@ -44,8 +34,9 @@
<field name="type">graph</field>
<field name="arch" type="xml">
<graph orientation="horizontal" string="Picking" type="bar">
<field name="state"/>
<field name="product_id"/>
<field name="nbr" operator="+"/>
<field name="state" group="True"/>
</graph>
</field>
</record>
@@ -57,38 +48,33 @@
<field name="arch" type="xml">
<search string="Search">
<group col="16" colspan="6">
<filter string="This Year" icon="terp-hr" domain="[('name','=',time.localtime()[0])]" default="1" />
<filter string="This Month" icon="terp-hr" domain="[('month','=',time.strftime('%%m'))]" default="1"/>
<filter icon="terp-stock" string="This Year"
domain="[('date','&lt;=', time.strftime('%%Y-%%m-%%d')),('date','&gt;',(datetime.date.today()-datetime.timedelta(days=365)).strftime('%%Y-%%m-%%d'))]"
help="Picking in this year"/>
<filter icon="terp-stock" string="This Month"
name="month"
domain="[('date','&lt;=', time.strftime('%%Y-%%m-%%d')), ('date','&gt;',(datetime.date.today()-datetime.timedelta(days=30)).strftime('%%Y-%%m-%%d'))]"
help="Picking in this month"/>
<separator orientation="vertical"/>
<filter string="Current" icon="terp-hr" domain="[('state','in',('open','draft'))]"/>
<filter string="Order Date" icon="terp-stock" domain="[('order_date',=,time.strftime('%%Y-%%m-%%d'))]" />
<filter string="Expected Date" icon="terp-hr" domain="[('expected_date',=,time.strftime('%%Y-%%m-%%d'))]"/>
<filter string="Todo" icon="terp-stock" domain="[('state','in',('draft','auto','confirmed','assigned'))]"/>
<filter string="Done" icon="terp-stock" domain="[('state','=','done')]"/>
<separator orientation="vertical"/>
<field name="partner_id"/>
<field name="reference" />
<field name="origin" />
<field name="type" />
</group>
<newline/>
<group expand="1" string="Extended options..." colspan="4" col="5">
<filter icon="terp-sale"
string="Sending Goods"
domain="[('type','=','out')]"/>
<filter icon="terp-sale"
string="Getting Goods"
domain="[('type','=','in')]"/>
<filter icon="terp-sale"
string="Internal"
domain="[('type','=','internal')]"/>
<filter icon="terp-sale"
string="Delivery"
domain="[('type','=','delivery')]"/>
</group>
<newline/>
<group expand="1" string="Group By..." colspan="4" col="5">
<filter string="Partner" icon="terp-stock" domain="[]" context="{'group_by':'address_id'}"/>
<filter string="State" name="State" icon="terp-stock" domain="[]" context="{'group_by':'state'}"/>
<separator orientation="vertical"/>
<filter string="Month" icon="terp-sale" domain="[]" context="{'group_by':'month'}"/>
<filter string="Year" icon="terp-sale" domain="[]" context="{'group_by':'name'}"/>
<filter string="Partner" name="Partner" icon="terp-stock" domain="[]" context="{'group_by':'partner_id'}"/>
<filter string="State" icon="terp-stock" domain="[]" context="{'group_by':'state'}"/>
<separator orientation="vertical"/>
<filter string="Shipping Type" icon="terp-stock" domain="[]" context="{'group_by':'type'}"/>
<filter string="Origin" icon="terp-stock" domain="[]" context="{'group_by':'origin'}"/>
<separator orientation="vertical"/>
<filter string="Day" icon="terp-stock" domain="[]" context="{'group_by':'day'}"/>
<filter string="Month" icon="terp-stock" domain="[]" context="{'group_by':'month'}"/>
<filter string="Year" icon="terp-stock" domain="[]" context="{'group_by':'year'}"/>
</group>
</search>
</field>
@@ -100,7 +86,7 @@
<field name="view_mode">tree,graph</field>
<field name="view_id" ref="view_report_report_stock_picking_tree"/>
<field name="search_view_id" ref="view_report_report_stock_picking_filter"/>
<field name="context">{'search_default_State': 1}</field>
<field name="context">{'search_default_Partner': 1,'search_default_month': 1}</field>
</record>
<record model="ir.actions.act_window.view" id="action_report_report_stock_picking_tree">