Example #1
0
 def test_quarterly_on_eff_date(self):
     print "Testing account balance on quarterly effective date...\n"
     self.policy.billing_schedule = "Quarterly"
     pa = PolicyAccounting(self.policy.id)
     self.assertEquals(
         pa.return_account_balance(date_cursor=self.policy.effective_date),
         300)
Example #2
0
 def test_annual_on_eff_date(self):
     print "Testing account balance on annual effective date...\n"
     self.policy.billing_schedule = "Annual"
     pa = PolicyAccounting(self.policy.id)
     self.assertEquals(
         pa.return_account_balance(date_cursor=self.policy.effective_date),
         1200)
Example #3
0
def get_result(policy, supplied_date):

    errors = {}
    try:
        pa = PolicyAccounting(policy)
    except orm.exc.NoResultFound:
        error_text = "No Policy found with Policy id: " + policy
        errors['error'] = error_text
        logger.error(error_text)
        return render_template("error.html", context=errors)

    invoices = pa.get_invoices(supplied_date)
    balance = pa.return_account_balance(supplied_date)
    main_dic = {}
    invoices_list = []
    for invoice in invoices:
        logger.debug(
            "invoice:  bill_date: %s - due_date: %s - cancel_date: %s - amount_due: %s",
            invoice.bill_date, invoice.due_date, invoice.cancel_date,
            invoice.amount_due)
        invoices_list.append({
            'bill_date':
            invoice.bill_date.strftime('%Y-%m-%d'),
            'due_date':
            invoice.due_date.strftime('%Y-%m-%d'),
            'cancel_date':
            invoice.cancel_date.strftime('%Y-%m-%d'),
            'amount_due':
            invoice.amount_due
        })
    main_dic['invoices'] = invoices_list
    main_dic['balance'] = balance
    main_dic['policy_id'] = policy
    return render_template('table.html', context=main_dic)
Example #4
0
    def test_policy_cancelled_with_description(self):
        self.policy.cancel_date = None
        self.policy.cancel_description = None

        pa = PolicyAccounting(self.policy.id)

        reset_invoices = Invoice.query.filter_by(policy_id=self.policy.id) \
            .order_by(Invoice.bill_date) \
            .all()
        for reset_invoice in reset_invoices:
            reset_invoice.deleted = False
        db.session.commit()

        pa.evaluate_cancel(date(2015, 5, 5), 'Just Because')

        invoices = Invoice.query.filter_by(policy_id=self.policy.id)\
            .order_by(Invoice.bill_date)\
            .all()

        self.assertEquals(invoices[0].deleted, False)
        self.assertEquals(invoices[1].deleted, True)
        self.assertEquals(invoices[2].deleted, True)
        self.assertEquals(invoices[3].deleted, True)

        self.assertEquals(self.policy.cancel_date, datetime.now().date())
        self.assertEquals(self.policy.cancel_description, 'Just Because')
Example #5
0
 def test_quarterly_on_last_installment_bill_date(self):
     self.policy.billing_schedule = "Quarterly"
     pa = PolicyAccounting(self.policy.id)
     invoices = Invoice.query.filter_by(policy_id=self.policy.id)\
                             .order_by(Invoice.bill_date).all()
     self.assertEquals(
         pa.return_account_balance(date_cursor=invoices[3].bill_date), 1200)
 def test_cancel_policy(self):
     pa = PolicyAccounting(self.policy.id)
     canceled = pa.cancel_policy(date(2015, 1, 17), "Test Cancel")
     self.assertEquals(canceled, True)
     self.assertEquals(self.policy.cancelation_date, date(2015, 1, 17))
     self.assertEquals(self.policy.status, "Canceled")
     self.assertEquals(self.policy.cancel_description, "Test Cancel")
Example #7
0
    def test_monthly_on_eff_date(self):
        self.policy.billing_schedule = "Monthly"
        pa = PolicyAccounting(self.policy.id)

        self.assertEquals(
            pa.return_account_balance(date_cursor=self.policy.effective_date),
            100)
