Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
6009 มุมมอง

Hi Guys

I Got Error (TypeError: 'int' object is not iterable)

My Code : (python :) def on_change_emp(self,cr,uid,ids,emp_id,context=None): vs = cr.execute('SELECT wage FROM hr_contract WHERE (id=%s)',(tuple(emp_id))).fetchone() if vs is not None: raise osv.except_osv((vs[0]),('Employee Wage')) else: pass

(XML :) <field name="emp_id" attrs="{'invisible':[('item_emp','!=',True)]}" on_change="on_change_emp(emp_id)"/>

อวตาร
ละทิ้ง

Hello Ali, you also have passed wrong "id" value in query. You are passing employee id in query and matching with contract "id". It will give wrong wage value too.

คำตอบที่ดีที่สุด

Use below code to get wage: In PYTHON file:

_columns = {
    'name': fields.many2one('hr.employee', "Employee", required=True),
    'wage_amt': fields.float('Wage', digits=(16,2), required=True, help="Basic Salary of the employee"),
}

def onchange_employee_id(self, cr, uid, ids, employee_id, context=None):
    v = {}
    if employee_id:
        contract_sr = self.pool.get('hr.contract').search(cr, uid, [('employee_id','=',employee_id)], context=context)
        if contract_sr:
                contract_br = self.pool.get('hr.contract').browse(cr, uid, contract_sr, context=context)[0]
                v['wage_amt'] = contract_br.wage

    return {'value': v}

In XML file:

<field name="name" on_change="onchange_employee_id(name)"/>
<field name="wage_amt"/>
อวตาร
ละทิ้ง
ผู้เขียน

Thanks a Lot It's Working My Friend

คำตอบที่ดีที่สุด

Hello Ali,

I guess problem is in your query.

Try this:

cr.execute('SELECT wage FROM hr_contract WHERE id in %s', (tuple(emp_id),))
cr.fetchone()

Thanks,

Serpent Consulting Services.

อวตาร
ละทิ้ง
ผู้เขียน

thanks for answer my friend but still give me that (TypeError: 'int' object is not iterable )

Did you try it after restart the server?

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
พ.ค. 24
1756
0
ส.ค. 24
2043
1
มี.ค. 23
2566
0
มี.ค. 15
5380
0
มี.ค. 25
1584