Beispiel #1
0
def book_create_invoice(book):
    book = book_get(book)
    obj = Invoice()
    obj.balance = "CR"  # Credit
    obj.book = book
    obj.status = "PE"  # Pending
    obj.to_pay = int(book.price.price_chf)
    # Default 10 days to pay
    obj.pay_till = datetime.datetime.now().date() + datetime.timedelta(
        days=book.price.days_till_pay)
    obj.notes = "\n Automatic created Invoice"
    obj.save()
Beispiel #2
0
 def test_missing_branch(self):
     """
     The branch was not provided
     """
     with self.assertRaises(IntegrityError) as context:
         invoice = Invoice(vendor=get_or_create_vendor(),
                           invoice_num='INV0001',
                           date="2020-06-15",
                           total_amount=100.0,
                           document=create_document())
         invoice.save()
         self.fail("'test_missing_branch' did not get the expected error")
     self.assertTrue(
         'null value in column "branch_id" violates not-null constraint' in
         str(context.exception))
Beispiel #3
0
 def test_missing_date(self):
     """
     The date was not provided
     """
     branch = get_or_create_branch()
     with self.assertRaises(IntegrityError) as context:
         invoice = Invoice(branch=branch,
                           vendor=get_or_create_vendor(store=branch.store),
                           invoice_num='INV0001',
                           total_amount=100.0,
                           document=create_document())
         invoice.save()
         self.fail("'test_missing_date' did not get the expected error")
     self.assertTrue(
         'null value in column "date" violates not-null constraint' in str(
             context.exception))
Beispiel #4
0
 def test_missing_invoice_num(self):
     """
     The invoice_num was not provided
     """
     branch = get_or_create_branch()
     with self.assertRaises(ValidationError) as context:
         invoice = Invoice(branch=branch,
                           vendor=get_or_create_vendor(store=branch.store),
                           date="2020-06-15",
                           total_amount=100.0,
                           document=create_document())
         invoice.full_clean()
         invoice.save()
         self.fail("'test_invoice_num' did not get the expected error")
     self.assertTrue("{'invoice_num': ['This field cannot be blank.']}" in
                     str(context.exception))
    def make_invoices(self) -> None:
        """
        Create invoices for the policy according with its billing schedule
        """
        for invoice in self.policy.invoices:
            DBSession.delete(invoice)

        invoices = []
        first_invoice = Invoice(
            self.policy.id,
            self.policy.effective_date,  # bill_date
            self.policy.effective_date + relativedelta(months=1),  # due
            self.policy.effective_date +
            relativedelta(months=1, days=14),  # cancel
            self.policy.annual_premium,
        )
        invoices.append(first_invoice)

        if self.policy.billing_schedule == "Annual":
            pass
        elif self.policy.billing_schedule == "Two-Pay":
            first_invoice.amount_due = first_invoice.amount_due / BILLING_SCHEDULES.get(
                self.policy.billing_schedule)
            for i in range(1,
                           BILLING_SCHEDULES.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 6
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id,
                    bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    BILLING_SCHEDULES.get(self.policy.billing_schedule),
                )
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Quarterly":
            first_invoice.amount_due = first_invoice.amount_due / BILLING_SCHEDULES.get(
                self.policy.billing_schedule)
            for i in range(1,
                           BILLING_SCHEDULES.get(
                               self.policy.billing_schedule)):
                months_after_eff_date = i * 3
                bill_date = self.policy.effective_date + relativedelta(
                    months=months_after_eff_date)
                invoice = Invoice(
                    self.policy.id,
                    bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    BILLING_SCHEDULES.get(self.policy.billing_schedule),
                )
                invoices.append(invoice)
        elif self.policy.billing_schedule == "Monthly":
            first_invoice.amount_due = first_invoice.amount_due / BILLING_SCHEDULES.get(
                self.policy.billing_schedule)
            for i in range(1,
                           BILLING_SCHEDULES.get(
                               self.policy.billing_schedule)):
                bill_date = self.policy.effective_date + relativedelta(
                    months=i)
                invoice = Invoice(
                    self.policy.id,
                    bill_date,
                    bill_date + relativedelta(months=1),
                    bill_date + relativedelta(months=1, days=14),
                    self.policy.annual_premium /
                    BILLING_SCHEDULES.get(self.policy.billing_schedule),
                )
                invoices.append(invoice)
        else:
            print("You have chosen a bad billing schedule.")

        for invoice in invoices:
            DBSession.add(invoice)
        DBSession.commit()