大家好,我是 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)
)
然后我有 View 文件:
<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 类自动生成的模式弹出框。
View 文件是我尝试过的,我也将 View 添加到 manifest.py
这是界面,食物成本是one2many字段enter image description here
这是我想要覆盖的弹出模式框 enter image description here
那么我错过了什么? 请帮我解决我的问题,我是 Odoo 的新手。我的 Odoo 版本是 Odoo 11,提前致谢。
最佳答案
有两个选项。
- 再定义一个具有更高优先级的表单 View (用于 View 排序)。 Odoo 将加载优先级最低的 View (默认为 16 btw),因此您的旧 View 将加载到菜单中。现在获取新 View 的 externel/xml id 并在员工表单 View 中“调用”它,如下所示:
<field name="food_ids" context="{'form_view_ref': 'my_module.my_second_food_form_view'}" />
- 或者您可以直接在员工表单 View 中定义表单和 TreeView ,您可以在其中定义 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>
关于python - Odoo 11 如何覆盖 one2many 字段自动生成的模态视图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51260801/