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

Dear all

I would want to have the same behavior as when you click on

Sale > Customers > Create (> the customer checkbox for the partner is automatically selected)

Or

Purchase > Suppliers > Create (> the supplier checkbox for the partner is automatically selected)

I added a new checkbox "Doctor" to partner, and I would want to set it as default if I click "Create" at my new menu at Medical.

Medical > Doctor > Create (> the doctor checkbox should be checked)

Thank you in advance

Best regards!

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

you should set it's default value to True, then the checkbbox will appear selected in new object

อวตาร
ละทิ้ง
ผู้เขียน

Hello Temur, I want it to set doctor = True only if I create a new partner from my new menuitem action.

ok then. in such case you can set default value for doctor field using function. my answer is still valid in this conditions.

you can implement function that assigns default value as follows:

def compute_default_value_of_doctor(self):
    return self.env.context.get('doctor_default', False)

in your action set 'doctor_default' in context....

of course you've to add

default=compute_default_value_of_doctor
to your "Doctor" fields definition.
ผู้เขียน

Works great! Thank you!

ผู้เขียน คำตอบที่ดีที่สุด

This solution worked as Temur said at the comments: 

def compute_default_value_of_doctor(self):
return self.env.context.get('doctor_default', False)

# Fields
doctor = fields.Boolean(string='Is doctor?', default=compute_default_value_of_doctor)

For the specific action view for the doctor menuitem add this:

<field name="context">{"default_doctor": True}</field>

Update: There is no need to write the python code, just add "default_" at the context field before the name of the attribute and it will work.

Regards!

อวตาร
ละทิ้ง

upvote for the "default_" prefix ;)

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 23
2323
Server actions in menuItem แก้ไขแล้ว
2
ก.ย. 23
5692
Set Domain during Create method แก้ไขแล้ว
1
ก.ค. 20
3852
naked domain set up แก้ไขแล้ว
3
ก.ค. 25
4110
0
พ.ค. 25
801