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

I override the name field in product.template to be computed so I need to search by name about the product

this is The Error from Log

raise ValueError("Invalid leaf %s" % str(self.leaf))
ValueError: Invalid leaf (False, 'ilike', 'تيل')
class autopart(models.Model):
_inherit = 'product.template'

@api.multi
@api.depends('item', 'car', 'model', 'dsc', 'drc', 'year', 'org')
def compute_amount(self):
    for rec in self:
        rec.name = " ".join(
            [rec.item and rec.item.name or "", rec.car and rec.car.name or "", rec.model and rec.model.name or "",
             rec.dsc and rec.dsc.name or "", rec.drc and rec.drc.name or "", rec.org and rec.org.name or "",
             rec.year and rec.year.name or ""])

def pro_searach(self, operator, value):

    if operator == 'like':
        operator = 'ilike'
        name = self.env['product.template'].search([('name', operator, value)], limit=None)
    return [(self.name, operator, value)]
name = fields.Char(string="Name", required=False ,compute=compute_amount,search=pro_searach)
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

The issue is with the field you passed in the domain in pro_search method in return statement.

return [('name', operator, value)]  #  [(self.name, operator, value)] it should not be self.name but should be a field
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Modified code:

name = fields.Char(string="Name", required=False,compute=compute_amount,search=pro_searach,store=True)

Reference: https://old.reddit.com/r/learnopenerp/

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

You need make this field as stored. Only stored computed field are searchables. Go to ORM documentation and locate computed field \here 

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
7
พ.ย. 19
7837
1
พ.ค. 23
2339
1
ก.พ. 21
3846
1
ธ.ค. 19
5449
Computed field not updating in form view แก้ไขแล้ว
3
พ.ค. 23
17235