Reputation: 17
I created a many2one field that has relationship custom model. I want to know how to self default value. My default value is "Head/Branch".
Here is my code. Thank You.
from odoo import models, fields, api
import logging
class CrmnNewTask(models.Model):
_inherit = 'res.partner'
head_branch=fields.Many2one('head.branch', string='Head/Branch',index=True, ondelete='cascade')
class Headbranch(models.Model):
_name='head.branch'
name=fields.Char('Head/Branch')
Upvotes: 0
Views: 2924
Reputation: 716
Please implement this example in your code :
user_id = fields.Many2one('res.users','User', default=lambda self: self.env.user)
Here I have set current user name in many2one field. You can also set default value using function. This one another example :
*
tax_group_id = fields.Many2one('account.tax.group', string="Tax Group", default=_default_tax_group, required=True)
@api.model
def _default_tax_group(self):
return self.env['account.tax.group'].search([], limit=1)
*
Upvotes: 2
Reputation: 2358
Try this:
Go to your form where is field head_branch
Active developer mode
Populate field and save as default https://i.sstatic.net/gHPS3.jpg
Upvotes: 0