0

我想知道如何继续在销售报价中按条形码(ean 13)搜索产品。就像这里的图片,我只有产品名称和产品内部参考。

截屏

我尝试像这样覆盖模型 product.product :

# -*- coding: utf-8 -*-

from openerp import models, api

class product_product(models.model):

_inherit = "product.product"

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

res = super(product_product, self).name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100)

if operator in ('ilike', 'like', '=', '=like', '=ilike'):

domain = [('ean13', operator, name)]

ids = self.search(cr, user, domain, limit=limit, context=context)

res += self.name_get(cr, user, ids, context=context)

return res

self.search([('ean13', 'ilike', name)])
4

2 回答 2

0

name_get方法更改出现在下拉列表中的默认名称。

name_search而是覆盖该方法,如下所示:

@api.model
def name_search(self, name='', args=None, operator='ilike', limit=100):
    # Make a search with default criteria
    temp = super(models.Model, self).name_search(
        name=name, args=args, operator=operator, limit=limit)
    # Make the other search
    temp += super(ProductProduct, self).name_search(
        name=name, args=args, operator=operator, limit=limit)
    # Merge both results
    res = []
    keys = []
    for val in temp:
        if val[0] not in keys:
            res.append(val)
            keys.append(val[0])
            if len(res) >= limit:
                break
    return res

您只需要将ean13as well 的结果添加到方法中:

self.search([('ean13', 'ilike', name)])
于 2018-05-10T15:45:41.493 回答
0

你也可以这样写

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

    res = super(product_product, self).name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100)

    if operator in ('ilike', 'like', '=', '=like', '=ilike'):

        domain = [('ean13', operator, name)]

        ids = self.search(cr, user, domain, limit=limit, context=context)
        res+=self.browse(ids).name_get()
        return res
    
于 2020-08-05T12:06:43.910 回答