Odoo 11如何覆盖one2many字段的自动生成的模态视图

时间:2018-07-10 08:43:52

标签: python odoo odoo-11

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

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类自动生成的模式弹出框。

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

这是界面,食品费用是一个单身字段enter image description here

这是我要覆盖enter image description here

的弹出模式框

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

1 个答案:

答案 0 :(得分:1)

有两个选项。

  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>