Добавить товар ean13 штрих-код в поиске позиции цитаты (Odoo 8) - PullRequest
0 голосов
/ 10 мая 2018

Я хочу знать, как приступить к добавлению в поиск товара по штрих-коду (ean 13) в коммерческих предложениях. Как и изображение здесь, у меня есть только название продукта и внутренняя ссылка продукта.

screenshot

Я пытаюсь переопределить модель 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 Ответ

0 голосов
/ 10 мая 2018

Метод 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)])
...