From 6568504f5bd207d5b55a92724b69fd71b0d95c1e Mon Sep 17 00:00:00 2001 From: i701 Date: Fri, 4 Jul 2025 16:32:21 +0500 Subject: [PATCH] =?UTF-8?q?migration(billing):=20Add=20expires=5Fat=20fiel?= =?UTF-8?q?d=20and=20is=5Fexpired=20property=20to=20Topup=20model=20for=20?= =?UTF-8?q?expiration=20management=20=F0=9F=94=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._options_topup_expired_topup_expires_at.py | 26 +++++++++++++++++++ .../migrations/0009_remove_topup_expired.py | 16 ++++++++++++ billing/models.py | 7 +++++ 3 files changed, 49 insertions(+) create mode 100644 billing/migrations/0008_alter_topup_options_topup_expired_topup_expires_at.py create mode 100644 billing/migrations/0009_remove_topup_expired.py diff --git a/billing/migrations/0008_alter_topup_options_topup_expired_topup_expires_at.py b/billing/migrations/0008_alter_topup_options_topup_expired_topup_expires_at.py new file mode 100644 index 0000000..46cd966 --- /dev/null +++ b/billing/migrations/0008_alter_topup_options_topup_expired_topup_expires_at.py @@ -0,0 +1,26 @@ +# Generated by Django 5.2 on 2025-07-04 06:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("billing", "0007_topup_paid_at"), + ] + + operations = [ + migrations.AlterModelOptions( + name="topup", + options={"ordering": ["-created_at"]}, + ), + migrations.AddField( + model_name="topup", + name="expired", + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name="topup", + name="expires_at", + field=models.DateTimeField(blank=True, null=True), + ), + ] diff --git a/billing/migrations/0009_remove_topup_expired.py b/billing/migrations/0009_remove_topup_expired.py new file mode 100644 index 0000000..71c5576 --- /dev/null +++ b/billing/migrations/0009_remove_topup_expired.py @@ -0,0 +1,16 @@ +# Generated by Django 5.2 on 2025-07-04 11:13 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("billing", "0008_alter_topup_options_topup_expired_topup_expires_at"), + ] + + operations = [ + migrations.RemoveField( + model_name="topup", + name="expired", + ), + ] diff --git a/billing/models.py b/billing/models.py index 8017793..8fee3d6 100644 --- a/billing/models.py +++ b/billing/models.py @@ -53,9 +53,16 @@ class Topup(models.Model): paid = models.BooleanField(default=False) paid_at = models.DateTimeField(null=True, blank=True) mib_reference = models.CharField(default="", null=True, blank=True) + expires_at = models.DateTimeField(null=True, blank=True) created_at = models.DateTimeField(default=timezone.now) updated_at = models.DateTimeField(auto_now=True) + @property + def is_expired(self): + if self.expires_at is None: + return False + return timezone.now() > self.expires_at + def __str__(self): return f"Topup for {self.user}"