TypeError:只能将元组(不是"int")连接到元组 [英] TypeError: can only concatenate tuple (not "int") to tuple

查看:40
本文介绍了TypeError:只能将元组(不是"int")连接到元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从db返回值并收到此错误.我在这里尝试了先前回答的问题,但是没有运气.有人可以帮助我吗?

i am trying to return a value from db and getting this error.I tried the previously answered questions here,but no luck.Can anyone help me?

@frappe.whitelist()
def generate_barcode():

    last_barcode = frappe.db.sql("""\
        select MAX(barcode) from `tabItem` """)

    if last_barcode:
        last_barcode = last_barcode + 1

    else:
        x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
        random.shuffle(x)
        last_barcode = x[0]



    return {'last_barcode':last_barcode}

添加回溯:

Traceback (innermost last):
File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/app.py", line 49, in   application
response = frappe.handler.handle()
File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/handler.py", line 66, in handle
execute_cmd(cmd)
File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/handler.py", line 89, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File "/home/adminuser/frappe-bench-hitech/apps/frappe/frappe/__init__.py", line 531, in   call
return fn(*args, **newargs)
File "/home/adminuser/frappe-bench-hitech/apps/erpnext/erpnext/stock/doctype/item/item.py", line 405, in generate_barcode
last_barcode = last_barcode + 1
TypeError: can only concatenate tuple (not "int") to tuple

推荐答案

我以某种方式得到了答案.感谢大家的帮助.

I somehow got the answer.Thanks for everyone's help.

@frappe.whitelist()
def generate_barcode():

last_barcode_auto = frappe.db.sql("""\
    select MAX(barcode) from `tabItem` """)

if last_barcode_auto[0][0] :
    last_barcode = last_barcode_auto[0][0]
    final_barcode= last_barcode+1

else:
    final_barcode=random.randrange(100001, 100000000000, 2)



return {'final_barcode':final_barcode}

这篇关于TypeError:只能将元组(不是"int")连接到元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