Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2673,18 +2673,19 @@ def admin_api():
|
|
| 2673 |
try:
|
| 2674 |
if action == 'add_product':
|
| 2675 |
name = request.form.get('name', '').strip()
|
| 2676 |
-
price_kgs_str = request.form.get('price_kgs', '').replace(',', '.')
|
| 2677 |
if not name:
|
| 2678 |
return jsonify({'error': get_translation('flash_product_name_price_required')}), 400
|
|
|
|
|
|
|
| 2679 |
try:
|
| 2680 |
-
price_kgs = round(float(price_kgs_str), 2)
|
| 2681 |
if price_kgs < 0: price_kgs = 0.0
|
| 2682 |
-
except ValueError:
|
| 2683 |
-
|
| 2684 |
|
| 2685 |
discount_percent_str = request.form.get('discount_percent', '0')
|
| 2686 |
try:
|
| 2687 |
-
discount_percent = int(discount_percent_str)
|
| 2688 |
if not (0 <= discount_percent <= 100): discount_percent = 0
|
| 2689 |
except ValueError:
|
| 2690 |
discount_percent = 0
|
|
@@ -2765,19 +2766,16 @@ def admin_api():
|
|
| 2765 |
|
| 2766 |
product_to_edit['name'] = request.form.get('name', product_to_edit['name']).strip()
|
| 2767 |
|
| 2768 |
-
price_kgs_str = request.form.get('price_kgs')
|
| 2769 |
-
|
| 2770 |
-
|
| 2771 |
-
|
| 2772 |
-
|
| 2773 |
-
|
| 2774 |
-
product_to_edit['price_kgs'] = 0.0
|
| 2775 |
-
except ValueError:
|
| 2776 |
-
pass
|
| 2777 |
|
| 2778 |
discount_percent_str = request.form.get('discount_percent', str(product_to_edit.get('discount_percent',0)))
|
| 2779 |
try:
|
| 2780 |
-
discount_percent = int(discount_percent_str)
|
| 2781 |
if not (0 <= discount_percent <= 100): discount_percent = product_to_edit.get('discount_percent', 0)
|
| 2782 |
product_to_edit['discount_percent'] = discount_percent
|
| 2783 |
except ValueError: pass
|
|
|
|
| 2673 |
try:
|
| 2674 |
if action == 'add_product':
|
| 2675 |
name = request.form.get('name', '').strip()
|
|
|
|
| 2676 |
if not name:
|
| 2677 |
return jsonify({'error': get_translation('flash_product_name_price_required')}), 400
|
| 2678 |
+
|
| 2679 |
+
price_kgs_str = request.form.get('price_kgs', '').replace(',', '.')
|
| 2680 |
try:
|
| 2681 |
+
price_kgs = round(float(price_kgs_str), 2)
|
| 2682 |
if price_kgs < 0: price_kgs = 0.0
|
| 2683 |
+
except (ValueError, TypeError):
|
| 2684 |
+
price_kgs = 0.0
|
| 2685 |
|
| 2686 |
discount_percent_str = request.form.get('discount_percent', '0')
|
| 2687 |
try:
|
| 2688 |
+
discount_percent = int(discount_percent_str)
|
| 2689 |
if not (0 <= discount_percent <= 100): discount_percent = 0
|
| 2690 |
except ValueError:
|
| 2691 |
discount_percent = 0
|
|
|
|
| 2766 |
|
| 2767 |
product_to_edit['name'] = request.form.get('name', product_to_edit['name']).strip()
|
| 2768 |
|
| 2769 |
+
price_kgs_str = request.form.get('price_kgs', str(product_to_edit.get('price_kgs',0.0))).replace(',', '.')
|
| 2770 |
+
try:
|
| 2771 |
+
price_kgs = round(float(price_kgs_str), 2)
|
| 2772 |
+
if price_kgs < 0: price_kgs = 0.0
|
| 2773 |
+
product_to_edit['price_kgs'] = price_kgs
|
| 2774 |
+
except (ValueError, TypeError): pass
|
|
|
|
|
|
|
|
|
|
| 2775 |
|
| 2776 |
discount_percent_str = request.form.get('discount_percent', str(product_to_edit.get('discount_percent',0)))
|
| 2777 |
try:
|
| 2778 |
+
discount_percent = int(discount_percent_str)
|
| 2779 |
if not (0 <= discount_percent <= 100): discount_percent = product_to_edit.get('discount_percent', 0)
|
| 2780 |
product_to_edit['discount_percent'] = discount_percent
|
| 2781 |
except ValueError: pass
|