python - 在报价行项目搜索中添加产品 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)])
解决方案
该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
您只需要将ean13
as well 的结果添加到方法中:
self.search([('ean13', 'ilike', name)])
推荐阅读
- c# - 操纵 Linq 表达式,因为我希望它们具有魔力
- python - 如何从行中检索想要的字符串
- python - PyPi 在版本名称的开头和结尾添加破折号“-”
- reactjs - React 应用 SSL 错误:EVP_DecryptFinal_ex 错误解密
- javascript - 在 Apple 上使用 Acrobat Javascript 打开 pdf
- ios - 创建时位于关键窗口之外的 iOS TableView 单元格不会触发 didSelect
- c# - LINQ 不会使用 EF Core 对组产生 COUNT() 查询
- angular - 什么是 RxJS 中的订阅以及 Observables 如何与它们交互?
- android - 到 Python 服务器的 Android 套接字连接
- oracle - insert all and inner join in oracle