Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
1602 มุมมอง

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 

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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 

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

i think you can use user defaults 

activate debug mode

open the contact page 

press on debug icon

click on user defaults 


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ธ.ค. 24
1132
3
ก.ค. 25
2349
1
มิ.ย. 25
3199
2
มิ.ย. 25
2293
1
พ.ค. 25
1430