待解决:图形中当改变分组时,图例不正确
            
存储比率计算时,分组合计不正确

wizard:过滤条件向导,用于输入过滤条件

wizard/sale_chart.py

# -*- coding: utf-8 -*-
from openerp.osv import fields,
osv
import datetime

class
dispatch_sale_chart(osv.osv_memory):
   
_name = "dispatch.sale.chart"
    _description =
u"产品报表向导"
   
    def _get_date_from(self,
cr, uid, context=None):
        """Return
default date_from value"""
       
DATE_FORMAT = "%Y-%m"
        return
datetime.datetime.strftime(datetime.date.today(),
DATE_FORMAT)+'-01'
   
    def
_get_date_to(self, cr, uid,
context=None):
        """Return default
date_to value"""
        DATE_FORMAT =
"%Y-%m-%d"
        return
datetime.datetime.strftime(datetime.date.today(),
DATE_FORMAT)
   
    _columns =
{
        'date_from':fields.date(u'日期从',
select=True, required=True),
       
'date_to':fields.date(u'日期至', select=True,
required=True),
        'target_state':
fields.selection([('draft', u'草稿'),('confirmed', u'已确认'),('all',
u'全部'
)], u'选择状态', required=True), #暂未使用   

    }
   
    _defaults
= {
        'target_state':
'all',
        'date_from':
_get_date_from,
        'date_to':
_get_date_to,
    }

    #动态调用 模块 中的 action ,
组合默认过滤条件(domain)和默认分组(context)

    def
dispatch_sale_chart_open_window(self, cr, uid, ids,
context=None):
        mod_obj =
self.pool.get('ir.model.data')
       
act_obj =
self.pool.get('ir.actions.act_window')
       
if context is
None:
           
context = {}
        data =
self.read(cr, uid, ids, [],
context=context)[0]
       
result = mod_obj.get_object_reference(cr, uid, 'kl_dispatch',
'action_dispatch_sale_profit_tree')
       
id = result and result[1] or False
       
result = act_obj.read(cr, uid, [id],
context=context)[0]
       

        if
context.get('emp_profit', False):
#职员利润统计
           
result['context'] =
str({'group_by_no_leaf':1,'group_by':['department_id', 'employee_id']})
#默认按部门、职员分组,不显示明细
       
else:
           
result['context'] = str({'group_by_no_leaf':1,'group_by':['category',
'product']})
#默认按产品类别、产品名称分组,不显示明细
           

        result['domain'] =
str([('date', '>=', data.get('date_from')), ('date', '<=',
data.get('date_to'))])

#日期查询条件
       
'''
        if data.get('target_state') ==
'all':
           
result['domain'] = str([('date', '>=', data.get('date_from')), ('date',
'<=', data.get('date_to'))])
       
else:
           
result['domain'] = str([('date', '>=', data.get('date_from')), ('date',
'<=', data.get('date_to')), ('state', '=',
data.get('target_state'))])
       
'''
       

        result['name'] = '利润统计('
+ data.get('date_from') + '至' + data.get('date_to') + ')'
#显示页面标题

return result

dispatch_sale_chart()

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

wizard/sale_chart_view.xml

<?xml version="1.0"
encoding="utf-8"?>
<openerp>
    <data>
        <record
id="view_dispatch_sale_chart" model="ir.ui.view">
           
<field name="name">dispatch_sale_chart_form</field>
           
<field name="model">dispatch.sale.chart</field>
           
<field name="arch" type="xml">
               
<form string="销售报表向导" version="7.0">
                   
<group>
                       
<field name="date_from" class="oe_inline"/> -
                       
<field name="date_to" class="oe_inline"/>
                   
</group>
                   
<footer>
                       
<button string="查询报表" name="dispatch_sale_chart_open_window" type="object"
class="oe_highlight"/>
                       
or
                       
<button string="取消" class="oe_link"
special="cancel"/>
                   
</footer>
               
</form>
           
</field>
       
</record>

<record
id="action_dispatch_sale_emp_profit_chart"
model="ir.actions.act_window">
           
<field
name="name">职员利润统计</field>
           