def main_page():
    if request.method == 'GET':
        # send the user the form
        return render_template('invoices.html')
    elif request.method == 'POST':
        # read form data
        policy_number = request.form['policy_number']
        effective_date = request.form['effective_date']

    # Use Policy Number to get Policy Id
    policy = Policy.query.filter_by(policy_number=policy_number)\
        .first()

    # Pass Policy ID to the filter mechnism
    if policy is not None:
        invoices = Invoice.query.filter_by(policy_id=policy.id)\
            .order_by(Invoice.bill_date)\
            .all()

        pa = PolicyAccounting(policy.id)
        balance = pa.return_account_balance(effective_date)

    else:
        invoices = []
        balance = 0

    return render_template("invoices.html", invoices=invoices, balance=balance)
Example #9
0
 def test_update_billing_schedule_to_incorrect_name(self):
     self.policy.billing_schedule = "Annual"
     self.assertFalse(self.policy.invoices)
     pa = PolicyAccounting(self.policy.id)
     self.assertEqual(len(self.policy.invoices), 1)
     pa.update_billing_schedule("Wrong-Schedule")
     self.assertEqual(len(self.policy.invoices), 1)
     self.assertEqual(self.policy.invoices[0].deleted, False)
Example #10
0
 def test_update_billing_schedule_annual_to_twopay(self):
     self.policy.billing_schedule = "Annual"
     self.assertFalse(self.policy.invoices)
     pa = PolicyAccounting(self.policy.id)
     self.assertEqual(len(self.policy.invoices), 1)
     pa.update_billing_schedule("Two-Pay")
     self.assertEqual(len(self.policy.invoices), 3)
     self.assertEqual(self.policy.invoices[0].deleted, True)
Example #11
0
 def test_cancel_policy_with_wrong_description(self):
     pa = PolicyAccounting(self.policy.id)
     pa.cancel_policy('unpaid', None, date(2019, 3, 3))
     self.assertEqual(self.policy.invoices[0].deleted, False)
     self.assertEqual(self.policy.status, 'Active')
     self.assertNotEqual(self.policy.cancelation_reason, 'unpaid')
     self.assertNotEqual(self.policy.cancellation_description, None)
     self.assertEqual(self.policy.cancelation_date, date(2019, 3, 3))
Example #12
0
 def test_cancel_policy_with_wrong_status(self):
     pa = PolicyAccounting(self.policy.id)
     pa.cancel_policy('wrong cancelation status', 'This is the description for the cancelation', date(2019, 3, 3))
     self.assertEqual(self.policy.invoices[0].deleted, False)
     self.assertEqual(self.policy.status, 'Active')
     self.assertNotEqual(self.policy.cancelation_reason, 'wrong cancelation status')
     self.assertEqual(self.policy.cancellation_description, 'This is the description for the cancelation')
     self.assertEqual(self.policy.cancelation_date, date(2019, 3, 3))
Example #13
0
 def test_cancel_policy(self):
     pa = PolicyAccounting(self.policy.id)
     pa.cancel_policy('unauthorized', 'This is the description for the cancelation', date(2019, 3, 3))
     self.assertEquals(self.policy.invoices[0].deleted, True)
     self.assertEquals(self.policy.status, 'Canceled')
     self.assertEquals(self.policy.cancelation_reason, 'unauthorized')
     self.assertEquals(self.policy.cancellation_description, 'This is the description for the cancelation')
     self.assertEquals(self.policy.cancelation_date, date(2019, 3, 3))
Example #14
0
 def test_new_invoices_changed_billing_schedule_from_two_pay(self):
     self.policy.billing_schedule = "Quarterly"
     pa = PolicyAccounting(self.policy)
     pa.change_billing_schedule("Two-Pay")
     invoices = Invoice.query.filter_by(policy_id=self.policy.id) \
                             .filter(Invoice.deleted.is_(False)) \
                             .all()
     self.assertEquals(len(invoices), 2)
