2017-02-22 29 views
0

我正在使用SoapPY從第三方服務中恢復數據,並將其保存在字典結構中。所收集的數據具有二維結構,與銷售訂單結構(標題行)類似。 我在填寫一些關鍵值後點擊自定義按鈕時會這樣做。我禁用了創建和保存按鈕,因爲我想要一個不同的表單行爲。我只需要獲取數據並手動將其保存在相應的表格(標題和行)中。我不希望自定義按鈕自動執行創建方法,因爲默認情況下,任何按鈕都會執行該方法。 任何消氣,請?Odoo 8及以上。自動創建並保存,無需創建和保存按鈕

def custom_button(self): 

    # Get the info from third party using SOAPPy 
    WSDLFile = "http://www.expedientes.poderjudicial.gub.uy/wsConsultaIUE.php?wsdl" 
    proxy = WSDL.Proxy(WSDLFile) 
    UIE = str(self.int_sede) + '-' + str(self.int_nro_registro) + '/' + str(self.int_ano) 
    soap_exp = proxy.consultaIUE(UIE) 

    # Set variables 
    str_origen = soap_exp[1] 
    str_caratula = soap_exp[3] 
    str_abogado_actor = soap_exp[4] 
    str_abogado_demandado = soap_exp[5] 
    movimientos = soap_exp[6] 

    mov_exp = [] 
    for mov in movimientos: 
     mov_exp.append ((0, 0, {'str_sede': mov['sede'], 
          'date_venc': mov['vencimiento'], 
          'str_decreto': mov['decreto'], 
          'date_mov': mov['fecha'], 
          'str_movimiento': mov['tipo']})) 

    expediente = {'int_sede': self.int_sede, 'int_nro_registro': self.int_nro_registro, 'int_ano': self.int_ano, 
        'str_origen': str_origen, 
        'str_caratula': str_caratula, 
        'str_abogado_actor': str_abogado_actor, 
        'str_abogado_demandado': str_abogado_demandado, 
        'movimiento_ids': mov_exp 
       } 

    return write(expediente) 

enter image description here

+0

每個Odoo/openerp模型都有一個'create'方法你嘗試過嗎?事實上,你正在避免的按鈕實際上調用了相同的'create'方法 – danidee

+0

我從表格中取下了按鈕,但我沒有想要自定義按鈕自己創建。我想用手做。 – jack10bells

+0

是的,我明白,也許如果你顯示一些代碼,我們可以更好地理解你,並幫助你 – danidee

回答

0

如果你想避免Odoo的ORM然後就繼續使用SQL。通過創建和保存記錄,我們的意思是相同的東西。寫入方法在已經創建的記錄集上運行。我看到:

return write(expediente)

這是什麼?你在某個地方定義了一個可調用的write?您是否正在導入寫入方法?寫方法通常調用像self.write({'my_field':its_value})其中自是recordset

所以,在你的按鈕,你可以在點擊:

1)使用self.create({field1:value1, field2:value2, ...})

2)使用self.env.cr.execute(r"insert raw sql here")創建表中的記錄你想要的(也就是說,如果你不想實際使用Odoo的ORM

相關問題