Unbound methods

Asked by Jose Loureiro

i have this method in a class called 'orcamento':

def _verifica_contabilizado(self, cr, uid, ids,context=None):

        for orc in lista_orcs:
            if orc.tipo_orc=='mod':
                for orclinha in orc_linhas_lista:
                    if orclinha.anulacao>0.0:
                       if not sncp_orcamento_acumulados.verifica_abate(cr,uid,orclinha.orcamento_id.ano,orclinha.organica_id,orclinha.economica_id,orclinha.funcional_id,orclinha.anulacao):
                            raise osv.except_osv(_(u'Para a combinação '+str(orclinha.organica_id.code)+'/'+str(orclinha.economica_id.code)+'/'
                                                _(u'o abate de '+str(orclinha.anulacao)+u' não é possível')
return True

in if statement i call function verifica_abate() from class sncp_orcamento_acumulados with the following definition:
verifica_abate(self, cr, uid, ids,ano,organica_id,economica_id,funcional_id,anulacao):
This function i call it with the database that corresponds to the sncp_orcamento_acumulados empty.

I have this error:
unbound method verifica_abate() must be called with sncp_orcamento_acumulados instance as first argument (got Cursor instance instead).
How can i create this instance to pass as argument of method verifica_abate()?

What i am doing wrong?
Can you help me?

Question information

English Edit question
Odoo Addons (MOVED TO GITHUB) Edit question
No assignee Edit question
Solved by:
Alexandre Fayolle - camptocamp
Last query:
Last reply:
Revision history for this message
Best Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) said :

verifica_abate is not a function, it is a class method. You need to call it from an instance of the sncp_orcamento_acumulados model.

This would give something like the following, assuming that sncp_orcamento_acumulados is an OpenERP Model (deriving from osv.osv or orm.Model):

add this at the begining of _verifica_contabilizado:

    sncp_orcament_acumulatos_obj = self.poo|['sncp.orcamento.acumulatos']

replace "sncp_orcamento_acumulados" with "sncp_orcamento_acumulados_obj" in the test

Revision history for this message
Jose Loureiro (miguel-loureiro) said :

Thanks. it solve my problem. :)