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

class A(models.Model):

b_ids = fields.One2many('a', a_id);

@api.onchange('b_ids')

def set_all_other_value_to_false(self):

    for b_id in self:

        b_id.boolean_flag = False

        #how can I set all other value to false, except the last one which I selected to True?

class B(models.Model):

boolean_flag = fields.Boolean(default=False)

a_id = fields.Many2One('a')


I don't know how I can set all boolean_flag to False except the last one which I selected. How can I solve that problem?

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

"self.b_ids.ids" to get list
use sql to select this list
compare "boolean_flag" in db and in self.b_ids.boolean_flag

Try:

update value via self.env

https://www.odoo.com/forum/help-1/question/odoo-8-how-to-update-value-of-one2many-field-with-at-second-level-by-using-create-and-write-method-using-api-104615

Or

Override write method

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

it does not work with sql, because it can be that it is not saved in the database (create modus).

คำตอบที่ดีที่สุด

In onchange Odoo creates a new object and replaces self with it. The origin object  can be found under self._origin
Check if this is useful?


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

how does this solve this problem? can you give a example?

the view should be updated immediately.

Does the b_ids.ids change? Only change b_ids.boolean_flag? Do you want to check the last click?

ผู้เขียน

yes, I want to know to last click. and I want to set the last boolean_flag to True and the rest records of False.

This is impossible in the general case, when all records b_ids are not stored in database. Only solutions is to modify javascript.

ผู้เขียน

Thanks. I hope there will be a solution.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มิ.ย. 18
5208
1
ม.ค. 22
18758
0
ก.ย. 20
3066
3
ก.ค. 19
5603
0
เม.ย. 16
3324