Update business case form with currency symbol and improved functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
andrei
2025-10-01 06:37:47 +00:00
parent 2f569ae683
commit d2ff24b6da
4 changed files with 60 additions and 6 deletions

View File

@@ -5,17 +5,17 @@
"company_name": "gfdgdf",
"email": "gfdgf",
"phone": "gfdgfdg",
"store_name": "test222",
"store_name": "test1232",
"country": "gfdgfd",
"starting_date": "2025-09-25",
"duration": 36,
"store_types": [
"Convenience"
],
"currency_symbol": "$",
"currency_symbol": "",
"convenience_store_type": {
"stores_number": 1233,
"monthly_transactions": 32131312,
"monthly_transactions": 3211312,
"has_digital_screens": true,
"screen_count": 2,
"screen_percentage": 123123,

View File

@@ -1571,7 +1571,7 @@
</div>
<div>
<label for="${id}-screen-percentage" class="block text-base font-medium text-gray-700 mb-1">Number of stores with digital screens</label>
<input type="number" id="${id}-screen-percentage" name="${id}_screen_percentage" min="0" max="100"
<input type="number" id="${id}-screen-percentage" name="${id}_screen_percentage" min="0"
class="w-full p-3 border border-gray-300 bg-white rounded-md focus:outline-none focus:ring-1 focus:ring-[#eb742e] focus:border-[#eb742e]">
</div>
</div>
@@ -1597,7 +1597,7 @@
<div id="${id}-radio-questions" class="space-y-4 hidden">
<div>
<label for="${id}-radio-percentage" class="block text-base font-medium text-gray-700 mb-1">Number of stores with radio</label>
<input type="number" id="${id}-radio-percentage" name="${id}_radio_percentage" min="0" max="100"
<input type="number" id="${id}-radio-percentage" name="${id}_radio_percentage" min="0"
class="w-full p-3 border border-gray-300 bg-white rounded-md focus:outline-none focus:ring-1 focus:ring-[#eb742e] focus:border-[#eb742e]">
</div>
</div>

View File

@@ -3,7 +3,59 @@ import json
import os
import re
import openpyxl
from openpyxl.utils import get_column_letter
CURRENCY_LOCALE_MAP = {
'$': '-409', # English (US)
'': '-2', # English (Euro)
}
CURRENCY_BRACKET_PATTERN = re.compile(r'\[\$([^\]-]*)(-[^\]]*)?\]')
def apply_currency_symbol(workbook, symbol):
"""Propagate the selected currency symbol across formats, labels, and charts."""
target_symbol = (symbol or '$').strip() or '$'
def replace_currency_token(fmt):
if not isinstance(fmt, str) or ('$' not in fmt and '' not in fmt):
return fmt
def _replace_match(match):
locale_hint = match.group(2) or ''
if target_symbol in CURRENCY_LOCALE_MAP:
locale_hint = f"-{CURRENCY_LOCALE_MAP[target_symbol].lstrip('-')}" if match.group(2) or locale_hint else ''
return f'[${target_symbol}{locale_hint}]'
updated = CURRENCY_BRACKET_PATTERN.sub(_replace_match, fmt)
updated = updated.replace('"$"', f'"{target_symbol}"')
return updated
for worksheet in workbook.worksheets:
for row in worksheet.iter_rows():
for cell in row:
fmt = cell.number_format
updated_format = replace_currency_token(fmt)
if updated_format != fmt:
cell.number_format = updated_format
value = cell.value
if isinstance(value, str) and not value.startswith('=') and ('' in value or '$' in value):
new_value = value.replace('', target_symbol).replace('$', target_symbol)
if new_value != value:
cell.value = new_value
for chart in getattr(worksheet, '_charts', []):
axes = [getattr(chart, 'y_axis', None), getattr(chart, 'secondary_y_axis', None)]
for axis in axes:
if not axis or not getattr(axis, 'number_format', None):
continue
fmt_obj = axis.number_format
format_code = getattr(fmt_obj, 'formatCode', None)
if not isinstance(format_code, str):
continue
updated_code = replace_currency_token(format_code)
if updated_code != format_code:
fmt_obj.formatCode = updated_code
def update_excel_variables(excel_path):
"""
@@ -153,6 +205,8 @@ def update_excel_variables(excel_path):
except Exception as e:
print(f"Error updating cell {cell_ref}: {e}")
apply_currency_symbol(wb, user_data.get('currency_symbol', ''))
# Force formula recalculation before saving
print("Forcing formula recalculation...")
wb.calculation.calcMode = 'auto'