Odoo 11如何覆盖one2many字段的自动生成的模态视图 [英] Odoo 11 how to override the auto generated modal views of one2many field

查看:219
本文介绍了Odoo 11如何覆盖one2many字段的自动生成的模态视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是Odoo的新手,现在我有2个型号,如下所示:

Hi guys i am new to Odoo, for now i have 2 model as below:

class HumanResource(models.Model):
_name = 'hr.employee'
_inherit = 'hr.employee'

test = fields.Char('test')

# Profiling Details
food_ids = fields.One2many(
    'hr.employee.food',
    'food_id',
    string='Food Cost'
)

class HrFood(models.Model):
_name = "hr.employee.food"
_description = "Employee Food"

# food_id = fields.Many2one('hr.employee', 'Food', default={'food_id': lambda self, cr, uid, context: context.get('food_id')})
food_id = fields.Many2one('hr.employee', string='Employee Name')
# foodtype = ?to?
food_name = fields.Char(
    string='Food Name',
    help='Please Enter the Food Name'
)

food_category = fields.Selection(
    [('breakfast', 'Breakfast'),
     ('lunch', 'Lunch'),
     ('teatime', 'Tea Time'),
     ('dinner', 'Dinner'),
     ('supper', 'Supper')],
    string='Category',
)
food_cost = fields.Float(
    string='Food Amount',
    digits=(5, 2)
)

然后我有查看文件:

<odoo>
<record id="view_form_hr_employee_food" model="ir.ui.view">
    <field name="name">Create Food Cost</field>
    <field name="model">hr.employee.food</field>
    <field name="arch" type="xml">
        <form>
            <sheet>
                <group>
                        <field name="food_id" />
                        <separator string="Reference" />
                        <field name="food_category" />
                        <field name="food_name" />
                        <field name="food_cost" />
                </group>
            </sheet>
        </form>
    </field>
</record>
</odoo>

我试图覆盖类HrFood自动生成的模式弹出框.

I'm trying to override the modal pop up box that auto generate by the class HrFood.

视图文件是我尝试过的,我也确实将视图添加到了清单 .py

The view file is what i've tried, also i did add the views into manifest.py

这是界面,食物费用是one2many字段在此处输入图像描述

This is the interface, and the food cost is the one2many field enter image description here

这是我要覆盖的弹出模式框在此处输入图像描述

This is the pop up modal box that i want to override enter image description here

那我错过了什么? 请帮助我解决我的问题,我是Odoo的newbee.我的Odoo版本是Odoo 11,谢谢.

So what do i missed? Please help me to solve my question, i am newbee in Odoo. And my Odoo version is Odoo 11, Thanks in advance.

推荐答案

有两个选项.

  1. 再定义一个具有更高优先级的表单视图(用于对视图进行排序). Odoo将以最低优先级加载视图(默认值为16 btw),因此您的旧视图将加载到菜单中.现在,获取新视图的externel/xml ID并在您的员工表单视图中调用"它,例如:

<field name="food_ids" context="{'form_view_ref': 'my_module.my_second_food_form_view'}" />

  1. 或者您可以直接在员工表单视图中定义表单和树形视图,您可以在其中定义one2many字段:

<field name="food_ids">
    <form>
        <!-- your form view here -->
    </form>
    <tree editable="bottom"> <!-- if you don't want it editable just delete the attribute -->
        <!-- your tree view here -->
    </tree>
</field>

这篇关于Odoo 11如何覆盖one2many字段的自动生成的模态视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