Skip to content Skip to sidebar Skip to footer

How To Pass Value With Onchange One2many Variable In Odoo?

Solution 1:

No need to write onchange attribute in view file. With new API, we can directly achieve onchange functionality with @api.onchange('field_name')

We can pass context in one2many field and get that value with self._context.get('context_key_name')

Try with following:

<field name="salary_month"/>
<field name="earning_type_id" context="{'salary_month': salary_month}">
    <tree editable="bottom">
        <field name="earnings_type" />
        <field name="based_on"  on_change="calc_amount(based_on)" />
        <field name="amount" />
        <field name="total" />
    </tree>
</field>


@api.onchange('based_on')
def onchange_calc_amount(self):

    context = self._context

    if context.has_key('salary_month'):

        print self.based_on
        print context.get('salary_month')

Post a Comment for "How To Pass Value With Onchange One2many Variable In Odoo?"