odoo中def init(self):
阿新 • • 發佈:2019-01-13
# -*- 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