(cr,uid,frozendict(context)TypeError:'float'对象不可迭代

时间:2016-08-10 14:06:45

标签: python typeerror

我正在尝试使用odoo中的onchange方法更新字段。

我的.py代码是

class hr_contract(osv.osv):
_name = 'hr.contract'
_description = 'Contract'


def _wage(self, cr, uid, ids,context=None):
        res = {}
        pay_slip = 0
        pay_slip1 = 0

        for obj in self.browse(cr, uid, ids, context=context):
            s1 = ("""select schedule_pay from hr_contract where employee_id=%s""" % (obj.employee_id.id))
            cr.execute(s1)
            l1 = cr.fetchone()
            value10 = l1[0]
            if value10 == 'bi-weekly':
                s4 = (
                    """select salary from hr_contract where employee_id=%s """ % (
                        obj.employee_id.id))
                cr.execute(s4)
                l4 = cr.fetchone()
                salary = l4[0]
                # **************************************************************#
                ######### Week1  #############
                s5 = ("""select week1 from hr_contract where employee_id=%s """ % (
                    obj.employee_id.id))
                cr.execute(s5)
                l5 = cr.fetchone()
                week1 = l5[0]
                print "week1", week1
                if week1 != None:
                    if week1 > 48.00:
                        weeked1 = week1 - 48.00
                        total_amt = salary * (weeked1 * 1.5)
                        total_pay = 48.00 * salary
                        pay_slip = total_amt + total_pay
                        pay_slip1 += pay_slip
                        print "payslip..", pay_slip
                        cr.execute(""" update hr_contract set week1=%s where employee_id=%s""" % (
                            week1, obj.employee_id.id))
                    else:
                        pay_slip = week1 * salary
                        pay_slip1 += pay_slip
                        print "payslip..", pay_slip1

我更改字段并保存时显示错误

File "/home/rck/Desktop/odoo/openerp/api.py", line 769, in __new__
    self.cr, self.uid, self.context = self.args = (cr, uid, frozendict(context))
TypeError: 'float' object is not iterable

如果我从for循环中删除 context ,则会获取计算的先前值。

我该如何解决这个问题?

我使用xml中的onchange调用该函数

<field name="week1" on_change="_wage(week1)"/>

该字段在py

中设置为float
 'wage': fields.float('Per Hour Wages'),
 'week1': fields.float('Week 1'),

1 个答案:

答案 0 :(得分:0)

这是TypeError: 'float' object is not iterable"的意思: -

count=7,然后for i in count:表示for i in 7:,这将无效。 in之后的位应该是可迭代类型,而不是数字。试试这个:

for i in range(count):

如评论中所述,隔离了您的问题以获得更清晰的答案。