Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
7 Trả lời
7824 Lượt xem

i want to use name_search in product to get product by search the lot name which in stock.production.lot

class ProductProduct(models.Model):
_inherit = 'product.product'

@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):

args = args or []
print('arg ',args)
            recs = self.search([('lot_name', operator, name)]  args, limit=limit) #stock_quant_ids.lot_id.name
print('recs ', recs)
if not recs.ids:
return super(ProductProduct, self).name_search(name=name, args=args,
operator=operator,
limit=limit)
return recs.name_get()


Ảnh đại diện
Huỷ bỏ

When should you use name_search method: https://goo.gl/7PHhPP

Tác giả Câu trả lời hay nhất

from odoo.osv import expression

class ProductProduct(models.Model):

_inherit = 'product.product'

lot = fields.Char()

@api.model

def name_search(self, name='', args=None, operator='ilike', limit=100):

""" search for product using the Lot number """

self.lot = name

print (self.lot)

args = args or []

recs = None

# only perform search by when the name is passed

if name:

# don't use limit here

recs = self.env['stock.production.lot'].search([('barcode', operator, name)])

if recs:

# handle extra filter that was passed by the domain attribute in the XML

args = expression.AND([args, [('id', 'in', recs.mapped('product_id').ids)]])

return self.search(args, limit=limit).name_get()

# no Lot was founded may be the user meant to search by product name

return super(ProductProduct, self).name_search(name=name,

args=args,

operator=operator,

limit=limit)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Mostafa: I haven't looked at the logic but going purely by the syntax, if you put a env['stock.production.lot'] after self like so it should work.

self.env['stock.production.lot'].search([('lot_name', operator, name)]


Ảnh đại diện
Huỷ bỏ
Tác giả

raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))

ValueError: Invalid field u'type' in leaf "<osv.ExtendedLeaf: (u'type', u'=', u'product') on stock_production_lot (ctx: )>"

You typically get this error when the domain condition is not correct. Is it possible to post the section of the custom code you have written ?

Tác giả

recs = self.env['stock.production.lot'].search([('name', operator, name)] +args, limit = limit)

Check the run-time value of operator, name, args and limit when this gets executed.

Tác giả

thanks i found the solution

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 25
420
Search a message Đã xử lý
1
thg 2 25
1217
0
thg 9 23
2160
2
thg 6 23
3938
1
thg 8 22
12707