Odoo Help

Welcome!

This community 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.

0

How to set a column default value to the value of another column in the same model

By
Jesse Rye
on 10/27/16, 5:17 PM 86 views

I'm trying to get a field "planned_qty" to the same value as "product_qty" when its created but I'm not having any luck. I thought all I needed to do was define the field like below and default = product_qty. But alas its not that easy. Can someone advise?

planned_qty = fields.Float( 'Planned Quantity', digits = dp.get_precision( 'Product Unit of Measure' ) )
1
Ameera PP
On 10/28/16, 3:00 AM

1) create fields like:

'product_qty': fields.float(string='Product Qty'),

'planned_qty': fields.float(string='Planned Quantity'),

2)define in xml

<field name="planned_qty" on_change="onchange_planned_qty(planned_qty)"/>
<field name="product_qty" on_change="onchange_product_qty(product_qty)"/>

3) call onchange function

def onchange_product_qty(self, cr, uid, ids, product_qty, context=None):
        if product_qty:
            return {'value': {''planned_qty': product_qty}}  

      else:
            return {'value':{''planned_qty': ''}}


    def onchange_'planned_qty(self, cr, uid, ids, 'planned_qty, context=None):
        if planned_qty:
            return {'value': {'product_qty': planned_qty}} 

       else:
            return {'value': {'product_qty': ''}}


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/27/16, 5:17 PM
Seen: 86 times
Last updated: 10/28/16, 3:00 AM