[IMP]:Improved SQL purchase report.

bzr revid: apa@tinyerp.com-20100310072742-28lym17cjluthmf6
This commit is contained in:
apa-tiny 2010-03-10 12:57:42 +05:30
parent 3995a50e22
commit c9be1c2271
5 changed files with 129 additions and 231 deletions

View File

@ -41,7 +41,8 @@
'purchase_wizard.xml',
'stock_view.xml',
'partner_view.xml',
'process/purchase_process.xml'
'process/purchase_process.xml',
'report/purchase_report_view.xml',
],
'demo_xml': ['purchase_demo.xml'],
'installable': True,

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
@ -15,12 +15,13 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import order
import request_quotation
import purchase_report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
@ -15,7 +15,7 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@ -26,11 +26,12 @@
from osv import fields,osv
import tools
class report_purchase_order_product(osv.osv):
_name = "report.purchase.order.product"
_description = "Purchases Orders by Products"
class report_purchase_order(osv.osv):
_name = "report.purchase.order"
_description = "Purchases Orders"
_auto = False
_columns = {
'date': fields.date('Date', readonly=True),
'name': fields.char('Year',size=64,required=False, readonly=True),
'state': fields.selection([
('draft','Quotation'),
@ -43,6 +44,10 @@ class report_purchase_order_product(osv.osv):
('cancel','Cancel')
], 'Order State', readonly=True),
'product_id':fields.many2one('product.product', 'Product', readonly=True),
'category_id': fields.many2one('product.category', 'Categories', readonly=True),
'partner_id':fields.many2one('res.partner', 'Partner', readonly=True),
'company_id':fields.many2one('res.company', 'Company', readonly=True),
'user_id':fields.many2one('res.users', 'Responsible', 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),
@ -53,62 +58,19 @@ class report_purchase_order_product(osv.osv):
}
_order = 'name desc,price_total desc'
def init(self, cr):
tools.sql.drop_view_if_exists(cr, 'report_purchase_order_product')
tools.sql.drop_view_if_exists(cr, 'report_purchase_order')
cr.execute("""
create or replace view report_purchase_order_product as (
create or replace view report_purchase_order as (
select
min(l.id) as id,
s.date_order as date,
to_char(s.date_order, 'YYYY') as name,
to_char(s.date_order, 'MM') as month,
s.state,
s.partner_id as partner_id,
s.create_uid as user_id,
s.company_id as company_id,
l.product_id,
sum(l.product_qty*u.factor) as quantity,
count(*),
sum(l.product_qty*l.price_unit) as price_total,
(sum(l.product_qty*l.price_unit)/sum(l.product_qty*u.factor))::decimal(16,2) as price_average
from purchase_order s
left join purchase_order_line l on (s.id=l.order_id)
left join product_uom u on (u.id=l.product_uom)
where l.product_id is not null
group by l.product_id, to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),s.state
)
""")
report_purchase_order_product()
class report_purchase_order_category(osv.osv):
_name = "report.purchase.order.category"
_description = "Purchases Orders by Categories"
_auto = False
_columns = {
'name': fields.char('Year',size=64,required=False, readonly=True),
'state': fields.selection([
('draft','Quotation'),
('waiting_date','Waiting Schedule'),
('manual','Manual in progress'),
('progress','In progress'),
('shipping_except','Shipping Exception'),
('invoice_except','Invoice Exception'),
('done','Done'),
('cancel','Cancel')
], 'Order State', readonly=True),
'category_id': fields.many2one('product.category', 'Categories', 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),
'count': fields.integer('# of Lines', 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),
}
_order = 'name desc,price_total desc'
def init(self, cr):
tools.sql.drop_view_if_exists(cr, 'report_purchase_order_category')
cr.execute("""
create or replace view report_purchase_order_category as (
select
min(l.id) as id,
to_char(s.date_order, 'YYYY') as name,
to_char(s.date_order, 'MM') as month,
s.state,
t.categ_id as category_id,
sum(l.product_qty*u.factor) as quantity,
count(*),
@ -120,10 +82,12 @@ class report_purchase_order_category(osv.osv):
left join product_template t on (t.id=p.product_tmpl_id)
left join product_uom u on (u.id=l.product_uom)
where l.product_id is not null
group by t.categ_id, to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),s.state
)
group by s.company_id,s.create_uid,s.partner_id,
t.categ_id,l.product_id,s.date_order,
to_char(s.date_order, 'YYYY'),to_char(s.date_order, 'MM'),s.state
)
""")
report_purchase_order_category()
report_purchase_order()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_purchase_order_graph">
<field name="name">product.month.graph</field>
<field name="model">report.purchase.order</field>
<field name="type">graph</field>
<field name="arch" type="xml">
<graph string="Purchase Orders Statistics" type="bar">
<field name="product_id"/>
<field name="quantity" operator="+"/>
<field name="price_total" operator="+"/>
</graph>
</field>
</record>
<record id="view_purchase_order_tree" model="ir.ui.view">
<field name="name">report.purchase.order.tree</field>
<field name="model">report.purchase.order</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Purchase Orders Statistics">
<field name="name"/>
<field name="month"/>
<field name="partner_id"/>
<field name="product_id"/>
<field name="user_id" invisible="1"/>
<field name="category_id" invisible="1"/>
<field name="date" invisible="1"/>
<field name="company_id" invisible="1"/>
<field name="count"/>
<field name="quantity"/>
<field name="price_total"/>
<field name="price_average"/>
<field name="state"/>
</tree>
</field>
</record>
<record id="view_purchase_order_search" model="ir.ui.view">
<field name="name">report.purchase.order.search</field>
<field name="model">report.purchase.order</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Sale Orders">
<filter icon="terp-purchase"
string="This Year"
domain="[('name','=',time.strftime('%%Y'))]"
default="1"
help="Sales orders of the year"/>
<filter icon="terp-purchase"
string="This Month"
default="1"
domain="[('month','=',time.strftime('%%m'))]"
help="Sales orders of this month"/>
<separator orientation="vertical"/>
<filter icon="terp-purchase"
string="Quotations"
domain="[('state','=','draft')]"/>
<filter icon="terp-purchase"
string="Purchases"
default="1"
domain="[('state','&lt;&gt;','draft'),('state','&lt;&gt;','cancel')]"/>
<separator orientation="vertical"/>
<field name="product_id"/>
<field name="user_id" widget="selection">
<filter icon="terp-purchase"
string="My Sales"
domain="[('user_id','=',uid)]"/>
</field>
<field name="partner_id"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<newline/>
<group expand="1" string="Group By..." colspan="10" col="12">
<filter string="Company" icon="terp-purchase" context="{'group_by':'company_id'}"/>
<filter string="Responsible" icon="terp-purchase" context="{'group_by':'user_id'}" default="1"/>
<separator orientation="vertical"/>
<filter string="Product" icon="terp-purchase" context="{'group_by':'product_id'}"/>
<filter string="Product Category" icon="terp-purchase" context="{'group_by':'category_id'}"/>
<filter string="Partner" icon="terp-purchase" context="{'group_by':'partner_id'}"/>
<filter string="State" icon="terp-purchase" context="{'group_by':'state'}"/>
<separator orientation="vertical"/>
<filter string="Month" icon="terp-purchase" context="{'group_by':'date'}"/>
<filter string="Year" icon="terp-purchase" context="{'group_by':'name'}"/>
</group>
</search>
</field>
</record>
<record id="action_purchase_order_report_all" model="ir.actions.act_window">
<field name="name">Purchase Orders</field>
<field name="res_model">report.purchase.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="search_view_id" ref="view_purchase_order_search"/>
</record>
<menuitem id="base.next_id_73" name="Reporting" parent="base.menu_purchase_root" sequence="8"/>
<menuitem action="action_purchase_order_report_all" id="menu_action_purchase_order_report_all" parent="base.next_id_73" sequence="3"/>
</data>
</openerp>

