Pay: move some model-related methods from helpers to models

Otherwise we end up in circular dependency hell
This commit is contained in:
fnux 2020-03-04 09:39:18 +01:00
commit 9aabc66e57
6 changed files with 108 additions and 107 deletions

View file

@ -1,7 +1,6 @@
from django.core.management.base import BaseCommand
from uncloud_auth.models import User
from uncloud_pay.models import Order, Bill
from uncloud_pay.helpers import get_balance_for, get_payment_method_for
from uncloud_pay.models import Order, Bill, PaymentMethod, get_balance_for
from datetime import timedelta
from django.utils import timezone
@ -19,7 +18,7 @@ class Command(BaseCommand):
balance = get_balance_for(user)
if balance < 0:
print("User {} has negative balance ({}), charging.".format(user.username, balance))
payment_method = get_payment_method_for(user)
payment_method = PaymentMethod.get_primary_for(user)
if payment_method != None:
amount_to_be_charged = abs(balance)
charge_ok = payment_method.charge(amount_to_be_charged)