Skip to content

Commit

Permalink
Added dollar amount
Browse files Browse the repository at this point in the history
  • Loading branch information
clr-li committed Dec 27, 2023
1 parent 320d44e commit e01185a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions app_users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class AppUserTransactionAdmin(admin.ModelAdmin):
"created_at",
"end_balance",
"type",
"dollar_amt",
]
readonly_fields = ["created_at"]
list_filter = ["created_at", IsStripeFilter]
Expand Down
17 changes: 17 additions & 0 deletions app_users/migrations/0014_appusertransaction_dollar_amt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.5 on 2023-12-27 20:44

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("app_users", "0013_alter_appusertransaction_type"),
]

operations = [
migrations.AddField(
model_name="appusertransaction",
name="dollar_amt",
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=6),
),
]
4 changes: 3 additions & 1 deletion app_users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,14 @@ def add_balance(self, amount: int, invoice_id: str) -> "AppUserTransaction":
user: AppUser = AppUser.objects.select_for_update().get(pk=self.pk)
user.balance += amount
user.save(update_fields=["balance"])

dollar_amt = amount / 100
return AppUserTransaction.objects.create(
user=self,
invoice_id=invoice_id,
amount=amount,
end_balance=user.balance,
type=type,
dollar_amt=dollar_amt,
)

def copy_from_firebase_user(self, user: auth.UserRecord) -> "AppUser":
Expand Down Expand Up @@ -231,6 +232,7 @@ class AppUserTransaction(models.Model):
end_balance = models.IntegerField()
created_at = models.DateTimeField(editable=False, blank=True, default=timezone.now)
type = models.CharField(max_length=255, default="Stripe")
dollar_amt = models.DecimalField(max_digits=6, decimal_places=2, default=0.0)

class Meta:
verbose_name = "Transaction"
Expand Down

0 comments on commit e01185a

Please sign in to comment.