<field
name="res_model">dispatch.sale.chart</field>
           
<field
name="view_type">form</field>
           
<field
name="view_mode">tree,form</field>
           
<field name="view_id"
ref="view_dispatch_sale_chart"/>
           
<field
name="target">new</field>
           
<field name="context">{'emp_profit':True}</field>
<!--职员利润-->
       
</record>
       

        <record
id="action_dispatch_sale_product_profit_chart"
model="ir.actions.act_window">
           
<field
name="name">产品利润统计</field>
           
<field
name="res_model">dispatch.sale.chart</field>
           
<field
name="view_type">form</field>
           
<field
name="view_mode">tree,form</field>
           
<field name="view_id"
ref="view_dispatch_sale_chart"/>
           
<field
name="target">new</field>
           
<field
name="context">{'product_profit':True}</field>

<!--产品利润-->
       
</record>
       

        <menuitem name="利润统计" 
id="menu_dispatch_sale_profit_chart" parent="menu_dispatch_report_root"
groups="group_dispatch_manager"
sequence="20"/>
          

        <menuitem name="职员利润统计" 
id="menu_dispatch_sale_emp_profit_chart"
action="action_dispatch_sale_emp_profit_chart"
          
parent="menu_dispatch_sale_profit_chart"
sequence="10"/>
          

        <menuitem name="产品利润统计" 
id="menu_dispatch_sale_product_profit_chart"
action="action_dispatch_sale_product_profit_chart"
          
parent="menu_dispatch_sale_profit_chart"
sequence="20"/>
   
</data>
</openerp>

report:分组报表、图形分析

report/sale_report.py

# -*- coding:utf-8 -*-
import pooler
import logging
import netsvc
import
tools
logger = netsvc.Logger()
import datetime
import time
import
math
from osv import fields,osv
from openerp.tools.translate import
_  #用于翻译代码中的静态字符串

class
dispatch_sale_report(osv.osv):
   
_name='dispatch.sale.report'
   _description=u"销售单视图"
#增加产品类别的关联,用于查询报表
   _auto =
False
   _rec_name =
'name'

_columns={
       
'name':fields.char(u'单号', size=64,
readonly=True),
       
'date':fields.date(u'日期',
readonly=True),
       
'month':fields.char(_size=10, string = u'月份',
readonly=True),
       
"customer":fields.many2one("dispatch.customer", u"客户",
readonly=True),
       
"product":fields.many2one("dispatch.product", u"产品",
readonly=True),
       
'category':fields.many2one('product.category', u'产品分类',
readonly=True),
       
'price':fields.float(u'单价', digits=(18, 2),
readonly=True),
       
'num':fields.integer(u'数量',
readonly=True),
       
'cost':fields.float(u'成本', digits=(18, 2),
readonly=True),
       
'sum_sale':fields.float(digits=(18, 2), string = u'销售金额',
readonly=True),
       
'sum_cost':fields.float(digits=(18, 2), string = u'成本金额',
readonly=True),
       
'sum_profit':fields.float(digits=(18, 2), string = u'利润金额',
readonly=True),
       
'employee_id':fields.many2one('hr.employee',u'业务员',
readonly=True),
       
'department_id':fields.many2one('hr.department',u'部门',
readonly=True),
       
'klbh':fields.char(u'开龙单号',size=64,
readonly=True),
       
"work_order":fields.many2one("dispatch.work_order","服务单",
readonly=True),
       
'note':fields.text(u'备注',
readonly=True),
        'state':
fields.selection([('draft', u'草稿'),('confirmed', u'已确认')], u'状态',
readonly=True),
        'create_uid':
fields.many2one('res.users', u"创建用户", readonly=True),
   
}
   
    def init(self,
cr):
        tools.drop_view_if_exists(cr,
'dispatch_sale_report')
       
cr.execute("""
           
create or replace view dispatch_sale_report as
(
               
select sale.id, sale.name, sale.date, sale.month, sale.customer, sale.product,
product.category, sale.price,
sale.num,
                          
sale.cost, sale.sum_sale, sale.sum_cost, sale.sum_profit, sale.employee_id,
sale.department_id,
                          
sale.klbh, sale.work_order, sale.note, sale.state,
sale.create_uid
               
from dispatch_sale as
sale
               
inner join dispatch_product as product on (product.id =
sale.product)                                                            
           
)
       
""")
   
