On change

Asked by Jennifer

Hi

I want to replace an on_change function onchange_price to onchange_amt in an xml file. So what i did I wrote another xml file and replace from

<field name="line_dr_ids" on_change="onchange_price(line_dr_ids, tax_id, partner_id)"
                                 default_get="{'journal_id':journal_id,'partner_id':partner_id,'type':type}"
                                 colspan="4" nolabel="1" height="180">
                                <tree string="Payment Lines" editable="bottom">
                                    <field name="move_line_id" context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
                                        on_change="onchange_move_line_id(move_line_id)"
                                        domain="[('account_id.type','=','payable'), ('reconcile_id','=', False), ('partner_id','=',parent.partner_id)]"
                                        />
                                    <!-- check can be used for any payment - should account type be expense ? -/ -->
                                    <field name="account_id" widget="selection" domain="[('type','=','payable')]"/>
                                    <field name="name"/>
                                    <field name="date_original" readonly="1"/>
                                    <field name="date_due" readonly="1"/>
                                    <field name="amount_original" readonly="1"/>
                                    <field name="amount_unreconciled" sum="Open Balance" readonly="1"/>
                                    <field name="amount" sum="Payment"/>
                                </tree>
                            </field>

To this

<field name ="line_dr_ids" on_change="onchange_price(line_dr_ids, tax_id, partner_id)" default_get="{'journal_id':journal_id,'partner_id':partner_id,'type':type}" colspan="4" nolabel="1" height="180" position="replace">
     <field name="line_dr_ids" on_change="onchange_amt(line_dr_ids, tax_id, partner_id)" default_get="{'journal_id':journal_id,'partner_id':partner_id,'type':type}" colspan="4" nolabel="1" height="180"/>
    </field>

But it is not working. same code if i replace in the original one it works fine. Any guess where I am wrong.
Kind regards

Jennifer

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Ana Juaristi Olalde
Solved:
Last query:
Last reply:
Revision history for this message
Ferdinand (office-chricar) said :
#1

did you inherit from the original view ?

Revision history for this message
Ana Juaristi Olalde (ajuaristio) said :
#2

Hi Jennifer:

If you want to replace a field in a form you have to inherit the "father"
form and then use xpath on inherited form to replace the field that you
wanna change.

You can find xpath use cases on several openerp modules. You can also take a
look on technical memento where it is explained.
Wishing this helps:

Ana

2011/3/31 Jennifer <email address hidden>

> New question #151164 on OpenERP Addons:
> https://answers.launchpad.net/openobject-addons/+question/151164
>
> Hi
>
> I want to replace an on_change function onchange_price to onchange_amt in
> an xml file. So what i did I wrote another xml file and replace from
>
> <field name="line_dr_ids" on_change="onchange_price(line_dr_ids, tax_id,
> partner_id)"
>
> default_get="{'journal_id':journal_id,'partner_id':partner_id,'type':type}"
> colspan="4" nolabel="1" height="180">
> <tree string="Payment Lines"
> editable="bottom">
> <field name="move_line_id"
> context="{'journal_id':parent.journal_id, 'partner_id':parent.partner_id}"
>
> on_change="onchange_move_line_id(move_line_id)"
>
> domain="[('account_id.type','=','payable'), ('reconcile_id','=', False),
> ('partner_id','=',parent.partner_id)]"
> />
> <!-- check can be used for any payment -
> should account type be expense ? -/ -->
> <field name="account_id"
> widget="selection" domain="[('type','=','payable')]"/>
> <field name="name"/>
> <field name="date_original"
> readonly="1"/>
> <field name="date_due" readonly="1"/>
> <field name="amount_original"
> readonly="1"/>
> <field name="amount_unreconciled"
> sum="Open Balance" readonly="1"/>
> <field name="amount" sum="Payment"/>
> </tree>
> </field>
>
> To this
>
> <field name ="line_dr_ids" on_change="onchange_price(line_dr_ids, tax_id,
> partner_id)"
> default_get="{'journal_id':journal_id,'partner_id':partner_id,'type':type}"
> colspan="4" nolabel="1" height="180" position="replace">
> <field name="line_dr_ids"
> on_change="onchange_amt(line_dr_ids, tax_id, partner_id)"
> default_get="{'journal_id':journal_id,'partner_id':partner_id,'type':type}"
> colspan="4" nolabel="1" height="180"/>
> </field>
>
>
>
> But it is not working. same code if i replace in the original one it works
> fine. Any guess where I am wrong.
> Kind regards
>
> Jennifer
>
> You received this question notification because you are a member of
> OpenERP Committers, which is an answer contact for OpenERP Addons.
>

--
Ana Juaristi Olalde
Avanzosc, S.L.
Partner OpenERP
www.anajuaristi.com
www.openerpsite.com
www.avanzosc.com
Skype: avanzosc
677 93 42 59 - 943 02 69 02

Revision history for this message
Jennifer (dazzlingirl-n) said :
#3

Hi
Find below complete set of code :

<record model="ir.ui.view" id="view_payment_write_check_form">
            <field name="name">hmo.account.voucher.payment.write.check.form</field>
            <field name="model">account.voucher</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
    <field name ="line_dr_ids" on_change="onchange_price(line_dr_ids, tax_id, partner_id)" default_get="{'journal_id':journal_id,'partner_id':partner_id,'type':type}" colspan="4" nolabel="1" height="180" position="replace">
     <field name="line_dr_ids" on_change="onchange_amt(line_dr_ids, tax_id, partner_id)" default_get="{'journal_id':journal_id,'partner_id':partner_id,'type':type}" colspan="4" nolabel="1" height="180"/>
    </field>
            </field>
        </record>

Revision history for this message
Jennifer (dazzlingirl-n) said :
#4

Hi

Can we use the xpath when we want to replace a function i.e using Position=Replace

Revision history for this message
Best Ana Juaristi Olalde (ajuaristio) said :
#5

Yes. You are replacing full field configuration, this is you are replacing
the onchange function associated to the field.

If you need mantaining the "father" form field onchange function
functionality you should use super function call on onchange function
definition called from your inherited field.

2011/3/31 Jennifer <email address hidden>

> Question #151164 on OpenERP Addons changed:
> https://answers.launchpad.net/openobject-addons/+question/151164
>
> Jennifer posted a new comment:
> Hi
>
> Can we use the xpath when we want to replace a function i.e using
> Position=Replace
>
> --
> You received this question notification because you are a member of
> OpenERP Committers, which is an answer contact for OpenERP Addons.
>

--
Ana Juaristi Olalde
Avanzosc, S.L.
Partner OpenERP
www.anajuaristi.com
www.openerpsite.com
www.avanzosc.com
Skype: avanzosc
677 93 42 59 - 943 02 69 02

Revision history for this message
Jennifer (dazzlingirl-n) said :
#6

Thanks Ana Juaristi Olalde, that solved my question.