我有这样的动作:
. . .
<record id="confirm_action" model="ir.actions.server">
<field name="name">Confirm</field>
<field name="binding_model_id" ref="my_module.model_purchase_order_line"/>
<field name="model_id" ref="my_module.model_purchase_order_line"/>
<field name="state">code</field>
<field name="code">
action = records.confirm_line()
</field>
</record>
. . .
我的模型中有这个代码:
class purchase_order_line_inherit(models.Model):
_inherit = "purchase.order.line"
def confirm_line(self):
for line in self:
purchase_orders = self.env['purchase.order.line'].search(['product_id.id','=',line.product_id.id])
这是错误:
Odoo 服务器错误回溯(最近一次调用最后一次):文件“/home/odoo/odoo/odoo/addons/base/models/ir_http.py”,第 237 行,在 _dispatch 结果 = request.dispatch() 文件“/home/ odoo/odoo/odoo/http.py”,第 683 行,在调度结果中 = self._call_function(**self.params) 文件“/home/odoo/odoo/odoo/http.py”,第 359 行,在 _call_function 返回checked_call(self.db, *args, **kwargs) 文件“/home/odoo/odoo/odoo/service/model.py”,第 94 行,在包装器中返回 f(dbname, *args, **kwargs) 文件“ /home/odoo/odoo/odoo/http.py”,第 347 行,在 checked_call 结果 = self.endpoint(*a, **kw) 文件“/home/odoo/odoo/odoo/http.py”,第 912 行,通话中 return self.method(*args, **kw) File "/home/odoo/odoo/odoo/http.py", line 531, in response_wrap response = f(*args, **kw) File "/home/odoo /odoo/addons/web/controllers/main.py”,第 1733 行,运行结果 = action.run() 文件“/home/odoo/odoo/odoo/addons/base/models/ir_actions.py”,第 629 行, 在运行 res = runner(run_self, eval_context=eval_context) 文件 "/home/odoo/odoo/odoo/addons/base/models/ir_actions.py", 第 498 行, in _run_action_code_multi safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True) # nocopy 允许返回 'action' File "/home/odoo/odoo/odoo/tools/safe_eval.py", line 346, in safe_eval raise ValueError('%s: "%s" 同时评估\n%r' % (ustr(type(e)), ustr(e), expr)) 异常
上述异常是以下异常的直接原因:
回溯(最后一次调用):文件“/home/odoo/odoo/odoo/http.py”,第 639 行,在 _handle_exception return super(JsonRequest, self)._handle_exception(exception) 文件“/home/odoo/odoo/ odoo/http.py”,第 315 行,在 _handle_exception 中引发 exception.with_traceback(None) from new_cause ValueError: <class 'TypeError'>: "'int' object is not subscriptable" 同时评估 'action = records.confirm_line()'
我想要做的只是获取与我之前选择的行具有相同产品的采购订单行的数据。我做错了什么?
它给了我这条线的错误purchase_orders = self.env['purchase.order.line'].search(['product_id.id','=',line.product_id.id])
。