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:
61
test_second_sale.py
Normal file
61
test_second_sale.py
Normal file
@@ -0,0 +1,61 @@
|
||||
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, Sale, SaleBatchAllocation
|
||||
|
||||
grach = Client.objects.get(schema_name='grach')
|
||||
connection.set_tenant(grach)
|
||||
|
||||
print("=== Second Sale Test ===\n")
|
||||
|
||||
product = Product.objects.get(sku='FLOWER-001')
|
||||
warehouse = Warehouse.objects.get(name='Main Warehouse')
|
||||
|
||||
# Создаем вторую продажу на 20 единиц
|
||||
print("Creating second sale (qty=20)\n")
|
||||
|
||||
sale2 = Sale.objects.create(
|
||||
product=product,
|
||||
warehouse=warehouse,
|
||||
quantity=Decimal('20'),
|
||||
sale_price=Decimal('250.00')
|
||||
)
|
||||
|
||||
print("Sale 2 created: qty=20\n")
|
||||
|
||||
# Проверяем allocations
|
||||
allocations = SaleBatchAllocation.objects.filter(sale=sale2)
|
||||
total = sum(a.quantity for a in allocations)
|
||||
|
||||
print("Allocations for Sale 2:")
|
||||
for alloc in allocations:
|
||||
print(" - qty={}, cost={}".format(alloc.quantity, alloc.cost_price))
|
||||
|
||||
print("\nTotal allocated: {}".format(total))
|
||||
print("Sale qty: {}".format(sale2.quantity))
|
||||
|
||||
if total == sale2.quantity:
|
||||
print("PASS: Allocations match Sale qty")
|
||||
else:
|
||||
print("FAIL: Allocations ({}) != Sale qty ({})".format(total, sale2.quantity))
|
||||
|
||||
# Проверяем порядок FIFO (должны взяться из batch2 (7), batch3 (13))
|
||||
expected = [Decimal('7'), Decimal('13')]
|
||||
actual = [a.quantity for a in allocations]
|
||||
|
||||
print("\nExpected FIFO order: {}".format(expected))
|
||||
print("Actual order: {}".format(actual))
|
||||
|
||||
if actual == expected:
|
||||
print("PASS: FIFO order correct")
|
||||
else:
|
||||
print("FAIL: FIFO order incorrect")
|
||||
Reference in New Issue
Block a user