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.

1

AttributeError: 'float' object has no attribute 'get' [Closed]

By
priyankahdp
on 3/13/13, 7:47 AM 2,851 views

The Question has been closed

by
priyankahdp
on 04/18/2013 07:33:35

here is my error

2013-03-13 10:31:50,358 11345 ERROR OpenERP_DB openerp.osv.osv: Uncaught exception
Traceback (most recent call last):
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/orm.py", line 4479, in create
    self.pool.get(object)._store_set_values(cr, user, ids, fields2, context)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/orm.py", line 4627, in _store_set_values
    result = self._columns[f].get(cr, self, ids, f, SUPERUSER_ID, context=context)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/fields.py", line 1137, in get
    elif result.get(id):
AttributeError: 'float' object has no attribute 'get'
2013-03-13 10:31:50,363 11345 ERROR OpenERP_DB openerp.netsvc: 'float' object has no attribute 'get'
Traceback (most recent call last):
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/netsvc.py", line 293, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/service/web_services.py", line 618, in dispatch
    res = fn(db, uid, *params)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/osv.py", line 188, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/orm.py", line 4479, in create
    self.pool.get(object)._store_set_values(cr, user, ids, fields2, context)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/orm.py", line 4627, in _store_set_values
    result = self._columns[f].get(cr, self, ids, f, SUPERUSER_ID, context=context)
  File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/osv/fields.py", line 1137, in get
    elif result.get(id):
AttributeError: 'float' object has no attribute 'get'
2013-03-13 10:31:50,369 11345 INFO OpenERP_DB werkzeug: 127.0.0.1 - - [13/Mar/2013 10:31:50] "POST /web/dataset/call_kw HTTP/1.1" 200 -

and here is my module source code

class namelistupdate(osv.osv):

    def _invoiced_rate(self, cr, uid, ids, name, args, context):
        amount_untaxed = 1
        if amount_untaxed == 0:
            res = 100.0
        else:
            res = 50.0
        print (res)
        return res

    _name = "checkroll.namelist.update"
    _description = "This table is for keeping Name list updates"
    _columns = {        
        'date': fields.date("Date"),
        'value': fields.function(_invoiced_rate, method=True, type='float', string='Test', store=True),
    }

namelistupdate()

i checked in backend table also.they correctly created and fileds also correctly manipulated.please check this and inform me whats the issue

here shows my view.xml file

    <record model="ir.ui.view" id="namelist_update_form">
        <field name="name">Name List Update</field>
        <field name="model">checkroll.namelist.update</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="namelist_update">
                <field name="date" />
                <field name="value" />
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="namelist_update_list">
        <field name="name">Name List Update</field>
        <field name="model">checkroll.namelist.update</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="namelist_update">
                <field name="value" />
            </tree>
        </field>
    </record>

    <record model="ir.actions.act_window" id="action_namelist_update">
        <field name="name">Name List Update</field>
        <field name="res_model">checkroll.namelist.update</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>
6

Parth Gajjar

--Parth Gajjar--
1484
| 3 3 5
Ahmadabad, India
--Parth Gajjar--
Parth Gajjar
On 3/13/13, 8:04 AM

You need to return result in the form of dictionary object. and key should be id of that record.

Just replace your function

example

def _invoiced_rate(self, cr, uid, ids, name, args, context):
    amount_untaxed = 1
    record_id=ids[0]
    res={record_id: 0.0}
    if amount_untaxed == 0:
        res[record_id] = 100.0
    else:
        res[record_id] = 50.0
    print (res)
    return res

thanks for yours earliest reply.i defined 'res' variable. its not related with any other parts.wrote this code because need to get idea about need to check "how is the function fields work."

so is it possible write function without adding parameters (like my code)?

priyankahdp
on 3/13/13, 8:15 AM

function field need dictionary object which has a current records id as key. In function you must need to pass such dictionary.In your code another possibility is like this

return { ids[0] : res } // change only last line

Parth Gajjar
on 3/13/13, 8:25 AM

This will also work because function field needs only dictionary has a current records id as key.

def _invoiced_rate(self, cr, uid, ids, name, args, context):\n return { ids[0] : 50.0 } // change only last line

Parth Gajjar
on 3/13/13, 8:29 AM

thanks u soooooooooo much Mr.Parth Gajjar you saved my day... :-)

now its perfectly working..and need to know furthur about dictionary object also

priyankahdp
on 3/13/13, 8:30 AM

Go to this link , this will provide all type of python objects including dictionaries. http://docs.python.org/2/tutorial/datastructures.html#dictionaries

Parth Gajjar
on 3/13/13, 8:32 AM

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/13/13, 7:47 AM
Seen: 2851 times
Last updated: 3/16/15, 8:10 AM