码迷,mamicode.com
首页 > 其他好文 > 详细

odoo中def init(self):

时间:2019-01-13 19:12:59      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:repo   创建   des   sts   视图   string   model   only   exec   

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

标签:repo   创建   des   sts   视图   string   model   only   exec   

原文地址:https://www.cnblogs.com/1314520xh/p/10263443.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!