payemnt billing and credits refactoring
This commit is contained in:
@@ -18,7 +18,7 @@ def replenish_monthly_credits():
|
||||
Runs on the first day of each month at midnight.
|
||||
|
||||
For each active account with a plan:
|
||||
- Adds plan.included_credits to account.credits
|
||||
- Resets credits to plan.included_credits
|
||||
- Creates a CreditTransaction record
|
||||
- Logs the replenishment
|
||||
"""
|
||||
@@ -52,12 +52,11 @@ def replenish_monthly_credits():
|
||||
skipped += 1
|
||||
continue
|
||||
|
||||
# Add credits using CreditService
|
||||
# Reset credits using CreditService
|
||||
with transaction.atomic():
|
||||
new_balance = CreditService.add_credits(
|
||||
new_balance = CreditService.reset_credits_for_renewal(
|
||||
account=account,
|
||||
amount=monthly_credits,
|
||||
transaction_type='subscription',
|
||||
new_amount=monthly_credits,
|
||||
description=f"Monthly credit replenishment - {plan.name} plan",
|
||||
metadata={
|
||||
'plan_id': plan.id,
|
||||
@@ -69,7 +68,7 @@ def replenish_monthly_credits():
|
||||
|
||||
logger.info(
|
||||
f"Account {account.id} ({account.name}): "
|
||||
f"Added {monthly_credits} credits (balance: {new_balance})"
|
||||
f"Reset credits to {monthly_credits} (balance: {new_balance})"
|
||||
)
|
||||
replenished += 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user