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

on_change function on a float field

By
aci aisha
on 3/10/15, 5:18 AM 680 views

I have a float field total_qty.

I want to change another 4 quantities when this field changes.

So i create an on_change function as follows..

in .xml,

                    <field name="total_qty" on_change="onchange_total_qty(total_qty)"/>

in .py,

        def onchange_total_qty(self,cr,uid,ids,total_qty,context=None):
        vals = {'ratio_codes': '','r38ids': '','r40ids': '','r42ids': '','r44ids': ''}
        if total_qty:
            sample2=self.pool.get('ratio').browse(cr, uid, total_qty, context=None)
            vals['ratio_codes'] = sample2.ratio_code
            vals['r38ids'] = sample2.r38 * total_qty
            vals['r40ids'] = sample2.r40 * total_qty
            vals['r42ids'] = sample2.r42 * total_qty
            vals['r44ids'] = sample2.r44 * total_qty
        return {'value' : vals } 

But when i execute the following error occured!!

       TypeError: 'float' object is not iterable

What should be the mistake?

1

Vasanth

--Vasanth--
3458
| 5 3 8
Pondicherry, India
--Vasanth--
Vasanth
On 3/10/15, 5:58 AM

H,

you can just change your code like this:

def onchange_total_qty(self,cr,uid,ids,total_qty,context=None):
        vals = {'ratio_codes': '','r38ids': '','r40ids': '','r42ids': '','r44ids': ''}
        if total_qty:
            sample2=self.pool.get('ratio').browse(cr, uid, ids, context=None)
            vals['ratio_codes'] = sample2.ratio_code
            vals['r38ids'] = sample2.r38 * total_qty
            vals['r40ids'] = sample2.r40 * total_qty
            vals['r42ids'] = sample2.r42 * total_qty
            vals['r44ids'] = sample2.r44 * total_qty
        return {'value' : vals } 

0

Temur

--Temur--
2896
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 3/10/15, 5:22 AM

sample2=self.pool.get('ratio').browse(cr, uid, total_qty, context=None) << ERROR: total_qty passed instead of ids.

Already i did like this

aci aisha
on 3/10/15, 5:35 AM

yes I see, but your question was: "What should be the mistake?" so I highlighted the mistake

Temur
on 3/10/15, 6:05 AM
0

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 3/10/15, 5:21 AM

Hi,

I think you have make something wrong as follows.

if total_qty:
            #sample2=self.pool.get('ratio').browse(cr, uid, total_qty, context=None) this is wrong.

          sample2=self.pool.get('ratio').browse(cr, uid, ids[0], context=None)
            vals['ratio_codes'] = sample2.ratio_code

In the browse method you can not pass "total_qty" in place of "ids[0]". So, just change it and make your code will running.

Whats wrong..I coded as u..Where i pass ids?

aci aisha
on 3/10/15, 5:37 AM

I have just update my answer. Please have a look on it.

Emipro Technologies Pvt. Ltd.
on 3/10/15, 6:06 AM

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: 3/10/15, 5:18 AM
Seen: 680 times
Last updated: 3/16/15, 8:10 AM