首页 > 解决方案 > 在报价行项目搜索中添加产品 ean13 条形码 (Odoo 8)

问题描述

我想知道如何继续在销售报价中按条形码(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)])

标签: pythonpython-2.7odoo-8odooean-13

解决方案


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)])

推荐阅读