Skip to content

Commit

Permalink
Add comments for user.add_balance, remove unnecessary is_paying from …
Browse files Browse the repository at this point in the history
…update_fields there
  • Loading branch information
nikochiko committed Oct 13, 2023
1 parent f74e776 commit aa72701
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app_users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ def first_name(self):
return self.display_name.split(" ")[0]

def add_balance(self, amount: int, invoice_id: str, **invoice_items):
"""
Used to add/deduct credits when they are added or consumed.
When credits are bought with stripe -- invoice_id is the stripe
invoice ID.
When credits are deducted due to a run -- invoice_id is of the
form "gooey_in_{uuid}"
"""

from google.cloud import firestore
from google.cloud.firestore_v1.transaction import Transaction

Expand Down Expand Up @@ -142,7 +151,7 @@ def add_balance_direct(self, amount):
obj: AppUser = self.__class__.objects.select_for_update().get(pk=self.pk)
obj.balance += amount
obj.is_paying = True
obj.save(update_fields=["balance", "is_paying"])
obj.save(update_fields=["balance"])
return obj

def copy_from_firebase_user(self, user: auth.UserRecord) -> "AppUser":
Expand Down

0 comments on commit aa72701

Please sign in to comment.