简体   繁体   English

Odoo模块-调用其他模型的方法

[英]Odoo Module - calling a method of another model

I am trying to call the wkf_confirm_order method of the purchase order model. 我正在尝试调用采购订单模型的wkf_confirm_order方法。

In my code, I use the line: 在我的代码中,使用以下行:

po.wkf_confirm_order( self, cr, uid, [po.id] )

I get the following stack trace, and don't understand the issue with the parameters. 我得到以下堆栈跟踪,并且不了解参数的问题。 Some help would be most appreciated. 一些帮助将不胜感激。

File "/etc/odoo/addons/asn_import/asn_model.py", line 60, in do_import_file

po.wkf_confirm_order( self, cr, uid, [po.id] )

File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 254, in wrapper

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

File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 580, in new_api

result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)
TypeError: wkf_confirm_order takes at most 5 arguments (9 given)

The po object was created with the following command (values hardcoded for now): po对象是使用以下命令创建的(当前值已硬编码):

 po = self.env['purchase.order'].create(cr, uid, {'partner_id':name_asc[0],'location_id':12,'pricelist_id':2})

self shouldn't be given as a parameter when you call a method. 调用方法时,不应将self作为参数提供。 The only parameters you need are cr, uid, ids (in this case [po.id]) and context (if not provided it will be None) 您唯一需要的参数是cr,uid,id(在这种情况下为[po.id])和上下文(如果未提供,则为None)。

self will be automatically parsed to the method by Odoo Odoo将自动将self解析为该方法

This code should work: 此代码应工作:

po.wkf_confirm_order(cr, uid, [po.id] )

Make sure po.id is a purchase order record id. 确保po.id是采购订单记录ID。

Replace your code 替换您的代码

po.wkf_confirm_order( self, cr, uid, [po.id] )

with

po.wkf_confirm_order(cr, uid, [po.id], context=context)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM