2016-08-09 25 views
1

我想調用一個方法,每次我的模塊安裝或更新。在該方法內部,我想循環低谷模型記錄,但我只得到不同的錯誤。Odoo - 不能循環槽模型記錄

本文檔看起來非常簡單:https://www.odoo.com/documentation/9.0/reference/orm.html

但它不爲我工作。我得到這個錯誤:

ParseError: "'account.tax' object has no attribute '_ids'" while parsing

這是我如何調用該方法:

<openerp> 
    <data> 
     <function model="account.tax" name="_my_method" /> 
    </data> 
</openerp> 

我把這個從第一個答案在這裏:https://www.odoo.com/forum/help-1/question/how-can-i-execute-a-sql-statement-on-module-update-and-installation-6131

我的模型:

class my_account_tax(models.Model): 
    _name = 'account.tax' 
    _inherit = 'account.tax' 

    def _my_method(self, cr, uid, ids=None, context=None): 
     self.do_operation() 

    def do_operation(self): 
     print self 
     for record in self: 
      print record 

它基本上是從文檔複製粘貼。我只加方法的參數CR,UID,..如果我把他們帶走(和剛剛離開「自我」),錯誤有一點不同:

ParseError: "_my_method() takes exactly 1 argument (3 given)"

但也沒有告訴太多。 :(

回答

2

使用新的API

@api.multi #if you use the new api you don't have to list all parameter in the function 
def _my_method(self): 

,但你可以把它像做一個池您的手機型號超過環路扔你得到,如果你使用新的API不使用自 結果使用:self.env['model_name'].search([domain])

+0

nope。如果我嘗試「records = self.env ['account.tax']。search([()])」我得到另一個愚蠢的錯誤:「ParseError:''account.tax'object has沒有屬性'env'「 – user568021

+0

也我把@ api.multi以上兩個我的方法我得到這個:」ParseError:「old_api()需要至少4個參數(3給出)」 – user568021

+0

比你必須使用o ld api給方法5個參數並使用池而不是搜索,因爲當你不使用@api裝飾器時,self.env []。search不起作用 – Cherif