예제 #1
0
    def random_bills(self, example_housemates, db):
        # Save housemates
        for housemate in example_housemates:
            housemate.save()

        # Create 30 random bills
        for i in range(30):
            random_year = randint(2019, 2050)
            random_month = randint(1, 12)
            # Subtract from last day of month so I can make sure there're
            # still days left in the month for the service end date
            random_day = randint(1, calendar.monthrange(random_year, random_month)[1] - 5)
            bill = IndividualBill(debtor=example_housemates[randint(0, len(example_housemates) - 1)],
                                  service_start=date(year=random_year,
                                                     month=random_month,
                                                     day=random_day),
                                  service_end=date(year=random_year,
                                                   month=random_month,
                                                   day=random_day + 5),
                                  category=categories[randint(0, len(categories) - 1)][0],
                                  total=randint(1, 10000),
                                  paid=randint(0, 1))
            bill.save()
예제 #2
0
def split_bills_between_housemates(bills):
    housemates = get_housemates()
    for bill in bills:
        # Split the bill into equal parts between housemates
        split_cost = int((bill.total / len(housemates)) * 100)

        # Create an IndividualBill assigned to each housemate
        for housemate in housemates:
            housemate_bill, created = IndividualBill.get_or_create(
                debtor=housemate,
                service_start=bill.start_date,
                service_end=bill.end_date,
                category=bill.category,
                total=split_cost,
                paid=False)
            if created:
                housemate_bill.save()
예제 #3
0
    def example_gas_bills(self, example_housemates, db):
        # Save the housemates so we can use them
        example_housemates[0].save()
        example_housemates[1].save()
        example_housemates[2].save()

        bill1 = IndividualBill(debtor=example_housemates[0],
                               service_start=date(year=2019,
                                                  month=1,
                                                  day=1),
                               service_end=date(year=2019,
                                                month=2,
                                                day=1),
                               category=categories[0][0],
                               total=example_totals[0],
                               paid=False)
        bill2 = IndividualBill(debtor=example_housemates[1],
                               service_start=date(year=2019,
                                                  month=1,
                                                  day=1),
                               service_end=date(year=2019,
                                                month=2,
                                                day=1),
                               category=categories[0][0],
                               total=example_totals[1],
                               paid=False)
        bill3 = IndividualBill(debtor=example_housemates[2],
                               service_start=date(year=2019,
                                                  month=1,
                                                  day=1),
                               service_end=date(year=2019,
                                                month=2,
                                                day=1),
                               category=categories[0][0],
                               total=example_totals[2],
                               paid=False)
        bill1.save()
        bill2.save()
        bill3.save()
예제 #4
0
 def test_housemate_creation(self, random_bills):
     assert IndividualBill.select().count() == 30