odoo11.0模块开发View讲解(一)

感觉涉及view的知识点真是好多,不得不花很多时间在这里。 这一章继续讲关于view的。

  • 演示的数据模块例子

    新开了一个模块用来讲解,毕竟例子的局限性导致一些功能不好去写

# -*- coding: utf-8 -*-
from odoo import models, fields, api
class temperature_alarm(models.Model):
    _name = 'temperature_alarm.temperature_alarm'
    _description = '超温报警模块'
    name = fields.Char(string='产品名')
    temperature = fields.Integer(string='当前温度')
    security_value = fields.Integer(string='安全预值')
    alarm_level = fields.Integer(string='报警等级')
    start_time = fields.Date(string='开始运输日期')
    person = fields.Char(string='负责人')
    phone = fields.Char(string='联系电话')
    number = fields.Char(string='运单编号')
    status = fields.Integer(string='状态') # 0:准备运输  1:运输中 2:运输完成
    def button_search_logistics(self):
        print('button_search_logistics')
    def button_search_alarmlog(self):
        # search是api接口,提供数据条件搜索,参数是一个list,每个参数都是含有三个值得的tuple
        ob = self.search([('status','=',1)])
        print(ob.name)
class testInheritance(models.Model):
    _inherit = 'qingjia.qingjiadan' # _inherit表示继承某一模块,所以_name可能写,因为本身属于继承机制
    testField = fields.Char(string='测试字段')
  • search元素

    存在于带有arch字段的field元素里,用来自定义过滤搜索的,可以在筛选组里看到。

    <!--像这样用-->
    <!--设置筛选按钮-->
    <record model="ir.ui.view" id="temperature_menu_search">
        <field name="name">搜索</field>
        <field name="model">temperature_alarm.temperature_alarm</field>
        <field name="arch" type="xml">
            <search>
                <field name="name"/>
                <!--domain是过滤条件-->
                <filter string="准备运输" domain="[('status','=',0)]"/>
                <filter string="正在运输" domain="[('status','=',1)]"/>
                <filter string="运输完毕" domain="[('status','=',2)]"/>
            </search>
        </field>

    </record>
  • header元素

    存在于form元素中,放在开始位置就显示前面,放在form末尾就显示在后面

<form>
    <!--像这样用-->
    <header>
        <!--name是button的id,同时也是模型里的对应方法名绑定,用于监听按钮点击
                    string:按钮名称
        -->
        <button name="button_search_logistics" type="object" string="查询物流"/>
        <button name="button_search_alarmlog" type="object" string="查询报警日志"/>
    </header>
</form>
  • widget属性(小部件)

    存在于field元素的属性里,用于修饰该字段属于什么小部件

widget="statusbar"   头部状态条标签
widget="email"  电子邮件地址标签
widget="selection" 下拉选择标签
widget="mail_followers" 关注者标签
widget="mail_thread" 消息标签
widget="progressbar" 进度条,按百分比标签
widget="one2many_list" 一对多列表标签
widget="many2many_tags" 多对多显示标签
widget="url"  网站链接标签
widget='image' 图片标签
widget="many2many_kanban" 看版标签
widget="handler" 触发标签
widget="radio" 单选标签
widget="char_domain"   字符域标签
widget="monetary"  价格(和精度位数相关)标签
widget="float_time" 单精度时间标签
widget="html" html相关标签
widget="pad" pad显示相关标签
widget="date" 日期标签
widget="monetary" 金额标签
widget='text' 文本标签
widget="sparkline_bar" 燃尽标签
widget="checkbox" 复选框标签
widget="reference" 关联标签
<!--像这样用-->
<tree>
    <field name="start_time" widget="date"/>
    <field name="name"/>
    <field name="number"/>
</tree>

results matching ""

    No results matching ""