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)
)
And then i have the view file:
<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>
I'm trying to override the modal pop up box that auto generate by the class HrFood.
The view file is what i've tried, also i did add the views into manifest.py
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
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.
There are two options.
- Define one more form view with a higher priority (that's used for ordering of views). Odoo will load the view with the lowest priority (default is 16 btw), so your old view will be loaded in your menues. Now take the externel/xml id of the new view and "call" it in your employee form view like:
<field name="food_ids" context="{'form_view_ref': 'my_module.my_second_food_form_view'}" />
- Or you can just define form and tree views right in the employee form view, where you define your one2many field:
<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>
来源:https://stackoverflow.com/questions/51260801/odoo-11-how-to-override-the-auto-generated-modal-views-of-one2many-field