Kgshop commited on
Commit
fba6dda
·
verified ·
1 Parent(s): 4076fc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -15
app.py CHANGED
@@ -941,7 +941,7 @@ CATALOG_TEMPLATE = '''
941
  <div class="product-price-container">
942
  {% set discount = product.get('discount_percent', 0) %}
943
  {% set original_price_kgs = product.price_kgs %}
944
- {% if app_config.prices_enabled %}
945
  {% if discount > 0 %}
946
  {% set discounted_price_kgs = original_price_kgs * (100 - discount) / 100 %}
947
  <span class="original-price">{{ "%.2f"|format(original_price_kgs) }} {{ currency_code }}</span><br>
@@ -1540,7 +1540,7 @@ PRODUCT_DETAIL_TEMPLATE = '''
1540
 
1541
  {% set discount = product_info.get('discount_percent', 0) %}
1542
  {% set original_price_kgs = product_info.price_kgs %}
1543
- {% if app_config.prices_enabled %}
1544
  <div style="margin: 20px 0; padding: 15px; background: var(--bg-steel-mid); border-radius: 8px;">
1545
  <strong style="font-size: 1.1rem; color: var(--text-light);">{{ get_translation('price') }}</strong>
1546
  {% if discount > 0 %}
@@ -2677,17 +2677,20 @@ def admin_api():
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
2692
 
2693
  description = request.form.get('description', '').strip()
@@ -2766,19 +2769,24 @@ def admin_api():
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
 
2782
 
2783
  product_to_edit['description'] = request.form.get('description', product_to_edit.get('description', '')).strip()
2784
  product_to_edit['subcategory_id'] = request.form.get('subcategory_id') or None
 
941
  <div class="product-price-container">
942
  {% set discount = product.get('discount_percent', 0) %}
943
  {% set original_price_kgs = product.price_kgs %}
944
+ {% if app_config.prices_enabled and original_price_kgs > 0 %}
945
  {% if discount > 0 %}
946
  {% set discounted_price_kgs = original_price_kgs * (100 - discount) / 100 %}
947
  <span class="original-price">{{ "%.2f"|format(original_price_kgs) }} {{ currency_code }}</span><br>
 
1540
 
1541
  {% set discount = product_info.get('discount_percent', 0) %}
1542
  {% set original_price_kgs = product_info.price_kgs %}
1543
+ {% if app_config.prices_enabled and original_price_kgs > 0 %}
1544
  <div style="margin: 20px 0; padding: 15px; background: var(--bg-steel-mid); border-radius: 8px;">
1545
  <strong style="font-size: 1.1rem; color: var(--text-light);">{{ get_translation('price') }}</strong>
1546
  {% if discount > 0 %}
 
2677
  return jsonify({'error': get_translation('flash_product_name_price_required')}), 400
2678
 
2679
  price_kgs_str = request.form.get('price_kgs', '').replace(',', '.')
2680
+ if not price_kgs_str:
2681
+ price_kgs = 0.0
2682
+ else:
2683
+ try:
2684
+ price_kgs = round(float(price_kgs_str), 2)
2685
+ if price_kgs < 0: price_kgs = 0.0
2686
+ except ValueError:
2687
+ return jsonify({'error': get_translation('flash_invalid_price_format')}), 400
2688
 
2689
  discount_percent_str = request.form.get('discount_percent', '0')
2690
  try:
2691
  discount_percent = int(discount_percent_str)
2692
  if not (0 <= discount_percent <= 100): discount_percent = 0
2693
+ except (ValueError, TypeError):
2694
  discount_percent = 0
2695
 
2696
  description = request.form.get('description', '').strip()
 
2769
 
2770
  product_to_edit['name'] = request.form.get('name', product_to_edit['name']).strip()
2771
 
2772
+ price_kgs_str = request.form.get('price_kgs', '').replace(',', '.')
2773
+ if not price_kgs_str:
2774
+ product_to_edit['price_kgs'] = 0.0
2775
+ else:
2776
+ try:
2777
+ price_kgs = round(float(price_kgs_str), 2)
2778
+ if price_kgs < 0: price_kgs = 0.0
2779
+ product_to_edit['price_kgs'] = price_kgs
2780
+ except ValueError:
2781
+ pass
2782
 
2783
  discount_percent_str = request.form.get('discount_percent', str(product_to_edit.get('discount_percent',0)))
2784
  try:
2785
  discount_percent = int(discount_percent_str)
2786
  if not (0 <= discount_percent <= 100): discount_percent = product_to_edit.get('discount_percent', 0)
2787
  product_to_edit['discount_percent'] = discount_percent
2788
+ except (ValueError, TypeError):
2789
+ pass
2790
 
2791
  product_to_edit['description'] = request.form.get('description', product_to_edit.get('description', '')).strip()
2792
  product_to_edit['subcategory_id'] = request.form.get('subcategory_id') or None