Skip to content

Commit

Permalink
make PotPayout.paid_at nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed Jul 8, 2024
1 parent 12607cf commit 897df4c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion accounts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def get(self, request: Request, *args, **kwargs):
{"message": f"Account with ID {account_id} not found."}, status=404
)

payouts = PotPayout.objects.filter(recipient=account)
payouts = PotPayout.objects.filter(recipient=account, paid_at__isnull=False)
results = self.paginate_queryset(payouts, request, view=self)
serializer = PotPayoutSerializer(results, many=True)
return self.get_paginated_response(serializer.data)
9 changes: 6 additions & 3 deletions indexer_app/management/commands/populatedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,11 @@ def handle(self, *args, **options):
break
if "payouts" in config:
for payout in config["payouts"]:
if not payout["paid_at"]:
continue
paid_at = (
None
if "paid_at" not in payout
else datetime.fromtimestamp(payout["paid_at"] / 1000)
)
recipient, _ = Account.objects.get_or_create(
id=payout["project_id"]
)
Expand All @@ -476,7 +479,7 @@ def handle(self, *args, **options):
"amount": payout["amount"],
"amount_paid_usd": None,
"token": near_token, # pots only support native NEAR
"paid_at": datetime.fromtimestamp(payout["paid_at"] / 1000),
"paid_at": paid_at,
"tx_hash": None,
}
payout, _ = PotPayout.objects.update_or_create(
Expand Down
4 changes: 3 additions & 1 deletion indexer_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def fetch_usd_prices():
jobs_logger.info(f"USD prices fetched for {donations_count} donations.")

# payouts
payouts = PotPayout.objects.filter(amount_paid_usd__isnull=True)
payouts = PotPayout.objects.filter(
amount_paid_usd__isnull=True, paid_at__isnull=False
)
payouts_count = payouts.count()
jobs_logger.info(f"Fetching USD prices for {payouts_count} payouts...")
for payout in payouts:
Expand Down
9 changes: 8 additions & 1 deletion indexer_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,21 @@ async def handle_set_payouts(data: dict, receiver_id: str, receipt: Receipt):

logger.info(f"set payout data: {data}, {receiver_id}")
payouts = data.get("payouts", [])
pot = await Pot.objects.aget(id=receiver_id)
near_acct, _ = Account.objects.get_or_create(id="near")
near_token, _ = Token.objects.get_or_create(
id=near_acct
) # Pots only support native NEAR

insertion_data = []
for payout in payouts:
# General question: should we register projects as accounts?
pot_payout = PotPayout(
pot=pot,
recipient_id=payout.get("project_id"),
amount=payout.get("amount"),
ft_id=payout.get("ft_id", "near"),
token=near_token,
paid_at=None,
tx_hash=receipt.receipt_id,
)
insertion_data.append(pot_payout)
Expand Down
23 changes: 23 additions & 0 deletions pots/migrations/0010_alter_potpayout_paid_at.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.4 on 2024-07-08 13:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("pots", "0009_remove_potpayout_ft_alter_potpayout_token"),
]

operations = [
migrations.AlterField(
model_name="potpayout",
name="paid_at",
field=models.DateTimeField(
db_index=True,
help_text="Payout date.",
null=True,
verbose_name="paid at",
),
),
]
2 changes: 1 addition & 1 deletion pots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ class PotPayout(models.Model):
)
paid_at = models.DateTimeField(
_("paid at"),
null=False,
null=True,
help_text=_("Payout date."),
db_index=True,
)
Expand Down

0 comments on commit 897df4c

Please sign in to comment.