Odoo Help

1

how to call function inside another function

By
mihir shah
on 5/3/13, 4:23 AM 9,740 views

def confirmation(self, cr, uid, ids, context={}): ir_model_data = self.pool.get('ir.model.data')
return {

                'type': 'ir.actions.act_window',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'die.approval',
                        }


def action_confirm_draft(self, cr, uid, ids, context={}):
            if confirmation(self, cr, uid, ids, context={}) == True: 
                self.write(cr, uid, ids, {'state': 'sample','approved_by':uid})
                return True
            else:
                    return False

i am trying to call confirmation function in action_confirm_draft() , but is ven i call the action_confirm_draft function it gives me( NameError: global name 'confirmation' is not defined) error

5

ClueLogics Technologies Pvt. Ltd.

--ClueLogics Technologies Pvt. Ltd.--
6143
| 6 5 8
Delhi NCR, India
--ClueLogics Technologies Pvt. Ltd.--

 ClueLogics Technologies Pvt Ltd is a Software product and services provider. We are positioned to deliver robust, rapid and reliable Information Technology solutions that work. What we succeed upon is Technology and Technical Expertise. The industry review of ClueLogics has been commendable for the past years as most of its business comes from repeat orders by highly satisfied clients.

ClueLogics Technologies Pvt. Ltd.
On 5/6/13, 4:50 AM

hello mihir

Use "self" to call function if both functions inside same class (model)

if calling functions of another class (model) then use self.pool.get("model.name").calling_func(cr,uid,.........)

self property of python not of openep

that's it

1

Naresh Soni (nch)

--Naresh Soni (nch)--
--Naresh Soni (nch)--

Team Lead, Odoo(Formerly OpenERP) Support & OPW

Naresh Soni (nch)
On 5/3/13, 7:16 AM

Hello Mihir,

Do this:

def action_confirm_draft(self, cr, uid, ids, context={}):
        if self.confirmation(cr, uid, ids, context): 
            return self.write(cr, uid, ids, {'state': 'sample','approved_by':uid})
        return False

Thanks,

Hello Naresh if i am using the following it is throwing this error (TypeError: confirmation() got multiple values for keyword argument 'context' )

mihir shah
on 5/4/13, 4:24 AM

sorry my mistake I updated the syntax

Naresh Soni (nch)
on 5/6/13, 4:30 AM
0

Vale Trood

--Vale Trood--

1165
| 5 2 7
Tunis, France
--Vale Trood--


Vale Trood
On 8/13/15, 5:19 AM

The easiest example is of the on_change function. Here i give you an example of a call to a function.


def on_change_state_id(self, cr, uid, ids,state, project, credit, context=None): 

if state==1:

project_id = _get_project_id_by_name (self,cr, uid, project, context)

res = {'value':{'service_ids': self.get_inputs(cr, uid, ids, state, project,context=context),

}

}  

return res

else:

return False

---------------------------------------------------


def get_inputs(self, cr, uid,ids, state, project, context=None):

ret = [] 

project_id = _get_project_id_by_name (self,cr, uid, project, context

obj = self.pool.get('tes.project.service')

obj_ids = obj.search(cr, uid, [], context=context)

res = obj.read(cr, uid, obj_ids, ['id', 'int_service','ext_service','unit_service','int_service_unit','ext_service_unit','service_type','service_condition'], context)

for r in res :

inputs = {

'project_id' : project_id,

'int_services': r['int_service'],

'ext_services': r['ext_service'],

'unit_services': r['unit_service'],

'int_services_unit': r['int_service_unit'],

'ext_services_unit': r['ext_service_unit'],

'service_type': r['service_type'],

'service_condition' : r['service_condition'],

}

ret.append(inputs)

print ('------------liste de services-------')

print ret

return ret


Try simpler case like this:

def func2(msg):
    return 'result of func2("' + func1(msg) + '")'

def func1(msg):
    return 'result of func1("' + msg + '")'

print func1('test')
print func2('test')


It prints:

result of func1("test")
result of func2("result of func1("test")")

Notice the order of function definitions is intentionally reversed. The order of function definitions does not matter in Python.

Regards.


0
jamesbale
On 5/3/13, 4:39 AM

to call a function from function it is simple, what are you doing a bit surprise me

def confirmation(self, cr, uid, ids, context={}):


def action_confirm_draft(self, cr, uid, ids, context={}):
    self.confirmation(cr, uid, ids, context)

what if i want to check the function self.confirmation(cr, uid, ids, context) is true or fales , den wat is the syntax

mihir shah
on 5/3/13, 4:51 AM

then your function shloud return True or False , and check like this if confirmation(cr, uid, ids, context): thats it...

jamesbale
on 5/3/13, 6:44 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 5/3/13, 4:23 AM
Seen: 9740 times
Last updated: 8/13/15, 5:19 AM