View File

@ -1,171 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Purchases by products by month -->
<record id="view_order_product_form" model="ir.ui.view">
<field name="name">report.purchase.order.product.form</field>
<field name="model">report.purchase.order.product</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Purchases by products">
<field name="name" select="1"/>
<field name="month" select="1"/>
<field name="product_id" select="1"/>
<field name="count"/>
<field name="quantity" select="1"/>
<field name="price_total" select="1"/>
<field name="price_average" select="1"/>
<field name="state" select="1"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_product_month_graph">
<field name="name">product.month.graph</field>
<field name="model">report.purchase.order.product</field>
<field name="type">graph</field>
<field name="arch" type="xml">
<graph string="Purchases by products" type="bar">
<field name="product_id"/>
<field name="quantity" operator="+"/>
<field name="price_total" operator="+"/>
</graph>
</field>
</record>
<record id="view_order_product_tree" model="ir.ui.view">
<field name="name">report.purchase.order.product.tree</field>
<field name="model">report.purchase.order.product</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Purchases by products">
<field name="name"/>
<field name="month"/>
<field name="product_id"/>
<field name="count"/>
<field name="quantity"/>
<field name="price_total"/>
<field name="price_average"/>
<field name="state"/>
</tree>
</field>
</record>
<record id="view_order_product_search" model="ir.ui.view">
<field name="name">report.purchase.order.product.search</field>
<field name="model">report.purchase.order.product</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Purchases by products">
<group col="8" colspan="4">
<filter icon="terp-purchase" string="This Year" domain="[('name','=',time.strftime('%%Y'))]" help="Purchases by products during this year"/>
<filter icon="terp-purchase" string="This Month" domain="[('month','=',time.strftime('%%m'))]" help="Purchases by products during this month"/>
<separator orientation="vertical"/>
<field name="name" select="1"/>
<field name="month" select="1"/>
<field name="product_id" select="1"/>
<field name="state" select="1"/>
</group>
</search>
</field>
</record>
<record id="action_order_product_tree_all" model="ir.actions.act_window">
<field name="name">Purchases by Products</field>
<field name="res_model">report.purchase.order.product</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="search_view_id" ref="view_order_product_search"/>
</record>
<menuitem id="next_id_73" name="Reporting" parent="base.menu_purchase_root"/>
<menuitem action="action_order_product_tree_all" id="menu_report_order_product_all"
name="PO by Products" parent="next_id_73"/>
<!-- Purchases by category by month -->
<record id="view_order_category_form" model="ir.ui.view">
<field name="name">report.purchase.order.category.form</field>
<field name="model">report.purchase.order.category</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Purchases by Category of Products">
<field name="name" select="1"/>
<field name="month" select="1"/>
<field name="category_id" select="1"/>
<field name="count"/>
<field name="quantity" select="1"/>
<field name="price_total" select="1"/>
<field name="price_average" select="1"/>
<field name="state" select="1"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_product_category_graph">
<field name="name">product.category.graph</field>
<field name="model">report.purchase.order.category</field>
<field name="type">graph</field>
<field name="arch" type="xml">
<graph string="Purchases by Category of Products" type="bar">
<field name="category_id"/>
<field name="quantity" operator="+"/>
<field name="price_total" operator="+"/>
</graph>
</field>
</record>
<record id="view_order_category_tree" model="ir.ui.view">
<field name="name">report.purchase.order.category.tree</field>
<field name="model">report.purchase.order.category</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Purchases by Category of Products">
<field name="name"/>
<field name="month"/>
<field name="category_id"/>
<field name="count"/>
<field name="quantity"/>
<field name="price_total"/>
<field name="price_average"/>
<field name="state"/>
</tree>
</field>
</record>
<record id="view_order_category_search" model="ir.ui.view">
<field name="name">report.purchase.order.category.search</field>
<field name="model">report.purchase.order.category</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Purchases by category of products">
<group col="8" colspan="4">
<filter icon="terp-purchase" string="This Year" domain="[('name','=',time.strftime('%%Y'))]" help="Purchases by categories of products during this year"/>
<filter icon="terp-purchase" string="This Month" domain="[('month','=',time.strftime('%%m'))]" help="Purchases by categories of products during this month"/>
<separator orientation="vertical"/>
<field name="name" select="1"/>
<field name="month" select="1"/>
<field name="category_id" select="1"/>
<field name="state" select="1"/>
</group>
</search>
</field>
</record>
<record id="action_order_category_tree_all" model="ir.actions.act_window">
<field name="name">Purchases by Category of Products</field>
<field name="res_model">report.purchase.order.category</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="search_view_id" ref="view_order_category_search"/>
</record>
<menuitem action="action_order_category_tree_all" id="menu_report_order_category_all"
name="PO by Products Category" parent="report_purchase.next_id_73"/>
<act_window domain="[('product_id', '=', active_id)]" id="act_product_product_2_report_purchases_order_product" name="Monthly purchases" res_model="report.purchase.order.product" src_model="product.product"/>
<act_window domain="[('category_id', '=', active_id)]" id="act_product_category_2_report_purchase_order_category" name="Monthly purchases" res_model="report.purchase.order.category" src_model="product.category"/>
</data>
</openerp>