dispatch_sale_report()

report/sale_report_view.xml

<?xml
version="1.0"?>
<openerp>
 
<data>

<!-- views dispatch_sale_profit_tree
-->
    <record model="ir.ui.view"
id="dispatch_sale_profit_tree">
       
<field
name="name">dispatch.sale.profit.tree</field>
       
<field
name="model">dispatch.sale.report</field>
       <field
name="type">tree</field>
       
<field
name="priority">1</field>
       
<field name="arch"
type="xml">
           
<tree string="销售利润表"create="false" edit="false"
delete="false">
               
<field name="date"
invisible="1"/>
               
<field name="month"
invisible="1"/>
               
<field name="name"
invisible="1"/>
               
<field name="customer"
invisible="1"/>
               
<field name="category"
invisible="1"/>
               
<field name="product"
invisible="1"/>
               
<field name="num"
sum="合计"/>
               
<field name="price"
invisible="1"/>
               
<field name="cost"
invisible="1"/>
               
<field name="sum_sale"
sum="合计"/>
               
<field name="sum_cost"
sum="合计"/>
               
<field name="sum_profit"
sum="合计"/>
               
<field name="employee_id"
invisible="1"/>
               
<field name="department_id"
invisible="1"/>
             
<field name="work_order"
invisible="1"/>
             
<field name="klbh"
invisible="1"/>
               
<field name="state"
invisible="1"/>
           
</tree>
       
</field>
   
</record>
   
     <record
id="dispatch_sale_profit_graph"
model="ir.ui.view">
         
<field
name="name">dispatch.sale.profit.graph</field>
         
<field
name="model">dispatch.sale.report</field>
         
<field name="arch"
type="xml">
             
<graphstring="销售利润表"type="bar">
                  <field
name="product"/>
                 
<field
name="sum_profit"/>
                 
<field name="category"
group="True"/>
             
</graph>
         
</field>
    
</record>
   
    <!-- views
dispatch_sale_profit_filter -->
    <record
model="ir.ui.view"
id="dispatch_sale_profit_filter">
       
<field
name="name">dispatch.sale.profit.filter</field>
       
<field
name="model">dispatch.sale.report</field>
       <field
name="type">search</field>
       
<field name="arch"
type="xml">
           
<search
string="销售单">
               
<field
name="customer"/>
               
<field
name="category"/>
               
<field
name="product"/>
               
<field
name="department_id"/>
               
<field
name="employee_id"/>
               
<field
name="month"/>
               
<separator/>
               
<filter icon="terp-check" domain="[('state','=','draft')]" string="草稿"
name="draft"/>
               
<filter icon="terp-check" domain="[('state','=','confirmed')]" string="已确认"
name="confirm"/>
               <filter
icon="terp-check" domain="[('state','in',('draft', 'confirmed'))]" string="全部"
name="all"/>
               
<group expand="0"
string="分组">
                   
<filter string="产品类别" icon="terp-personal+" domain="[]"
context="{'group_by':'category'}"/>
                   
<filter string="产品" icon="terp-personal+" domain="[]"
context="{'group_by':'product'}"/>
                   
<filter string="客户" icon="terp-personal" domain="[]"
context="{'group_by':'customer'}"/>
                   
<filter string="部门" icon="terp-personal+" domain="[]"
context="{'group_by':'department_id'}"/>
                   
<filter string="员工" icon="terp-personal" domain="[]"
context="{'group_by':'employee_id'}"/>
                   
<filter string="按月" icon="terp-personal" domain="[]"
context="{'group_by':'month'}"/>
                   
<filter string="状态" icon="terp-stock_effects-object-colorize" domain="[]"
context="{'group_by':'state'}"/>
               
</group>
           
</search>
       
</field>
    </record>

   
<!-- action 默认tree,graph视图 -->
   
<record model="ir.actions.act_window"
id="action_dispatch_sale_profit_tree">
       
<field
name="name">销售利润统计</field>
       
