Reputation: 55
I'm using many2one field in Odoo 11. My select box's first option coming empty as default but I don't want to this.
<select class="o_input o_field_widget o_required_modifier" name="department_id" id="o_field_input_28">
<option value="false"></option>
<option value="4">Test Departma</option>
</select>
If there is one option except default empty option in the select box then it will be selected initially. Otherwise, It can be selected empty option initially.
Please help me.
Upvotes: 1
Views: 1457
Reputation: 14778
You could either set a default in the client or implement it in the code.
Code
@api.model
def default_department_id(self):
# just an example! implement your own default
# always return a recordset (even an empty one)!
return self.env['my.department.model'].search([], limit=1)
department_id = fields.Many2one(
comodel_name="my.department.model", default=default_department_id)
Client:
Upvotes: 2