odoo中def init(self):

本文详细介绍如何在Odoo中使用Python代码创建一个基于PostgreSQL的报表视图,包括定义模型、字段、视图和菜单项的过程。通过SQL语句构建视图,实现对测试订单数据的统计分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, tools


class test_report(models.Model):
    _name = 'test.report'
    _auto = False
    _description = 'Test Report'


    test = fields.Char(string='Test', readonly=True)
    qty = fields.Float(readonly=True)
    price = fields.Float(readonly=True)
    total = fields.Float(readonly=True)
    note = fields.Char(readonly=True)
    order_date = fields.Datetime(stirng='Order Date', readonly=True)

    @api.model_cr
    def init(self):
        """test report"""
        tools.drop_view_if_exists(self.env.cr, 'test_report')
        self.env.cr.execute("""
            CREATE OR REPLACE VIEW test_report AS (
                select t1.id,t1.test as test ,t1.qty as qty,t1.price as price,(t1.qty*t1.price) as total,t1.note as note,t0.now_date as order_date
                from test_order_data t0 
                left join test_order_data_line  t1 on t0.id=t1.order_id
            )""")
   <record id="test_report_tree_view" model="ir.ui.view">
            <field name="name">test report tree view</field>
            <field name="model">test.report</field>
            <field name="arch" type="xml">
                <tree string="">
                    <field name="test"/>
                    <field name="qty"/>
                    <field name="price"/>
                    <field name="total"/>
                    <field name="note"/>
                    <field name="order_date"/>
                </tree>
            </field>
        </record>
 <record model="ir.actions.act_window" id="test_report_action">
            <field name="name">测试报表</field>
            <field name="res_model">test.report</field>
            <field name="view_mode">tree</field>
        </record>



  <menuitem name="测试报表"
                  id="test_report_menu"
                  action="test_report_action"
                  sequence="3"/>

odoo中创建一个视图:postgresql 

转载于:https://www.cnblogs.com/1314520xh/p/10263443.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值