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

Hello guys.

I have a compute field and then I would like to put a search for this field in a view.

I found the documentation in odoov13 that looks  possible :

upper_name = field.Char(compute='_compute_upper', search='_search_upper')

def _search_upper(self, operator, value):
    if operator == 'like':
        operator = 'ilike'
    return [('name', operator, value)]



Then I tried to apply on my code :

sub_state = fields.Char(compute='_get_substate', search='_search_sub_state')



def _get_substate(self):
for batch in self:
batch.sub_state = 'wait'

@api.model
def _search_sub_state(self, operator, operand):
return [('name', operator, operand)]


However I can see in the screen the custom filter with the sub_state but when I put a value there it is  returning nothing.

Do you would know what is missing on my code?

Thank you so much
    

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

Hi,

Try to follow steps like in the below blog.

https://www.cybrosys.com/blog/how-to-add-a-search-filter-for-computed-fields-in-odoo-15

Regards

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

Hello, 
Remove the @api.model above the _search_sub_state method.



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

is your computed field stored? If it's not stored, the value only exists in the view, and not in the database where Odoo is searching.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มิ.ย. 25
15277
3
เม.ย. 25
5399
1
พ.ย. 24
1176
Compute Fields แก้ไขแล้ว
2
ก.ค. 24
2300
0
ก.พ. 24
28