Unbound methods

Asked by Jose Loureiro on 2013-11-05

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

def _verifica_contabilizado(self, cr, uid, ids,context=None):
        lista_orcs=self.browse(cr,uid,ids)
        db_orc_linhas=self.pool.get('sncp.orcamento.linha')

        for orc in lista_orcs:
            if orc.tipo_orc=='mod':
                linhas_ids=db_orc_linhas.search(cr,uid,[('orcamento_id','=',orc.id)])
                orc_linhas_lista=db_orc_linhas.browse(cr,uid,linhas_ids)
                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)+'/'
                                                   +str(orclinha.funcional_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?
Thanks,
José

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Alexandre Fayolle - camptocamp
Solved:
2013-11-06
Last query:
2013-11-06
Last reply:
2013-11-06

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

Thanks. it solve my problem. :)