Odoo13_创建明细表
1.models.py
from odoo import models, fields, api class Test(models.Model): _name = 'demo' _description = "测试子流程" name = fields.Char("姓名") age = fields.Integer("年龄") state = fields.Selection([('st0', '草稿'), ('st1', '已提交'), ('st2', '已审核'), ('st3', '正在录制'), ('st4', '已交稿')], default='st0', string="状态", track_visibility='onchange') # 明细表字段:第一个参数未明细表的表名,第二个参数未明细表中相对应的Many2one的字段 voicer_number = fields.One2many('sonn', 'test_zhu', string='配音员选择')
# 明细表:流程子表 class Sonn(models.Model): _name = 'sonn' _description = '流程子表' # 创建与主表相对应的Many2one字段,参数未主表表名 test_zhu = fields.Many2one('demo') name = fields.Many2one('pyy', string='配音员') post_cut_member = fields.Many2one('hqjj', string='后期剪辑负责人') age = fields.Integer("要求时间")
2.view.xml
<record id="view_demo_form01" model="ir.ui.view"> <field name="name">业务员发起时form视图</field> <field name="model">demo</field> <field name="arch" type="xml"> <form> <header> <field name="state" widget="statusbar" statusbar_visible="st0,st1,st2,st3,st4"/> </header> <sheet> <div style="text-align: center"><h1>业务员提交FORM</h1></div> <group col='4'> <field name="name"/> <field name="age"/> </group> <newline> <notebook> <page string="配音员选择" name="随便写"> <!-- 主表字段名 --> <field name="voicer_number">
<!-- 当主字段是One2many时,editable="bottom" 是添加明细表时不弹出form视图,直接编辑(可选)--> <tree editable="bottom"> <!-- 明细表字段名 --> <field name="name"/> <field name="post_cut_member"/> <field name="age"/> </tree> </field> </page> </notebook> </newline> </sheet> </form> </field> </record>