Example #15
0
 def test_deleted_invoices_changed_billing_schedule_from_monthly(self):
     self.policy.billing_schedule = "Monthly"
     pa = PolicyAccounting(self.policy)
     pa.change_billing_schedule("Quarterly")
     invoices = Invoice.query.filter_by(policy_id=self.policy.id)\
                             .filter(Invoice.deleted.is_(True))\
                             .all()
     self.assertEquals(len(invoices), 12)
Example #16
0
 def test_quarterly_on_second_installment_bill_date_with_full_payment(self):
     self.policy.billing_schedule = "Quarterly"
     pa = PolicyAccounting(self.policy.id)
     invoices = Invoice.query.filter_by(policy_id=self.policy.id)\
                             .order_by(Invoice.bill_date).all()
     self.payments.append(pa.make_payment(contact_id=self.policy.named_insured,
                                          date_cursor=invoices[1].bill_date, amount=600))
     self.assertEquals(pa.return_account_balance(date_cursor=invoices[1].bill_date), 0)
Example #17
0
 def test_monthly_on_eff_date(self):
     self.policy.billing_schedule = "Monthly"
     pa = PolicyAccounting(self.policy)
     invoices = Invoice.query.filter_by(policy_id=self.policy.id)\
         .order_by(Invoice.bill_date).all()
     self.payments.append(pa.make_payment(contact_id=self.policy.named_insured,
                                          date_cursor=invoices[0].bill_date, amount=100))
     self.assertEquals(pa.return_account_balance(date_cursor=invoices[0].bill_date), 0)
Example #18
0
 def test_pending_no_payment_before_cancellation_edge(self):
     """
     Same as above, but testing edge case of date_cursor == due_date
     """
     pa = PolicyAccounting(self.policy.id)
     # No payment made and we are past the due date, but before cancellation
     d = date(2015, 2, 1)
     self.assertTrue(
         pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=d))
Example #19
0
    def test_cancel_policy_invalid_reason(self):
        pa = PolicyAccounting(self.policy.id)
        pa.cancel_policy('Canceled', 'Random Status Code', 'description')

        self.assertEquals(self.policy.invoices[0].deleted, False)
        self.assertEquals(self.policy.status, 'Active')
        self.assertEquals(self.policy.status_code, None)
        self.assertEquals(self.policy.status_desc, None)
        self.assertEquals(self.policy.cancel_date, None)
Example #20
0
    def test_expire_policy(self):
        pa = PolicyAccounting(self.policy.id)
        pa.cancel_policy('Expired', 'Non-Payment')

        self.assertEquals(self.policy.invoices[0].deleted, True)
        self.assertEquals(self.policy.status, 'Expired')
        self.assertEquals(self.policy.status_code, 'Non-Payment')
        self.assertEquals(self.policy.status_desc, None)
        self.assertEquals(self.policy.cancel_date, datetime.now().date())
Example #21
0
    def test_cancel_policy(self):
        pa = PolicyAccounting(self.policy.id)
        pa.cancel_policy('Canceled', 'Fraud', 'description')

        self.assertEquals(self.policy.invoices[0].deleted, True)
        self.assertEquals(self.policy.status, 'Canceled')
        self.assertEquals(self.policy.status_code, 'Fraud')
        self.assertEquals(self.policy.status_desc, 'description')
        self.assertEquals(self.policy.cancel_date, datetime.now().date())
Example #22
0
 def test_two_pay_on_last_installment_bill_date(self):
     self.policy.billing_schedule = "Two-Pay"
     pa = PolicyAccounting(self.policy)
     invoices = Invoice.query.filter_by(policy_id=self.policy.id) \
         .order_by(Invoice.bill_date).all()
     for i in range(1, 3):
         self.payments.append(pa.make_payment(contact_id=self.policy.named_insured,
                                              date_cursor=invoices[0].bill_date, amount=600))
     self.assertEquals(pa.return_account_balance(date_cursor=invoices[1].bill_date), 0)
