feat(api): 通过 barcode convert 功能,在添加产品时,通过关联 barcode 一次性添加多件产品
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
2e646054ff
commit
f265d3144f
13
app.py
13
app.py
@ -194,8 +194,17 @@ def add():
|
|||||||
barcode = data.get("barcode", "")
|
barcode = data.get("barcode", "")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
grocy.product_by_barcode(barcode)
|
product = grocy.product_by_barcode(barcode)
|
||||||
grocy.add_product_by_barcode(barcode, 1.0, 0.0)
|
barcode_ = None
|
||||||
|
amount = 1.0
|
||||||
|
if product:
|
||||||
|
for product_barcode in product.product_barcodes:
|
||||||
|
if product_barcode.barcode == barcode:
|
||||||
|
barcode_ = product_barcode.barcode
|
||||||
|
break
|
||||||
|
if barcode_:
|
||||||
|
amount = barcode_.amount
|
||||||
|
grocy.add_product_by_barcode(barcode, amount, 0.0)
|
||||||
|
|
||||||
response_data = {"message": "Item added successfully"}
|
response_data = {"message": "Item added successfully"}
|
||||||
return jsonify(response_data), 200
|
return jsonify(response_data), 200
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user