Skip to Content
Menu
This question has been flagged
3 Replies
1077 Views

Hi community,

I wanted to make a boolean field in res.partner when i create a record in my custom module. Below is my code. Please help. 


class Res(models.Model):
_inherit = 'res.partner'

is_bool = fields.Boolean(default=False)


class Custom(models.Model):
_name = 'custom.custom'

name = fields.Char('Name')
age = fields.Integer('Age')


Regards.


Avatar
Discard
Best Answer

Hi,

You can do it by supering the create function of your custom.custom model.

You can use the below code,

@api.model
def create(self, vals):
res = super(ClassName, self).create(vals)
res.partner.is_bool = True
return res

Regards

Avatar
Discard
Author Best Answer
class Custom(models.Model):
_name = 'custom.custom'

name = fields.Char('Name')
age = fields.Integer('Age')
address = fields.Text('Address')
phone = fields.Integer('phone')
mail = fields.Char('Mail')
partner = fields.Many2one('res.partner')

@api.onchange
def onchange_partner(self):
self.name = self.partner.name

I want to make the boolean field true when creating and chosing the parnter


Avatar
Discard

using onchange you cannot achieve it, inside the create/write function you have to apply the logic for this or you have to add a button in the form for this.

Or make is_bool as a compute field

Best Answer

Hi,

What is the relation between custom.custom model and res.partner model ? Are you looking to tick the is_bool field as True for all the records in res.partner table when you create a record in custom.custom model ?

The above things are not clear from the question, any way you can achieve this by overriding the create method of the custom.custom model and updating the res.partner records inside the create function.


Thanks

Avatar
Discard