Odoo 11 如何覆盖 one2many 字段的自动生成模态视图
Odoo 11 how to override the auto generated modal views of one2many field
大家好,我是 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>
我正在尝试覆盖 class HrFood 自动生成的模式弹出框。
视图文件是我试过的,我也确实将视图添加到 manifest.py
这是界面,食物成本是one2many字段enter image description here
这是我要覆盖的弹出模式框enter image description here
所以我错过了什么?
请帮我解决我的问题,我是 Odoo 的新手。我的 Odoo 版本是 Odoo 11,在此先感谢。
有两种选择。
- 再定义一个具有更高优先级(用于视图排序)的表单视图。 Odoo 将加载具有最低优先级的视图(顺便说一下默认为 16),因此您的旧视图将加载到您的菜单中。现在获取新视图的 externel/xml id,并在您的员工表单视图中 "call" 它,例如:
<field name="food_ids" context="{'form_view_ref': 'my_module.my_second_food_form_view'}" />
- 或者您可以直接在员工表单视图中定义表单和树视图,您可以在其中定义 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 的新手,现在我有 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>
我正在尝试覆盖 class HrFood 自动生成的模式弹出框。
视图文件是我试过的,我也确实将视图添加到 manifest.py
这是界面,食物成本是one2many字段enter image description here
这是我要覆盖的弹出模式框enter image description here
所以我错过了什么? 请帮我解决我的问题,我是 Odoo 的新手。我的 Odoo 版本是 Odoo 11,在此先感谢。
有两种选择。
- 再定义一个具有更高优先级(用于视图排序)的表单视图。 Odoo 将加载具有最低优先级的视图(顺便说一下默认为 16),因此您的旧视图将加载到您的菜单中。现在获取新视图的 externel/xml id,并在您的员工表单视图中 "call" 它,例如:
<field name="food_ids" context="{'form_view_ref': 'my_module.my_second_food_form_view'}" />
- 或者您可以直接在员工表单视图中定义表单和树视图,您可以在其中定义 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>