コンテンツへスキップ
メニュー
この質問にフラグが付けられました
8 返信
30812 ビュー

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

アバター
破棄
最善の回答

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

アバター
破棄
最善の回答

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' )

sorry my mistake I updated the syntax

最善の回答

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.


アバター
破棄
最善の回答

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

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