Odoo Help


GTK client field onchange updates parent field

Hussein Kamel
on 4/2/14, 10:26 AM 1,430 views

I have been searching for a solution to my problem more than 2 weeks. I am customizing the sale order form, my problem is simply as following In the sale order line's tree, defined online inside the sale order form, when i change the quantity field value, I need to update a field in the parent form which is the sale order form.

In the onchange function, in the sale order line model, I tried to write the line res['parent.total_order_amount'] = total_order_amount , unfortunately it did not update parent form value.

The customized sale order model.

class ext_sale_order_with_separate_products(osv.osv):
_name = "ext.sale.order.with.separate_products"
_table = "ext_sale_order_with_separate_products"
_inherits = {'sale.order': 'base_order_id'}
_columns = {
    'base_order_id': fields.many2one('sale.order', 'Sale Order', required=True, ondelete="cascade"),
    'total_order_amount': fields.float('Total Amount', readonly=True),
    'light_order_line_ids': fields.one2many('ext.sale.order.line.light', 'order_id', 'Light Order Lines'),


The customized sale order line model

class ext_sale_order_line_light(osv.osv):
_logger = logging.getLogger("ext_sale")
_name = 'ext.sale.order.line.light'
_description = 'Sales Order Line'

_columns = {
    'order_id': fields.many2one('ext.sale.order.with.separate_products', 'Order'),
    'product_id': fields.many2one('product.product', 'Product'),
    'product_quantity': fields.float('Quantity'),

def onchange_product_quantity(self, cr, uid, ids, order_id, light_order_lines, context=None):
    res = {}
    product_pool = self.pool.get('product.product')
    if not light_order_lines:
        return res
    total_order_amount = 0
    for light_order_line in light_order_lines:
        light_order_line = light_order_line[2]
        if not light_order_line or not light_order_line['product_quantity'] or not light_order_line['product_id']:

        product_price = product_pool.read(cr, uid, light_order_line['product_id'], ['list_price'])['list_price']
        total_order_amount += light_order_line['product_quantity'] * product_price

    res['total_order_amount'] = total_order_amount
    return {'value':res}


The view is as the following

        <record id="view_order_form_separate_products" model="ir.ui.view">
        <field name="name">sale.order.form.separate_products</field>
        <field name="model">ext.sale.order.with.separate_products</field>
        <field name="type">form</field>
        <field name="priority">10</field>
        <field name="arch" type="xml">
            <form string="Sales Order">
                <notebook colspan="4">
                    <page string="Sales Order">
                        <group colspan="4" col="12" attrs="{'invisible':[('state','not in',('draft','ready_to_confirm'))]}">
                            <group colspan="4">
                                <separator colspan="4" string="Sales Order Lines"/>
                                <field colspan="4" name="light_order_line_ids" nolabel="1" widget="one2many_list" 
                                    attrs="{'readonly':[('state','not in',('draft','ready_to_confirm'))]}" height="350" options='{"quick_create": false}'>
                                    <tree string="Sales Order Lines" editable="bottom">
                                        <field name="product_id" width="200"/>
                                        <field name="product_quantity" string="Quantity" on_change="onchange_product_quantity(parent.id,parent.light_order_line_ids)"/>
                                    <form string="Sales Order Line">
                                        <field name="product_id"/>
                                        <field name="product_quantity" string="Quantity" />
                        <newline />
                        <group col="13" colspan="10">
                            <field name="total_order_amount"/>

On 4/24/15, 5:27 AM

This is what I want to know also.

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.


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

0 follower(s)


Asked: 4/2/14, 10:26 AM
Seen: 1430 times
Last updated: 4/24/15, 5:27 AM