diff --git a/backend/budget_tracking/migrations/0003_customlabel_current_amount_customlabel_goal_and_more.py b/backend/budget_tracking/migrations/0003_customlabel_current_amount_customlabel_goal_and_more.py new file mode 100644 index 0000000..b0757f7 --- /dev/null +++ b/backend/budget_tracking/migrations/0003_customlabel_current_amount_customlabel_goal_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0.6 on 2024-06-23 17:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('budget_tracking', '0002_alter_transaction_update_wallet'), + ] + + operations = [ + migrations.AddField( + model_name='customlabel', + name='current_amount', + field=models.DecimalField(decimal_places=2, default=0, max_digits=15), + ), + migrations.AddField( + model_name='customlabel', + name='goal', + field=models.DecimalField(decimal_places=2, default=0, max_digits=15), + ), + migrations.AddField( + model_name='customlabel', + name='is_monthly', + field=models.BooleanField(default=True), + ), + ] diff --git a/backend/budget_tracking/models.py b/backend/budget_tracking/models.py index 9b59b05..893d18d 100644 --- a/backend/budget_tracking/models.py +++ b/backend/budget_tracking/models.py @@ -196,10 +196,10 @@ def save(self, is_first_save=False, **kwargs): amount = self.value if self.type == 'Earning' else (-self.value) self.wallet.update_balance(amount) - if self.is_within_current_month() and self.label.is_monthly: + if self.label and self.is_within_current_month() and self.label.is_monthly: self.label.update_balance(self.value) - if not self.label.is_monthly: + if self.label and not self.label.is_monthly: self.label.update_balance(self.value) return super().save(**kwargs) diff --git a/backend/users/models.py b/backend/users/models.py index 3c9b65c..c49850e 100644 --- a/backend/users/models.py +++ b/backend/users/models.py @@ -20,16 +20,16 @@ def create_user(self, name, email, password=None): user.save(using=self._db) labels_data = [ - {"id": 0, "name": "Food", "color": "white"}, - {"id": 1, "name": "Transportation", "color": "black"}, - {"id": 2, "name": "Housing", "color": "white"}, - {"id": 3, "name": "Utilities", "color": "black"}, - {"id": 4, "name": "Entertainment", "color": "white"}, - {"id": 5, "name": "Salary", "color": "black"}, - {"id": 6, "name": "Freelance Income", "color": "white"}, - {"id": 7, "name": "Investment", "color": "black"}, - {"id": 8, "name": "Gifts", "color": "white"}, - {"id": 9, "name": "Other", "color": "black"}, + {"id": 0, "name": "Food", "color": "white", "is_monthly" : True}, + {"id": 1, "name": "Transportation", "color": "black", "is_monthly" : True}, + {"id": 2, "name": "Housing", "color": "white", "is_monthly" : True}, + {"id": 3, "name": "Utilities", "color": "black", "is_monthly" : True}, + {"id": 4, "name": "Entertainment", "color": "white", "is_monthly" : True}, + {"id": 5, "name": "Salary", "color": "black", "is_monthly" : True}, + {"id": 6, "name": "Freelance Income", "color": "white", "is_monthly" : True}, + {"id": 7, "name": "Investment", "color": "black", "is_monthly" : True}, + {"id": 8, "name": "Gifts", "color": "white", "is_monthly" : True}, + {"id": 9, "name": "Other", "color": "black", "is_monthly" : True}, ] # Creation of a related wallet for the created user