<field name="sequence"
eval="10"/>
        <field
name="type">ir.actions.act_window</field>
       
<field
name="res_model">dispatch.sale.report</field>
       
<field
name="view_type">form</field>
       <field
name="view_mode">tree,graph</field>
       
<field name="view_id"
ref="dispatch_sale_profit_tree"/>
       
<field name="search_view_id"
ref="dispatch_sale_profit_filter"/>
   
</record>

<!-- action 添加tree视图,可用于视图排序显示 -->
    <record
model="ir.actions.act_window.view"
id="action_dispatch_sale_profit_tree1">
       <field
name="sequence"
eval="10"/>
       <field
name="view_mode">tree</field>
       <field
name="view_id"
ref="dispatch_sale_profit_tree"/>
       <field
name="act_window_id"
ref="action_dispatch_sale_profit_tree"/>
   
</record>

<!-- action 添加graph视图,可用于视图排序显示 -->
    <record
model="ir.actions.act_window.view"
id="action_dispatch_sale_profit_graph">
       <field
name="sequence"
eval="20"/>
       <field
name="view_mode">graph</field>
       <field
name="view_id"
ref="dispatch_sale_profit_graph"/>
       <field
name="act_window_id"
ref="action_dispatch_sale_profit_tree"/>
   
</record>
   
 
</data>
</openerp>

report:数据库创建视图中计算比率

# -*- coding: utf-8 -*-
from openerp import tools
from openerp.osv
import fields, osv

class dispatch_transfer_order_report(osv.osv):
    _name =
"dispatch.transfer_order.report"
    _description =
u"转机单统计"
    _auto = False
    _rec_name =
'storefront'
    _order = 'storefront'
   
_columns = {
        'year':
fields.char(u'年', size=4,
readonly=True),
        
'month': fields.char(u'月',
size=8,readonly=True),    
        
"storefront":fields.many2one("dispatch.storefront",u"店面",
readonly=True),
        
"sale_num":fields.float(u"销售数量",readonly=True),
        
"transfer_num":fields.float(u"转机数量",readonly=True
),
        "transfer_rate":fields.float(u"转机率",readonly=True),
   
}

def init(self,
cr):
        tools.drop_view_if_exists(cr,
'dispatch_transfer_order_report')
       
cr.execute("""
           
create or replace view dispatch_transfer_order_report as
(
               
select
                   min(transfer_order.id)
as
id,
                   
storefront.id as
storefront,
                   to_char(transfer_order.date,
'YYYY') as
year,
                   
transfer_order.month as
month,
                   
sum(transfer_order.transfer_num) as
transfer_num,
                   
sum(transfer_order.sale_num) as
sale_num,
                   sum(transfer_order.transfer_num)/sum(transfer_order.sale_num)
as
transfer_rate
               
from dispatch_transfer_order as
transfer_order
               
inner join dispatch_storefront as storefront on (storefront.id =
transfer_order.storefront)
               
group by
storefront.id,
                        
to_char(transfer_order.date,
'YYYY'),
                        
transfer_order.month   
                                        
           
)
       
""")
       
dispatch_transfer_order_report()

openerp学习笔记 统计、分析、报表(过滤条件向导、分组报表、图形分析、比率计算、追加视图排序)的更多相关文章

  1. OpenCV学习笔记(27)KAZE 算法原理与源码分析(一)非线性扩散滤波

    http://blog.csdn.net/chenyusiyuan/article/details/8710462 OpenCV学习笔记(27)KAZE 算法原理与源码分析(一)非线性扩散滤波 201 ...

  2. openerp学习笔记 模块结构分析

    以OpenERP7.0中的 hr_expense 模块为例: 如图中代码所示: __init__.py :和普通 Python 模块中的__init__.py 作用相同,主要用于引用模块根目录下的.p ...

  3. openerp学习笔记 搜索视图(自己创建的、自己的、本部门的、本部门及下属部门的、今日的、日期从,日期至、多条件模糊搜索、or、and)

    自己创建的: domain="[('create_uid','=',uid)]" 自己的: domain="[('employee_id','=','#kl_user_e ...

  4. openerp学习笔记 视图中字段只变化(on_change)联动其他字段值、选择和过滤

    1.修改产品数量时,自动计算产品销售金额.销售成本和销售利润<field name="num" on_change="on_change_product(produ ...

  5. Dynamic CRM 2013学习笔记(八)过滤查找控件 (类似省市联动)

    我们经常要实现类似省市联动一样的功能,常见的就是二个查找控件,一个选择了省后,另一个市的查找控件就自动过滤了,只显示当前省下的市,而不是所有的市.当然这是最简单的,实际工作中还有更复杂的功能要通过过滤 ...

  6. Python学习笔记(二):条件控制语句与循环语句及常用函数的用法

    总结的内容: 1.条件控制语句 2.while循环语句 3.for循环语句 4.函数的用法 一.条件控制语句 1.介绍 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决 ...

  7. openerp学习笔记 context 的应用

    1.在Action中定义,context用于传递搜索条件和分组条件,在搜索视图中默认显示: 示例代码: <record model="ir.actions.act_window&quo ...

  8. Web Service学习笔记(webservice、soap、wsdl、jws详细分析)

    Web Service概述 Web Service的定义 W3C组织对其的定义如下,它是一个软件系统,为了支持跨网络的机器间相互操作交互而设计.Web Service服务通常被定义为一组模块化的API ...

  9. Web Service学习笔记(webservice、soap、wsdl、jws详细分析) (转)

    Web Service概述 Web Service的定义 W3C组织对其的定义如下,它是一个软件系统,为了支持跨网络的机器间相互操作交互而设计.Web Service服务通常被定义为一组模块化的API ...

随机推荐

  1. php打包下载以及断点续传

    php下载单文件 以及 多文件打包下载,支持断点续传 断点续传的功能未经验证 需要nginx或者apache服务器指定静态文件,png, mp4, zip等后缀文件的目录, 直接实例化并调用 down ...

  2. idea中安装git后,代码颜色代表的含义

    idea中安装git以后,代码文件出现了不同的颜色 它们分别表示的含义: 绿色,已经加入控制暂未提交 红色,未加入版本控制 蓝色,加入,已提交,有改动 白色,加入,已提交,无改动 灰色:版本控制已忽略 ...

  3. 第十二章·Kibana深入-日志图形展示

    1.Kibana创建区域图 Kibana支持多重图从展示功能,需要日志是json格式的支持. Kibana区域图 打开浏览器,访问:http://10.0.0.54:5601   选择一个日志  ...

  4. 迭代器遍历【List、Set、Map】

    迭代器遍历[List.Set.Map] example package boom.collection; import java.util.ArrayList; import java.util.Ha ...

  5. deep_learning_Function_One-host参数

    在很多机器学习任务中,特征并不总是连续值,而有可能是分类值.比如星期类型,有星期一.星期二.…….星期日,比如浏览器类型有["uses Firefox", "uses C ...

  6. 数据库——Oracle(4)

    1 Oracle中常用字符处理函数:用来处理char,varchar以及varchar2类型数据. 1)length(列名/字符串):统计当前该列的列值/字符串中字符的个数 select ename, ...

  7. unzip解压3G或者4G以上文件失败的解决方法

    Linux下,使用unzip解压时,报错:End-of-central-directory signature not found.  Either this file is nota zipfile ...

  8. Tomcat基础知识

    介绍Tomcat之前先介绍下Java相关的知识. 各常见组件: 1.服务器(server):Tomcat的一个实例,通常一个JVM只能包含一个Tomcat实例:因此,一台物理服务器上可以在启动多个JV ...

  9. 论文参考文献中的M R J意义

    1 期刊作者.题名[J].刊名,出版年,卷(期):起止页码 2 专著作者.书名[M].版本(第一版不著录).出版地:出版者,出版年.起止页码 3 论文集作者.题名[C].//编者.论文集名.出版地:出 ...

  10. android的ant编译打包

    Android本身是支持ant打包项目的,并且SDK中自带一个build.xml文件. 通过该文件,可以对文件进行编译.打包.安装等.并且支持多种方式打包,如debug或者release. 一般的,可 ...