# Path: accounts/factories.py
# class UserFactory(factory.DjangoModelFactory):
#     username = factory.Sequence(lambda n: 'admin%d' % n)
#     password = 'secret'
#     email = factory.LazyAttribute(lambda obj: '%s@example.com' % obj.username)
# 
#     class Meta:
#         model = User
# 
#     @classmethod
#     def _create(cls, model_class, *args, **kwargs):
#         manager = cls._get_manager(model_class)
#         return manager.create_user(*args, **kwargs)
# 
# Path: books/factories.py
# class DebtLoanFactory(factory.DjangoModelFactory):
#     with_who = "ACME co."
#     title = factory.Sequence(lambda n: 'debt_loan_%d' % n)
#     amount = 42
#     category = models.DebtLoan.DEBT
#     user = factory.SubFactory(UserFactory)
# 
#     class Meta:
#         model = models.DebtLoan
# 
# Path: books/factories.py
# class TransactionFactory(factory.DjangoModelFactory):
#     title = factory.Sequence(lambda n: 'transaction_%d' % n)
#     amount = 10
#     category = models.Transaction.EXPENSE
#     user = factory.SubFactory(UserFactory)
# 
#     class Meta:
#         model = models.Transaction
# 
# Path: books/models.py
# class DebtLoan(models.Model):
#     DEBT = 0
#     LOAN = 1
#     CATEGORY_CHOICES = (
#         (DEBT, 'debt'),
#         (LOAN, 'loan'),
#     )
# 
#     with_who = fields.CharField(max_length=255)
#     title = fields.CharField(max_length=255, null=True, blank=True)
#     amount = fields.DecimalField(max_digits=10, decimal_places=2)
#     category = fields.PositiveSmallIntegerField(choices=CATEGORY_CHOICES)
#     created = fields.DateTimeField(default=timezone.now, editable=False)
#     modified = fields.DateTimeField(default=timezone.now)
#     active = fields.BooleanField(default=True)
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
# 
#     def __str__(self):
#         if self.title:
#             return "{}: {}".format(self.with_who, self.title)
#         else:
#             return "{}".format(self.with_who)
# 
#     def deactivate(self):
#         if self.active:
#             self.active = False
#             self.save()
# 
# Path: books/models.py
# class Transaction(models.Model):
#     EXPENSE = 'exp'
#     INCOME = 'inc'
#     CATEGORY_CHOICES = (
#         (EXPENSE, 'expense'),
#         (INCOME, 'income'),
#     )
# 
#     title = fields.CharField(max_length=255)
#     amount = fields.DecimalField(max_digits=10, decimal_places=2)
#     category = fields.CharField(max_length=3, choices=CATEGORY_CHOICES)
#     created = fields.DateTimeField(default=timezone.now, editable=False)
#     modified = fields.DateTimeField(default=timezone.now)
#     active = fields.BooleanField(default=True)
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return "{}".format(self.title)
# 
#     def deactivate(self):
#         if self.active:
#             self.active = False
#             self.save()


from datetime import datetime
from datetime import timedelta
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from django.utils import timezone
from accounts.factories import UserFactory
from books.factories import DebtLoanFactory
from books.factories import TransactionFactory
from books.models import DebtLoan
from books.models import Transaction
import random
import factory
import pytz
            5,
            amount=factory.Sequence(lambda n: random.randint(1, 10)),
            category=factory.Sequence(lambda n: random.choice(categories)),
            user=self.admin,
            created=factory.Sequence(lambda n: self._get_last_month()),
        )

        # create for this year
        TransactionFactory.create_batch(
            5,
            amount=factory.Sequence(lambda n: random.randint(1, 10)),
            category=factory.Sequence(lambda n: random.choice(categories)),
            user=self.admin,
            created=factory.Sequence(lambda n: self._get_this_year()),
        )

        # create for all time
        TransactionFactory.create_batch(
            5,
            amount=factory.Sequence(lambda n: random.randint(1, 10)),
            category=factory.Sequence(lambda n: random.choice(categories)),
            user=self.admin,
            created=factory.Sequence(lambda n: self._get_all_time()),
        )
        print("Transactions for admin created")

    def create_debt_loans(self):
        categories = [DebtLoan.DEBT, DebtLoan.LOAN]

        # create now

# Path: accounts/factories.py
# class UserFactory(factory.DjangoModelFactory):
#     username = factory.Sequence(lambda n: 'admin%d' % n)
#     password = 'secret'
#     email = factory.LazyAttribute(lambda obj: '%s@example.com' % obj.username)
# 
#     class Meta:
#         model = User
# 
#     @classmethod
#     def _create(cls, model_class, *args, **kwargs):
#         manager = cls._get_manager(model_class)
#         return manager.create_user(*args, **kwargs)
# 
# Path: books/factories.py
# class DebtLoanFactory(factory.DjangoModelFactory):
#     with_who = "ACME co."
#     title = factory.Sequence(lambda n: 'debt_loan_%d' % n)
#     amount = 42
#     category = models.DebtLoan.DEBT
#     user = factory.SubFactory(UserFactory)
# 
#     class Meta:
#         model = models.DebtLoan
# 
# Path: books/factories.py
# class TransactionFactory(factory.DjangoModelFactory):
#     title = factory.Sequence(lambda n: 'transaction_%d' % n)
#     amount = 10
#     category = models.Transaction.EXPENSE
#     user = factory.SubFactory(UserFactory)
# 
#     class Meta:
#         model = models.Transaction
# 
# Path: books/models.py
# class DebtLoan(models.Model):
#     DEBT = 0
#     LOAN = 1
#     CATEGORY_CHOICES = (
#         (DEBT, 'debt'),
#         (LOAN, 'loan'),
#     )
# 
#     with_who = fields.CharField(max_length=255)
#     title = fields.CharField(max_length=255, null=True, blank=True)
#     amount = fields.DecimalField(max_digits=10, decimal_places=2)
#     category = fields.PositiveSmallIntegerField(choices=CATEGORY_CHOICES)
#     created = fields.DateTimeField(default=timezone.now, editable=False)
#     modified = fields.DateTimeField(default=timezone.now)
#     active = fields.BooleanField(default=True)
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
# 
#     def __str__(self):
#         if self.title:
#             return "{}: {}".format(self.with_who, self.title)
#         else:
#             return "{}".format(self.with_who)
# 
#     def deactivate(self):
#         if self.active:
#             self.active = False
#             self.save()
# 
# Path: books/models.py
# class Transaction(models.Model):
#     EXPENSE = 'exp'
#     INCOME = 'inc'
#     CATEGORY_CHOICES = (
#         (EXPENSE, 'expense'),
#         (INCOME, 'income'),
#     )
# 
#     title = fields.CharField(max_length=255)
#     amount = fields.DecimalField(max_digits=10, decimal_places=2)
#     category = fields.CharField(max_length=3, choices=CATEGORY_CHOICES)
#     created = fields.DateTimeField(default=timezone.now, editable=False)
#     modified = fields.DateTimeField(default=timezone.now)
#     active = fields.BooleanField(default=True)
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
# 
#     def __str__(self):
#         return "{}".format(self.title)
# 
#     def deactivate(self):
#         if self.active:
#             self.active = False
#             self.save()


# Path: finance/management/commands/populate.py
from datetime import datetime
from datetime import timedelta
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from django.utils import timezone
from accounts.factories import UserFactory
from books.factories import DebtLoanFactory
from books.factories import TransactionFactory
from books.models import DebtLoan
from books.models import Transaction
import random
import factory
import pytz

            5,
            amount=factory.Sequence(lambda n: random.randint(1, 10)),
            category=factory.Sequence(lambda n: random.choice(categories)),
            user=self.admin,
            created=factory.Sequence(lambda n: self._get_last_month()),
        )

        # create for this year
        TransactionFactory.create_batch(
            5,
            amount=factory.Sequence(lambda n: random.randint(1, 10)),
            category=factory.Sequence(lambda n: random.choice(categories)),
            user=self.admin,
            created=factory.Sequence(lambda n: self._get_this_year()),
        )

        # create for all time
        TransactionFactory.create_batch(
            5,
            amount=factory.Sequence(lambda n: random.randint(1, 10)),
            category=factory.Sequence(lambda n: random.choice(categories)),
            user=self.admin,
            created=factory.Sequence(lambda n: self._get_all_time()),
        )
        print("Transactions for admin created")

    def create_debt_loans(self):
        categories = [DebtLoan.DEBT, DebtLoan.LOAN]

        # create now

        DebtLoanFactory.create_batch(