teljes backend_mentés

This commit is contained in:
Roo
2026-03-22 18:59:27 +00:00
parent 5d44339f21
commit 5d96b00f81
34 changed files with 2575 additions and 977 deletions

View File

@@ -160,39 +160,39 @@ class SmartDeduction:
"EARNED": 0.0
}
print(f"[DEBUG] SmartDeduction.deduct_from_wallets: user_id={user_id}, amount={amount}, remaining={remaining}")
print(f"[DEBUG] Wallet before: purchased={wallet.purchased_credits}, earned={wallet.earned_credits}, service_coins={wallet.service_coins}")
logger.debug(f"SmartDeduction.deduct_from_wallets: user_id={user_id}, amount={amount}, remaining={remaining}")
logger.debug(f"Wallet before: purchased={wallet.purchased_credits}, earned={wallet.earned_credits}, service_coins={wallet.service_coins}")
# 1. VOUCHER levonás (FIFO)
if remaining > 0:
voucher_used = await cls._deduct_from_vouchers(db, wallet.id, remaining)
used_amounts["VOUCHER"] = float(voucher_used)
remaining -= Decimal(str(voucher_used))
print(f"[DEBUG] After VOUCHER: voucher_used={voucher_used}, remaining={remaining}")
logger.debug(f"After VOUCHER: voucher_used={voucher_used}, remaining={remaining}")
# 2. SERVICE_COINS levonás
if remaining > 0 and wallet.service_coins >= remaining:
used_amounts["SERVICE_COINS"] = float(remaining)
wallet.service_coins -= remaining
remaining = Decimal('0')
print(f"[DEBUG] After SERVICE_COINS (full): used={remaining}, wallet.service_coins={wallet.service_coins}")
logger.debug(f"After SERVICE_COINS (full): used={remaining}, wallet.service_coins={wallet.service_coins}")
elif remaining > 0 and wallet.service_coins > 0:
used_amounts["SERVICE_COINS"] = float(wallet.service_coins)
remaining -= wallet.service_coins
wallet.service_coins = Decimal('0')
print(f"[DEBUG] After SERVICE_COINS (partial): used={wallet.service_coins}, remaining={remaining}, wallet.service_coins={wallet.service_coins}")
logger.debug(f"After SERVICE_COINS (partial): used={wallet.service_coins}, remaining={remaining}, wallet.service_coins={wallet.service_coins}")
# 3. PURCHASED levonás
if remaining > 0 and wallet.purchased_credits >= remaining:
used_amounts["PURCHASED"] = float(remaining)
wallet.purchased_credits -= remaining
remaining = Decimal('0')
print(f"[DEBUG] After PURCHASED (full): used={remaining}, wallet.purchased_credits={wallet.purchased_credits}")
logger.debug(f"After PURCHASED (full): used={remaining}, wallet.purchased_credits={wallet.purchased_credits}")
elif remaining > 0 and wallet.purchased_credits > 0:
used_amounts["PURCHASED"] = float(wallet.purchased_credits)
remaining -= wallet.purchased_credits
wallet.purchased_credits = Decimal('0')
print(f"[DEBUG] After PURCHASED (partial): used={wallet.purchased_credits}, remaining={remaining}, wallet.purchased_credits={wallet.purchased_credits}")
logger.debug(f"After PURCHASED (partial): used={wallet.purchased_credits}, remaining={remaining}, wallet.purchased_credits={wallet.purchased_credits}")
# 4. EARNED levonás (utolsó)
if remaining > 0 and wallet.earned_credits >= remaining: