我可以选择记录,但无法在自定义的Many2One字段中搜索

时间:2019-02-05 13:21:57

标签: python odoo-11

我并不是很擅长编码,但是我正在尽力了解基础知识。我在odoo11中有一个自定义字段,用于目的地端口(这是城市和国家/地区的组合):

PY:

destination = fields.Many2one('destination.location', string="Destination")

class DestinationLocation(models.Model):

    _name = 'destination.location'

    place = fields.Char(string="Place Name", required=True)

    country_id = fields.Many2one('res.country', string='Country', required=True)

    @api.multi

    @api.depends('place', 'country_id')

def name_get(self):

    result = []

    for x in self:

        name = x.place + ', ' + x.country_id.code

        result.append((x.id, name))

    return result

我在销售订单/报价XML中使用它:

<xpath expr="//form/sheet/group/group/field[@name='partner_id']" position="after">

      <field name="destination"/>

</xpath>

当我尝试在“目标”字段中键入时-建议不起作用。如果我输入名称,则该名称已经存在-在我进一步搜索之前,我不会手动建议使用它。而且,但是,即使在“搜索更多”窗口中,搜索也不起作用。它使用ID而不是城市名称进行查找。

任何帮助表示赞赏。

我试图添加api模型,但是我打破了销售模块:

@api.model

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

    args = args or []

    domain_name = ['|', '|', ('name', 'ilike', name), ('place', 'ilike', name), ('country_id', 'ilike', name)]

    recs = self.search(domain_name + args, limit=limit)

    return recs.name_get()

但是出现此错误:

Traceback (most recent call last):

File "/opt/odoo/odoo/tools/cache.py", line 84, in lookup

r = d[key]

File "/opt/odoo/odoo/tools/func.py", line 68, in wrapper

return func(self, *args, **kwargs)

File "/opt/odoo/odoo/tools/lru.py", line 44, in __getitem__

a = self.d[obj].me

KeyError: ('ir.actions.actions', <function IrActions.get_bindings at 0x7f1fcd4a0510>, frozenset({1, 3, 4, 5, 6, 7, 8, 13, 16, 19, 20, 21, 22, 23, 24, 28, 29, 33, 35, 36, 37, 38, 39, 44, 45, 49, 50}), 'sale.order')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/opt/odoo/odoo/fields.py", line 937, in __get__

value = record.env.cache.get(record, self)

File "/opt/odoo/odoo/api.py", line 960, in get

value = self._data[field][record.id][key]

KeyError: <odoo.api.Environment object at 0x7f1fae91e240>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/opt/odoo/odoo/http.py", line 651, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/opt/odoo/odoo/http.py", line 310, in _handle_exception

raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])

File "/opt/odoo/odoo/tools/pycompat.py", line 87, in reraise

raise value

File "/opt/odoo/odoo/http.py", line 693, in dispatch

result = self._call_function(**self.params)

File "/opt/odoo/odoo/http.py", line 342, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/opt/odoo/odoo/service/model.py", line 97, in wrapper

return f(dbname, *args, **kwargs)

File "/opt/odoo/odoo/http.py", line 335, in checked_call

result = self.endpoint(*a, **kw)

File "/opt/odoo/odoo/http.py", line 937, in __call__

return self.method(*args, **kw)

File "/opt/odoo/odoo/http.py", line 515, in response_wrap

response = f(*args, **kw)

File "/opt/odoo/addons/web/controllers/main.py", line 934, in call_kw

return self._call_kw(model, method, args, kwargs)

File "/opt/odoo/addons/web/controllers/main.py", line 926, in _call_kw

return call_kw(request.env[model], method, args, kwargs)

File "/opt/odoo/odoo/api.py", line 687, in call_kw

return call_kw_model(method, model, args, kwargs)

File "/opt/odoo/odoo/api.py", line 672, in call_kw_model

result = method(recs, *args, **kwargs)

File "/opt/odoo/odoo/models.py", line 1296, in load_views

for [v_id, v_type] in views

File "/opt/odoo/odoo/models.py", line 1296, in <dictcomp>

for [v_id, v_type] in views

File "/opt/odoo/addons/mail/models/mail_thread.py", line 374, in fields_view_get

res = super(MailThread, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)

File "/opt/odoo/odoo/models.py", line 1388, in fields_view_get

bindings = self.env['ir.actions.actions'].get_bindings(self._name)

File "<decorator-gen-27>", line 2, in get_bindings

File "/opt/odoo/odoo/tools/cache.py", line 89, in lookup

value = d[key] = self.method(*args, **kwargs)

File "/opt/odoo/odoo/addons/base/ir/ir_actions.py", line 120, in get_bindings

result[binding_type].append(action.read()[0])

File "/opt/odoo/odoo/addons/base/ir/ir_actions.py", line 207, in read

result = super(IrActionsActWindow, self).read(fields, load=load)

File "/opt/odoo/odoo/models.py", line 2604, in read

data[record][name] = convert(record[name], record, use_name_get)

File "/opt/odoo/odoo/models.py", line 4761, in __getitem__

return self._fields[key].__get__(self, type(self))

File "/opt/odoo/odoo/fields.py", line 941, in __get__

self.determine_value(record)

File "/opt/odoo/odoo/fields.py", line 1052, in determine_value

self.compute_value(recs)

File "/opt/odoo/odoo/fields.py", line 1008, in compute_value

self._compute_value(records)

File "/opt/odoo/odoo/fields.py", line 999, in _compute_value

getattr(records, self.compute)()

File "/opt/odoo/odoo/addons/base/ir/ir_actions.py", line 167, in _compute_search_view

fvg = self.env[act.res_model].fields_view_get(act.search_view_id.id, 'search')

File "/opt/odoo/odoo/api.py", line 760, in __getitem__

return self.registry[model_name]._browse((), self)

File "/opt/odoo/odoo/modules/registry.py", line 179, in __getitem__

return self.models[model_name]

KeyError: 'vendor.selector'

0 个答案:

没有答案