Добавить товар 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)])
1 ответ
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
а также к методу:
self.search([('ean13', 'ilike', name)])
Вы также можете написать так
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