fix: Улучшения системы ценообразования комплектов
Исправлены 4 проблемы: 1. Расчёт цены первого товара - улучшена валидация в getProductPrice и calculateFinalPrice 2. Отображение actual_price в Select2 вместо обычной цены 3. Количество по умолчанию = 1 для новых форм компонентов 4. Auto-select текста при клике на поле количества для удобства редактирования Изменённые файлы: - products/forms.py: добавлен __init__ в KitItemForm для quantity.initial = 1 - products/templates/includes/select2-product-init.html: обновлена formatSelectResult - products/templates/productkit_create.html: добавлен focus handler для auto-select - products/templates/productkit_edit.html: добавлен focus handler для auto-select 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
88
test_inventory_reconciliation.py
Normal file
88
test_inventory_reconciliation.py
Normal file
@@ -0,0 +1,88 @@
|
||||
import os
|
||||
import sys
|
||||
import django
|
||||
from decimal import Decimal
|
||||
|
||||
sys.path.insert(0, 'C:/Users/team_/Desktop/test_qwen/myproject')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
|
||||
django.setup()
|
||||
|
||||
from tenants.models import Client
|
||||
from django.db import connection
|
||||
from products.models import Product
|
||||
from inventory.models import Warehouse, Inventory, InventoryLine, WriteOff
|
||||
|
||||
grach = Client.objects.get(schema_name='grach')
|
||||
connection.set_tenant(grach)
|
||||
|
||||
print("=== Inventory Reconciliation Test ===\n")
|
||||
|
||||
product = Product.objects.get(sku='FLOWER-001')
|
||||
warehouse = Warehouse.objects.get(name='Main Warehouse')
|
||||
|
||||
# Проверяем текущий остаток
|
||||
print("Step 1: Current stock status\n")
|
||||
|
||||
current_qty = sum(b.quantity for b in product.stock_batches.filter(warehouse=warehouse))
|
||||
print("Current system stock: {} units".format(current_qty))
|
||||
|
||||
# Создаём инвентаризацию
|
||||
print("\nStep 2: Creating inventory (physical count)\n")
|
||||
|
||||
inventory = Inventory.objects.create(
|
||||
warehouse=warehouse,
|
||||
status='draft'
|
||||
)
|
||||
print("Inventory created (status=draft)")
|
||||
|
||||
# Добавляем строку с физическим подсчётом (меньше, чем в системе - ДЕФИЦИТ)
|
||||
print("\nStep 3: Adding inventory line with deficit\n")
|
||||
|
||||
# Физический подсчёт: 5 единиц (система имеет 7)
|
||||
inventory_line = InventoryLine.objects.create(
|
||||
inventory=inventory,
|
||||
product=product,
|
||||
quantity_system=current_qty,
|
||||
quantity_fact=Decimal('5')
|
||||
)
|
||||
print("Inventory line: system={}, fact={}, difference={}".format(
|
||||
inventory_line.quantity_system,
|
||||
inventory_line.quantity_fact,
|
||||
inventory_line.difference
|
||||
))
|
||||
|
||||
# Завершаем инвентаризацию
|
||||
print("\nStep 4: Finishing inventory (processing reconciliation)\n")
|
||||
|
||||
inventory.status = 'completed'
|
||||
inventory.save()
|
||||
print("Inventory status: completed")
|
||||
|
||||
# Проверяем все WriteOff операции
|
||||
print("\nStep 5: Checking WriteOff operations\n")
|
||||
|
||||
writeoffs = WriteOff.objects.all().order_by('-date')
|
||||
print("Total WriteOff records: {}".format(writeoffs.count()))
|
||||
|
||||
if writeoffs.exists():
|
||||
print("Recent WriteOffs:")
|
||||
for wo in writeoffs[:3]:
|
||||
print(" - qty={}, reason={}".format(
|
||||
wo.quantity,
|
||||
wo.reason
|
||||
))
|
||||
print("PASS: WriteOff created for deficit")
|
||||
else:
|
||||
print(" No WriteOff found")
|
||||
|
||||
# Проверяем новый остаток
|
||||
print("\nStep 6: Final stock status\n")
|
||||
|
||||
final_qty = sum(b.quantity for b in product.stock_batches.filter(warehouse=warehouse))
|
||||
print("Final system stock: {} units".format(final_qty))
|
||||
print("Expected: 5 units")
|
||||
|
||||
if final_qty == Decimal('5'):
|
||||
print("PASS: Stock reconciled correctly")
|
||||
else:
|
||||
print("FAIL: Stock mismatch (expected 5, got {})".format(final_qty))
|
||||
Reference in New Issue
Block a user