Odoo 错误 raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
Odoo error raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
我有一个 class Branch、class BranchLine、class Product 和 class TransRequest,我的想法是从一个分支发出产品的转移请求另一方面,我想做的是当用户 select 某个分支时,可用产品应该只可见 classes 如下
class CustomBranch(models.Model):
_name = 'custom.branch'
_description = 'Branch Record'
_rec_name = 'branch_name'
branch_name = fields.Char(string="Branch Name", required=False, )
branch_line = fields.One2many('custom.branch.line', 'branch_id', string='Branch Lines', )
class CustomBranchLine(models.Model):
_name = 'custom.branch.line'
_description = 'Branch Line Record'
branch_id = fields.Many2one('custom.branch', string='Branch')
product_id = fields.Many2one('custom.product', string='Product')
qty = fields.Integer(string="QTY", required=False, )
class CustomTransRequest(models.Model):
_name = 'custom.trans.request'
_description = 'Transfer Request'
branch_from_id = fields.Many2one('custom.branch', string="From")
branch_to_id = fields.Many2one('custom.branch.line', string="To")
product_ids = fields.Many2many('custom.product', string="Products")
@api.onchange('branch_from_id')
def onchange_branch_from(self):
for rec in self:
if rec.branch_from_id:
return {'domain': {'product_ids': [('branch_id', '=', rec.branch_from_id.id)]}}
但是当我 select 中的一个分支出现这个错误时
Error:
Odoo Server Error
Traceback (most recent call last):
File "/home/odoo/odoo12/odoo/odoo/http.py", line 656, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/odoo/odoo12/odoo/odoo/http.py", line 314, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/home/odoo/odoo12/odoo/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/home/odoo/odoo12/odoo/odoo/http.py", line 698, in dispatch
result = self._call_function(**self.params)
File "/home/odoo/odoo12/odoo/odoo/http.py", line 346, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/odoo/odoo12/odoo/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/home/odoo/odoo12/odoo/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "/home/odoo/odoo12/odoo/odoo/http.py", line 941, in __call__
return self.method(*args, **kw)
File "/home/odoo/odoo12/odoo/odoo/http.py", line 519, in response_wrap
response = f(*args, **kw)
File "/home/odoo/odoo12/odoo/addons/web/controllers/main.py", line 904, in search_read
return self.do_search_read(model, fields, offset, limit, domain, sort)
File "/home/odoo/odoo12/odoo/addons/web/controllers/main.py", line 926, in do_search_read
offset=offset or 0, limit=limit or False, order=sort or False)
File "/home/odoo/odoo12/odoo/odoo/models.py", line 4578, in search_read
records = self.search(domain or [], offset=offset, limit=limit, order=order)
File "/home/odoo/odoo12/odoo/odoo/models.py", line 1561, in search
res = self._search(args, offset=offset, limit=limit, order=order, count=count)
File "/home/odoo/odoo12/odoo/odoo/models.py", line 4110, in _search
query = self._where_calc(args)
File "/home/odoo/odoo12/odoo/odoo/models.py", line 3902, in _where_calc
e = expression.expression(domain, self)
File "/home/odoo/odoo12/odoo/odoo/osv/expression.py", line 672, in __init__
self.parse()
File "/home/odoo/odoo12/odoo/odoo/osv/expression.py", line 853, in parse
raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
ValueError: Invalid field 'branch_id' in leaf "<osv.ExtendedLeaf: ('branch_id', '=', 3) on custom_product (ctx: )>"
多亏了这个post
我认为它在 class 产品中寻找字段 ''branch_id',所以我添加了以下字段
branch_line = fields.One2many('custom.branch.line', 'product_id', string='Branch Lines', )
并将onchange修改为
@api.onchange('branch_from_id')
def onchange_branch_from(self):
for rec in self:
if rec.branch_from_id:
selected_lines = rec.env['custom.branch.line'].search([('branch_id', '=', rec.branch_from_id.id)])
for line in selected_lines:
return {'domain': {'product_ids': [('branch_line', '=', line.id)]}}
现在的问题是我无法检索超过 1 个产品,有人知道如何将列表发送到域吗?
我有一个 class Branch、class BranchLine、class Product 和 class TransRequest,我的想法是从一个分支发出产品的转移请求另一方面,我想做的是当用户 select 某个分支时,可用产品应该只可见 classes 如下
class CustomBranch(models.Model):
_name = 'custom.branch'
_description = 'Branch Record'
_rec_name = 'branch_name'
branch_name = fields.Char(string="Branch Name", required=False, )
branch_line = fields.One2many('custom.branch.line', 'branch_id', string='Branch Lines', )
class CustomBranchLine(models.Model):
_name = 'custom.branch.line'
_description = 'Branch Line Record'
branch_id = fields.Many2one('custom.branch', string='Branch')
product_id = fields.Many2one('custom.product', string='Product')
qty = fields.Integer(string="QTY", required=False, )
class CustomTransRequest(models.Model):
_name = 'custom.trans.request'
_description = 'Transfer Request'
branch_from_id = fields.Many2one('custom.branch', string="From")
branch_to_id = fields.Many2one('custom.branch.line', string="To")
product_ids = fields.Many2many('custom.product', string="Products")
@api.onchange('branch_from_id')
def onchange_branch_from(self):
for rec in self:
if rec.branch_from_id:
return {'domain': {'product_ids': [('branch_id', '=', rec.branch_from_id.id)]}}
但是当我 select 中的一个分支出现这个错误时
Error:
Odoo Server Error
Traceback (most recent call last):
File "/home/odoo/odoo12/odoo/odoo/http.py", line 656, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/odoo/odoo12/odoo/odoo/http.py", line 314, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/home/odoo/odoo12/odoo/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/home/odoo/odoo12/odoo/odoo/http.py", line 698, in dispatch
result = self._call_function(**self.params)
File "/home/odoo/odoo12/odoo/odoo/http.py", line 346, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/odoo/odoo12/odoo/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/home/odoo/odoo12/odoo/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "/home/odoo/odoo12/odoo/odoo/http.py", line 941, in __call__
return self.method(*args, **kw)
File "/home/odoo/odoo12/odoo/odoo/http.py", line 519, in response_wrap
response = f(*args, **kw)
File "/home/odoo/odoo12/odoo/addons/web/controllers/main.py", line 904, in search_read
return self.do_search_read(model, fields, offset, limit, domain, sort)
File "/home/odoo/odoo12/odoo/addons/web/controllers/main.py", line 926, in do_search_read
offset=offset or 0, limit=limit or False, order=sort or False)
File "/home/odoo/odoo12/odoo/odoo/models.py", line 4578, in search_read
records = self.search(domain or [], offset=offset, limit=limit, order=order)
File "/home/odoo/odoo12/odoo/odoo/models.py", line 1561, in search
res = self._search(args, offset=offset, limit=limit, order=order, count=count)
File "/home/odoo/odoo12/odoo/odoo/models.py", line 4110, in _search
query = self._where_calc(args)
File "/home/odoo/odoo12/odoo/odoo/models.py", line 3902, in _where_calc
e = expression.expression(domain, self)
File "/home/odoo/odoo12/odoo/odoo/osv/expression.py", line 672, in __init__
self.parse()
File "/home/odoo/odoo12/odoo/odoo/osv/expression.py", line 853, in parse
raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
ValueError: Invalid field 'branch_id' in leaf "<osv.ExtendedLeaf: ('branch_id', '=', 3) on custom_product (ctx: )>"
多亏了这个post
branch_line = fields.One2many('custom.branch.line', 'product_id', string='Branch Lines', )
并将onchange修改为
@api.onchange('branch_from_id')
def onchange_branch_from(self):
for rec in self:
if rec.branch_from_id:
selected_lines = rec.env['custom.branch.line'].search([('branch_id', '=', rec.branch_from_id.id)])
for line in selected_lines:
return {'domain': {'product_ids': [('branch_line', '=', line.id)]}}
现在的问题是我无法检索超过 1 个产品,有人知道如何将列表发送到域吗?