Call function inside other function odoo
<p>I want call function 2 inside function 1.</p>

<p>Function 2 need parameter (num2 and num3), after call in source I don't get any error but nothing happened aslo.</p>

<pre><code>def function_1(self, cr, uid, ids, num1, num2, num3, context=None):
        res = {}
        if num1:
            res['sum'] = num1 + num2
            return {'value': res}
        self.function_2(cr, uid, ids, num2, num3, context)


    def function_2(self, cr, uid, ids, num2,num3, context=None):
        res = {}
        if num2:
            res['sum2'] = num2 + num3
            return {'value': res}
</code></pre>

<p>What is problem here or any other solution?</p>

<p>You don't need <code>self</code> in <code>function_2</code> and you also need the <code>return</code> keyword, because after <code>function_2</code> evaluates and returns it's value to the caller which is <code>function_1</code>, <code>function_1</code> also has to return that result to it's caller. if you don't add a return statement <code>function_1</code> would end up returning <code>None</code> to it's caller.</p>

<pre><code>def function_1(self, cr, uid, ids, num1, num2, num3, context=None):
    # i'll place the function definition at the top (personal preference)
    def function_2(cr, uid, ids, num2,num3, context=None):
        res = {}
        if num2:
            res['sum2'] = num2 + num3
            return {'value': res}

    res = {}
    if num1:
        res['sum'] = num1 + num2
        return {'value': res}

    return function_2(cr, uid, ids, num2, num3, context=context)
</code></pre>

<p>Personally i don't see the need to have a nested function. i would have written it like this.</p>

<pre><code>def function_1(self, cr, uid, ids, num1, num2, num3, context=None):
    res = {}
    if num1:
        res['sum'] = num1 + num2
        return {'value': res}

    elif num2:
        res['sum2'] = num2 + num3
        return {'value': res}

    else:
        pass # return some default value here
</code></pre>

python openerp odoo-8 odoo-9