小编典典

TypeError:只能将元组(不是'nt')连接到元组

sql

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

@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

阅读 143

收藏
2021-04-14

共1个答案

小编典典

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

@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}
2021-04-14