FIX: Добавлен баланс кошелька клиента в модальное окно продажи POS

Проблема:
- Баланс кошелька клиента не отображался в модальном окне при нажатии "ПРОДАТЬ"
- Данные о балансе не передавались из backend в frontend

Исправления:

1. pos/views.py:
   - Добавлен wallet_balance в selected_customer при загрузке из Redis
   - Добавлен wallet_balance в system_customer
   - Добавлен wallet_balance в API set_customer (Redis + response)
   - Используется json.dumps() для корректной сериализации данных клиента

2. customers/views.py:
   - Добавлен wallet_balance в API поиска клиентов (api_search_customers)
   - Добавлен wallet_balance в API создания клиента (api_create_customer)

3. pos/static/pos/js/terminal.js:
   - Обновлена функция selectCustomer() для получения walletBalance
   - Обновлены все вызовы selectCustomer() для передачи баланса
   - selectedCustomer теперь содержит wallet_balance

4. pos/templates/pos/terminal.html:
   - Используются готовые JSON-строки из backend (system_customer_json, selected_customer_json)
   - Исправлена проблема с локализацией чисел в JSON

Результат:
Баланс кошелька клиента теперь корректно отображается в модальном окне продажи

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-04 13:11:50 +03:00
parent 4de89fca43
commit 16234b0a1f
4 changed files with 122 additions and 79 deletions

View File

@@ -181,14 +181,16 @@ def pos_terminal(request):
'showcase_kits_json': json.dumps([]),
'current_warehouse': None,
'warehouses': [],
'system_customer': {
'system_customer_json': json.dumps({
'id': system_customer.id,
'name': system_customer.name
},
'selected_customer': {
'name': system_customer.name,
'wallet_balance': float(system_customer.wallet_balance)
}),
'selected_customer_json': json.dumps({
'id': system_customer.id,
'name': system_customer.name
},
'name': system_customer.name,
'wallet_balance': float(system_customer.wallet_balance)
}),
'cart_data': json.dumps({}),
'title': 'POS Terminal',
}
@@ -208,7 +210,8 @@ def pos_terminal(request):
customer = Customer.objects.get(id=cached_customer_data['customer_id'])
selected_customer = {
'id': customer.id,
'name': customer.name
'name': customer.name,
'wallet_balance': float(customer.wallet_balance)
}
except Customer.DoesNotExist:
# Клиент был удален - очищаем кэш
@@ -218,7 +221,8 @@ def pos_terminal(request):
if not selected_customer:
selected_customer = {
'id': system_customer.id,
'name': system_customer.name
'name': system_customer.name,
'wallet_balance': float(system_customer.wallet_balance)
}
# Пытаемся получить сохраненную корзину из Redis
@@ -280,11 +284,12 @@ def pos_terminal(request):
'name': current_warehouse.name
},
'warehouses': warehouses_list,
'system_customer': {
'system_customer_json': json.dumps({
'id': system_customer.id,
'name': system_customer.name
},
'selected_customer': selected_customer, # Текущий выбранный клиент (из Redis или системный)
'name': system_customer.name,
'wallet_balance': float(system_customer.wallet_balance)
}),
'selected_customer_json': json.dumps(selected_customer), # Текущий выбранный клиент (из Redis или системный)
'cart_data': json.dumps(cart_data), # Сохраненная корзина из Redis
'title': 'POS Terminal',
}
@@ -355,14 +360,16 @@ def set_customer(request, customer_id):
redis_key = f'pos:customer:{request.user.id}:{current_warehouse.id}'
customer_data = {
'customer_id': customer.id,
'customer_name': customer.name
'customer_name': customer.name,
'wallet_balance': float(customer.wallet_balance)
}
cache.set(redis_key, customer_data, timeout=7200) # 2 часа
return JsonResponse({
'success': True,
'customer_id': customer.id,
'customer_name': customer.name
'customer_name': customer.name,
'wallet_balance': float(customer.wallet_balance)
})