Example #23
0
 def test_monthly_account_balance(self):
     self.policy.billing_schedule = "Monthly"
     pa = PolicyAccounting(self.policy.id)
     invoices = Invoice.query.filter_by(policy_id=self.policy.id)\
                             .order_by(Invoice.bill_date).all()
     # An index is used instead of iterate directly on the elements to help with the balance calculation
     for curr_invoice in range(len(invoices)):
         self.assertEquals(pa.return_account_balance(date_cursor=invoices[curr_invoice].bill_date),
                           (curr_invoice + 1) * invoices[curr_invoice].amount_due)
Example #24
0
    def test_Given_policy_to_cancel_When_policy_canceled_Then_policy_data_updated(
            self):
        pa = PolicyAccounting(self.policy.id)

        pa.cancel_policy("underwriting")

        self.assertEqual(pa.policy.status, 'Canceled')
        self.assertEqual(pa.policy.reason, "underwriting")
        self.assertEqual(pa.policy.date_changed, datetime.now().date())
Example #25
0
 def test_two_pay_payments_and_balance(self):
     self.policy.billing_schedule = "Two-Pay"
     pa = PolicyAccounting(self.policy.id)
     invoices = Invoice.query.filter_by(policy_id=self.policy.id)\
                             .order_by(Invoice.bill_date).all()
     for invoice in invoices:
         self.assertEquals(pa.return_account_balance(date_cursor=invoice.bill_date), invoice.amount_due)
         self.payments.append(pa.make_payment(contact_id=self.policy.named_insured,
                                              date_cursor=invoice.bill_date, amount=invoice.amount_due))
         self.assertEquals(pa.return_account_balance(date_cursor=invoice.bill_date), 0)
Example #26
0
    def test_nonpayment_cancellation(self):
        """
        Test the automatic cancallation of a policy due to nonpayment
        """
        self.assertIsNone(self.policy.cancellation)

        pa = PolicyAccounting(self.policy.id)
        pa.evaluate_cancel(date(2015, 6, 1))

        self.assertTrue(pa.policy.cancelled)
Example #27
0
 def test_pending_no_payment_after_cancellation_edge(self):
     """
     Test the method when the account is pending cancellation and after
     cancellation date has been reached.
     """
     pa = PolicyAccounting(self.policy.id)
     # No payment made and we are past the due date, but before cancellation
     d = date(2015, 2, 14)
     self.assertTrue(
         pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=d))
Example #28
0
 def test_quarterly_on_eff_date_after_change(self):
     """
     Same as above, but after a change in billing schedule.
     """
     self.policy.billing_schedule = "Monthly"
     pa = PolicyAccounting(self.policy.id)
     pa.change_billing_schedule("Quarterly")
     self.assertEquals(
         pa.return_account_balance(date_cursor=self.policy.effective_date),
         300)
Example #29
0
 def setUp(self):
     self.payments = []
     self.pa = PolicyAccounting(self.policy.id)
     self.invoices = Invoice.query.filter_by(
         policy_id=self.policy.id).order_by(Invoice.bill_date).all()
     self.payments.append(
         self.pa.make_payment(contact_id=self.policy.named_insured,
                              date_cursor=self.invoices[0].bill_date,
                              amount=400))
     self.pa.evaluate_cancel = MagicMock(
         side_effect=self.pa.evaluate_cancel)
Example #30
0
    def setUp(self):
        self.policy = Policy("Test Policy", date(2015, 1, 1), 1200)
        self.policy.named_insured = self.test_insured.id
        self.policy.agent = self.test_agent.id
        self.policy.billing_schedule = "Quarterly"

        db.session.add(self.policy)
        db.session.commit()

        self.pa = PolicyAccounting(self.policy.id)
        self.payments = []