odoo 自定义视图

文件架构:

  

  model 文件夹里面主要定义了  数据表  和 读取数据的方法  代码如下:

  web_funnet_chart.py:

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

class RunChart(models.Model):
    _name = 'run.chart'

    sales = fields.Integer()
    prices = fields.Integer()
    sale_date = fields.Date()

    @api.multi
    def get_run_chart_data(self):#获取数据库字段的值
        runCHart_ids = self.env['run.chart'].search([])
        sale_lst = []
        price_lst = []
        date_lst = []
        runCHart_lst = []
        for runCHart in runCHart_ids:
            # leads = self.search_count([('sales', '=', sale.sales)])
            sale_lst.append(runCHart.sales)
            price_lst.append(runCHart.prices)
            date_lst.append(runCHart.sale_date)
        runCHart_lst.append((sale_lst,price_lst,date_lst))
        return runCHart_lst

 

 

 

视图的定义放在 \static\src\js\web_funnel_chart.js 这个文件里面

具体代码如下:

/*global Highcharts*/
odoo.define("web_funnel_chart.web_funnel_chart", function(require) {
    "use strict";
    console.log(require)
    var core = require("web.core");
    var dataset = require("web.data");
    var Widget = require("web.Widget");
    var _t = core._t;

    var web_funnel_chart = Widget.extend({
        template: "FunnelChart",
        start: function() {
            var self = this;
            var emp_child = [];
            self.run_chart_dataset = new dataset.DataSetSearch(self, "run.chart", {}, []);
            self.run_chart_dataset.call("get_run_chart_data", [
                []
            ]).done(function(callbacks) {
                Highcharts.chart('container', { /*  视图在这里开始定义  */
                chart: {
                    zoomType: 'xy'
                },
                title: {
                    text: 'Daily sales and price charts'
                },
                subtitle: {
                    text: 'Remarks: basic version of the chart'
                },
                xAxis: [{
                    categories: callbacks[0][2],
                    crosshair: true
                }],
                yAxis: [{ // Primary yAxis
                    labels: {
                        format: '{value} RMB',
                        style: {
                            color: Highcharts.getOptions().colors[1]
                        }
                    },
                    title: {
                        text: 'Price',
                        style: {
                            color: Highcharts.getOptions().colors[1]
                        }
                    }
                }, { // Secondary yAxis
                    title: {
                        text: 'Sales',
                        style: {
                            color: Highcharts.getOptions().colors[0]
                        }
                    },
                    labels: {
                        format: '{value} Ton',
                        style: {
                            color: Highcharts.getOptions().colors[0]
                        }
                    },
                    opposite: true
                }],
                tooltip: {
                    shared: true
                },
                legend: {
                    layout: 'vertical',
                    align: 'left',
                    x: 120,
                    verticalAlign: 'top',
                    y: 100,
                    floating: true,
                    backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
                },
                series: [{
                    name: 'Sales',
                    type: 'column',
                    yAxis: 1,
                    data: callbacks[0][0],
                    tooltip: {
                        valueSuffix: ' Ton'
                    }

                }, {
                    name: 'Price',
                    type: 'spline',
                    data: callbacks[0][1],
                    tooltip: {
                        valueSuffix: ' RMB'
                    }
                }]
            });
            });

        },
    });

    core.action_registry.add("web_funnel_chart.funnel", web_funnel_chart);  /*把视图 注册在odoo里面  方便展示

});

 

 

\static\src\xml\web_funel_chear.xml  这个具体的作用还不太清楚(后续弄明白再更新)

<?xml version="1.0" encoding="UTF-8"?>
<templates>
    <t t-name="FunnelChart">
        <div id="container">
        </div>
    </t>
</templates>

 

 

\views\templates.xml  odoo的视图层   这个文件主要是把视图的相关文件与依赖包引进odoo

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <template id="assets_backend" name="web_lead_funnel_chart_assets" inherit_id="web.assets_backend">
        <xpath expr="." position="inside">
            <script type="text/javascript"
                    src="/web_funnel_chart/static/src/lib/highcharts.js"/>
            <script type="text/javascript"
                    src="/web_funnel_chart/static/src/lib/funnel.js"/>
            <script type="text/javascript"
                    src="/web_funnel_chart/static/src/js/web_funnel_chart.js"/>
        </xpath>
    </template>
</odoo>

 

 

views\web_funnel_chaer_view.xml 把视图显示到odoo上面的一些相关操作定义

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <record id="action_funnel_chart" model="ir.actions.client">
        <field name="name">Lead Funnel Chart</field>
        <field name="tag">web_funnel_chart.funnel</field>
    </record>

    <menuitem id="FunnelCHart_main" name="Funnel Chart11"/>

    <menuitem id="menu_FunnelCHart" name="Funnel Chart22" parent="FunnelCHart_main"
              action="action_funnel_chart" />

    <record id="run_chart_tree" model="ir.ui.view">
        <field name="name">RunCHart.tree</field>
        <field name="model">run.chart</field>
        <field name="arch" type="xml">
            <tree>
                <field name="sales" />
                <field name="prices" />
                <field name="sale_date" />
            </tree>
        </field>
    </record>

    <record id="run_chart_form" model="ir.ui.view">
        <field name="name">RunCHart.form</field>
        <field name="model">run.chart</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <group>
                        <field name="sales" />
                        <field name="prices" />
                        <field name="sale_date" />
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record id="action_run_chart" model="ir.actions.act_window">
        <field name="name">Run Chart</field>
        <field name="res_model">run.chart</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>

    <menuitem id="run_chart_main_mune" name="Run Chart"
              parent="FunnelCHart_main" action="action_run_chart"
    />

</odoo>

 

__manifest__.py 应用的描述文件

# -*- coding: utf-8 -*-
{
    'name':'test1',
    'category':'Web',
    'author':'Bruce',
    'depends':[],
    'data': [
        "views/templates.xml",
        "views/web_funnel_chaer_view.xml"
    ],

    'qweb': ['static/src/xml/*.xml'],
    'installable':True,
    'auto_install':False,
    'application':True

}

 

转载于:https://www.cnblogs.com/brucexl/p/7169135.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Odoo中新建自定义视图,需要进行以下操作: 1. 在odoopython代码中增加新视图类型与视图模式。这可以通过在ir_actions_act_window.py和ir_ui_view.py文件中添加相关代码来实现。例如,在ir_actions_act_window.py文件中,我们可以增加以下代码来定义新的视图模式: ``` # -*- coding: utf-8 -*- from odoo import fields, models class ActWindowView(models.Model): _inherit = 'ir.actions.act_window.view' view_mode = fields.Selection(selection_add=[('eview', 'echart views')]) ``` 在ir_ui_view.py文件中,我们可以添加以下代码来定义新的视图类型: ``` # -*- coding: utf-8 -*- from odoo import fields, models class View(models.Model): _inherit = 'ir.ui.view' type = fields.Selection(selection_add=[('eview', 'echart views')]) ``` 这样,Odoo就可以识别我们新定义的视图类型。 2. 定义js相关文件和模板代码。通过编写相应的javascript文件和模板代码,我们可以实现对自定义视图的布局和行为的控制。这些文件需要与新定义的视图类型相关联,并与视图模板文件进行交互。具体的实现方法可以根据项目需求和技术要求来确定。 这样,在执行以上操作之后,就可以在Odoo中创建自定义视图了。自定义视图可以根据具体需求来设计和实现,包括自定义的布局、交互和样式等方面 。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Odoo自定义视图教程](https://blog.csdn.net/u012739578/article/details/121670077)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值