OdooERP透视图开发

OdooERP10透视图开发

步骤

  • 创建py文件,定义模型字段
  • 定义模型初始init方法(创建sql视图)
  • 定义view和透视图xml文件

定义py文件,创建模型。

# -*- coding:utf-8 -*-
from odoo import fields, models, tools, api


class InterfaceBankReport(models.Model):
    _name = 'interface_bank_payment_report'
    _auto = False
    _description = u"银行付款单统计报表"

    PAYMENTSTATE = [
        ('00', u'草稿'),
        ('01', u'付款中'),
        ('02', u'交易成功'),
        ('03', u'交易失败')
    ]
    id = fields.Integer(string=u'序号')
    company_id = fields.Many2one(comodel_name='res.company', string=u'公司')
    payment_date = fields.Date(string=u'生成日期')
    payment_amt = fields.Float(string=u'交易金额')
    payment_s_user = fields.Char(string=u'收款户名')
    bank_type = fields.Selection(string=u'交易银行', selection=[('00', u'财企通'), ('01', u'农业银行')])
    state = fields.Selection(string=u'付款状态', selection=PAYMENTSTATE)

    def init(self):
        tools.drop_view_if_exists(self._cr, 'interface_bank_payment_report')
        self._cr.execute("""
            CREATE VIEW interface_bank_payment_report AS (
                SELECT 
                    payment.id as id,
                    payment.company_id as company_id,
                    payment.save_datetime as payment_date,
                    payment.pay_money as payment_amt,
                    payment.partner_id as payment_s_user,
                    payment.bank_type as bank_type, 
                    payment.state as state 
                FROM 
                    interface_bank_payment payment 
        )""")

这里interface_bank_payment表为银企直联模块的付款单。

可以看出以上代码定义了需要统计的字段,和创建了一个init方法,该方法是在数据库创建一条sql视图语句,当在前端界面中点击view视图的菜单时,执行的这条sql语句。

创建xml视图文件

新建xml文件,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <!--统计表tree视图-->
        <record id="interface_report.interface_report_tree_view" model="ir.ui.view">
            <field name="name">付款统计报表</field>
            <field name="model">interface_bank_payment_report</field>
            <field name="arch" type="xml">
                <tree create="false">
                    <field name="company_id"/>
                    <field name="bank_type"/>
                    <field name="payment_s_user"/>
                    <field name="payment_date"/>
                    <field name="payment_amt"/>
                    <field name="state"/>
                </tree>
            </field>
        </record>
        
        <!--统计表透视图-->
        <record id="interface_report.interface_report_pivot" model="ir.ui.view">
            <field name="name">interface_bank_payment_report_pivot</field>
            <field name="model">interface_bank_payment_report</field>
            <field name="arch" type="xml">
                <pivot string="付款统计报表" disable_linking="True">
                    <field name="payment_date" type="row"/>
                     <field name="payment_s_user" type="row"/>
                    <field name="company_id" type="col"/>
                    <field name="bank_type" type="col"/>
                    <field name="state" type="col"/>
                    <field name="payment_amt" type="measure"/>
                </pivot>
            </field>
        </record>
        
        <!--统计表graph视图-->
        <record id="interface_report.interface_report_graph" model="ir.ui.view">
            <field name="name">interface_bank_payment_report.graph</field>
            <field name="model">interface_bank_payment_report</field>
            <field name="arch" type="xml">
                <graph string="付款统计报表" stacked="True">
                    <field name="payment_date" type="row"/>
                    <field name="payment_amt" type="measure"/>
                </graph>
            </field>
        </record>
        
        <!--统计表动作-->
        <record id="interface_report.interface_report_action" model="ir.actions.act_window">
            <field name="name">付款统计报表</field>
            <field name="res_model">interface_bank_payment_report</field>
            <field name="view_type">form</field>
            <field name="view_mode">pivot,tree,graph</field>
            <field name="context">{}</field>
            <field name="domain">[]</field>
        </record>
        
        <!--统计表菜单-->
        <menuitem name="付款统计报表" 
                  id="interface_report.interface_report_menu"
                  parent="interface_report.report"
                  sequence="1"
                  action="interface_report.interface_report_action"/>

    </data>
</odoo>

效果图:

QQ20190121-151951.png

Last modification:January 21st, 2019 at 03:21 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment