Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
4 Odpowiedzi
1350 Widoki

Hi everyone,

When I create a new contact, the company_type is defined as person. I would like to set it to company by default.

So I created a model that inherited res.partner model, and I define is_company to True by default 

class ResPartner(models.Model):

    _inherit = 'res.partner'

    brand_name = fields.Char()

    is_company = fields.Boolean(default=True)

But it stays as person as default. 

What should I do ? 

Thanks a lot 

Awatar
Odrzuć
Najlepsza odpowiedź

I believe you can utilize user defaults for this purpose.

Enable debug mode.

Navigate to the contact page.

Tap on the debug icon.

Select the user defaults option.

Awatar
Odrzuć
Najlepsza odpowiedź

Hello Arthur LEHAVRE ,


Use this code you no need to override the is_company field.

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

@api.onchange('company_type')
def onchange_company_type(self):
rec = super().onchange_company_type()
self.is_company = False
return rec

Hope this helps!

Thanks & Regards,

Name : Yahoo Baba

Email:  yahoobaba077@gmail.com 

Awatar
Odrzuć
Autor Najlepsza odpowiedź

Thank you ! Indeed it works great ! And is there way to set it up in my model ?

Awatar
Odrzuć
Najlepsza odpowiedź

i think you can use user defaults 

activate debug mode

open the contact page 

press on debug icon

click on user defaults 


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
gru 24
902
3
lip 25
1907
1
cze 25
2165
2
maj 25
1910
1
maj 25
1158