2017-03-05 70 views
1

我只想知道,如何將某些函數轉換爲新的API,或者是否需要完全轉換它們,具體取決於我們使用的API調用。Odoo v10 API vs Odoo v8 API

例如,

@api.model 

the method is exposed as not using ids, its recordset will generally be empty. Its "old API" signature is cr, uid, *arguments, context: 
@api.model 
def some_method(self, a_value): 
    pass 
# can be called as 
old_style_model.some_method(cr, uid, a_value, context=context) 

在Odoo V8,假設我有這樣的功能:

def update_info(self, cr, uid, ids, context=None): 
    """ OpenERP osv memory wizard : update_info_partner 
    """ 
    context = context or {} 
    seniat_url_obj = self.env('seniat.url') 
    self.cr.execute('''SELECT id FROM res_partner WHERE vat ilike 'VE%';''') 
    record = self.cr.fetchall() 
    pids = [item[0] for item in record] 
    seniat_url_obj.connect_seniat(cr, uid, pids, context=context, 
            all_rif=True) 
    return{} 

如果我添加@api.model裝飾這個功能,我想我還需要更新它的屬性,即:self, cr, uid, ids, context=None,對吧?

在這種情況下,添加@api.model裝飾器,然後將函數屬性更改爲只有self就足夠了?

我只是試圖得到如何解決這個問題,從現在開始,因爲我將一些模塊從v8鏡像到v10。

回答

1

正如你自己

寫的方法公開不使用IDS,它記錄通常是空的。

api.model更多的是靜態方法的東西,在odoo ORM上下文中。對於python本身,它不是一個靜態方法。如果您使用記錄(數據庫記錄作爲python對象),請使用api.multiapi.one。如果根本沒有記錄,例如ORM create(),請使用api.model

將舊方法「翻譯」爲新API可被認爲非常簡單,僅適用於該主題。如果在方法參數中看到idsid<model>_id(s),則可能是api.multiapi.one。如果你沒有em:api.model。例外是計算,onchange和約束方法。