我想添加一个下拉项,允许我将所选项目从我的模块添加到清单中的产品列表。
我遵循了此威胁https://www.odoo.com/fr_FR/forum/aide-1/question/call-function-from-the-more-dropdown-list-61330并添加了此代码:
<record id="dditem1_action" model="ir.actions.server">
<field name="name">Add to inventory</field>
<field name="model_id" ref="model_sync2ba_products"/>
<field name="state">code</field>
<field name="condition">True</field>
<field name="code">if object: self.browse(cr,uid,context.get('active_ids', [])).your_function()</field>
</record>
<record id="dditem1" model="ir.values">
<field name="name">brand</field>
<field name="model">sync2ba.products</field>
<field name="key" >action</field>
<field name="key2">client_action_multi</field>
<field name="value" eval="'ir.actions.server,%d'%dditem1_action"/>
</record>
和
_name = 'sync2ba.products'
_rec_name = 'ProductId'
Brand = fields.Char(string="Brand")
..... OTHER FIELDS
@api.multi
def your_function(self):
for item in self:
# do something with selected records
print 'Hello'
我得到了他的错误:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/http.py", line 640, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/http.py", line 677, in dispatch
result = self._call_function(**self.params)
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/http.py", line 333, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/service/model.py", line 101, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/http.py", line 326, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/http.py", line 935, in __call__
return self.method(*args, **kw)
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/http.py", line 506, in response_wrap
response = f(*args, **kw)
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/addons/web/controllers/main.py", line 1161, in run
result = request.env['ir.actions.server'].browse([action_id]).run()
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/addons/base/ir/ir_actions.py", line 974, in run
res = func(action, eval_context=eval_context)
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/addons/website/models/ir_actions.py", line 58, in run_action_code_multi
res = super(ServerAction, self).run_action_code_multi(action, eval_context)
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/addons/base/ir/ir_actions.py", line 795, in run_action_code_multi
safe_eval(action.code.strip(), eval_context, mode="exec", nocopy=True) # nocopy allows to return 'action'
File "/usr/local/lib/python2.7/dist-packages/odoo-10.0+e.20170828-py2.7.egg/odoo/tools/safe_eval.py", line 301, in safe_eval
return unsafe_eval(c, globals_dict, locals_dict)
File "", line 1, in <module>
ValueError: <type 'exceptions.NameError'>: "name 'self' is not defined" while evaluating
u"if object: self.browse(cr,uid,context.get('active_ids', [])).your_function()"
非常感谢。
答案 0 :(得分:0)
我认为第一个问题是XML中的字段code
。
我看到,它适用于Odoo 9,但可能不适用于Odoo 10.你可以尝试一下:
<field name="code">
if context.get('active_model') == 'sync2ba.products' and context.get('active_ids'):
if object:
env['sync2ba.products'].with_context(context).browse(context.get('active_ids', [])).your_function()
</field>
self
并不存在于Odoo 10