odoo中def init(self):

Posted 1314520xh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了odoo中def init(self):相关的知识,希望对你有一定的参考价值。

# -*- 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 

以上是关于odoo中def init(self):的主要内容,如果未能解决你的问题,请参考以下文章

pycharm添加Odoo代码片段

psycopg2.ProgrammingError:无法在 odoo 14 中调整类型“NewId”

关于def __init__(self)

odoo中的mapped

对 def __init__ 中的 __init__ 方法感到困惑

PyQt5对话框窗口打开时没有布局