def get_invoices(p_id): invoices = Invoice.query.filter_by(policy_id = p_id).all() payments = Payment.query.filter_by(policy_id = p_id).all() pa = PolicyAccounting(p_id) date_cursor = invoices[len(invoices)-1].cancel_date amt = pa.return_account_balance(date_cursor) return render_template('index.html', invoices=invoices, payments=payments, balance=amt)
def get_invoices(): if request.method == 'POST': #pull information from form submission policy_number = request.form['policy_number'] date_cursor = request.form['date'] #filter to policy number that was submitted policy = Policy.query.filter(Policy.policy_number == policy_number).first() if policy: pa = PolicyAccounting(policy.id) #filter invoices to policy that was submitted invoices = Invoice.query.filter(Invoice.policy_id == policy.id)\ .filter(Invoice.deleted != 1).all() #filter paid invoices payments = Payment.query.filter(Payment.policy_id == policy.id).all() paid = len(payments) account_balance = pa.return_account_balance(date_cursor) return render_template('index.html', display=True, balance=account_balance, date=date_cursor, policy=policy_number,invoices=invoices, paid=paid) else: error = "Sorry the policy you entered may not exist." return render_template('index.html', display=False, error=error) else: error = "Error: Please try again!" return render_template('index.html', error=error)
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_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)
def test_non_agent_payment_on_annual_with_cancellation_pending(self): self.policy.billing_schedule = "Annual" pa = PolicyAccounting(self.policy.id) invoice = pa.policy.invoices[0] p = pa.make_payment(contact_id=self.policy.named_insured, date_cursor=invoice.due_date+relativedelta(days=21), amount=100) self.assertFalse(p)
def test_cancel_policy(self): """ Test to see if descriptive_cancel_policy successfully cancels policy in database. """ pa = PolicyAccounting(self.policy.id) pa.descriptive_cancel_policy("This policy is canceled.") self.assertEquals(self.policy.description, "This policy is canceled.") self.assertEquals(self.policy.cancel_date, datetime.now().date()) self.assertEquals(self.policy.status, "Canceled")
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)
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() payment = pa.make_payment(contact_id=self.policy.named_insured, date_cursor=invoices[1].bill_date, amount=600) if payment: self.payments.append(payment) # should be None, but keep track of it just in case # self.assertEquals(pa.return_account_balance(date_cursor=invoices[1].bill_date), 0) --original test, fails # new test, a better test that ensures the payment didn't go through self.assertEquals(pa.return_account_balance(date_cursor=invoices[1].bill_date), pa.policy.annual_premium/2)
def test_change_billing_schedule(self): p1 = Policy('Test Policy', date(2015, 01, 01), 500) p1.billing_schedule = 'Quarterly' db.session.add(p1) db.session.commit() pa = PolicyAccounting(p1.id) self.assertEquals(len(pa.policy.invoices), 4) self.assertEquals(pa.policy.invoices[0].amount_due, pa.policy.annual_premium / 4) pa.change_billing_schedule('Monthly') #filters out deleted invoices active_invoices = Invoice.query.filter_by(policy_id = pa.policy.id)\ .filter(Invoice.deleted != 1)\ .all() self.assertEquals(len(active_invoices), 12) self.assertEquals(active_invoices[0].amount_due, pa.policy.annual_premium / 12)
def test_monthly_billing_schedule(self): self.policy.billing_schedule = "Monthly" self.assertFalse(self.policy.invoices) pa = PolicyAccounting(self.policy.id) self.assertEquals(len(self.policy.invoices), 12) #assertEquals is the test self.assertEquals(self.policy.invoices[0].amount_due, self.policy.annual_premium / 12)
def test_annual_billing_schedule(self): self.policy.billing_schedule = "Annual" #No invoices currently exist self.assertFalse(self.policy.invoices) #Invoices should be made when the class is initiated pa = PolicyAccounting(self.policy.id) self.assertEquals(len(self.policy.invoices), 1) self.assertEquals(self.policy.invoices[0].amount_due, self.policy.annual_premium)
def index(): # You will need to serve something up here. if request.method == 'POST': policy_num = request.form['policy_num'] date_cursor = request.form['date'] policy = Policy.query.filter(Policy.policy_number == policy_num).one() invoices = Invoice.query.filter_by(policy_id = policy.id)\ .filter(Invoice.bill_date <= date_cursor)\ .filter(Invoice.deleted == False)\ .all() payments = Payment.query.filter_by(policy_id = policy.id)\ .filter(Payment.transaction_date <= date_cursor)\ .all() pa = PolicyAccounting(policy.id) amt = pa.return_account_balance(date_cursor) return render_template('index.html', policy_number=policy_num, date_posted=date_cursor, invoices=invoices, payments=payments, balance=amt) else: return render_template('index.html', invoices = [], payments = [])
def view_policy(): policy_number = request.args['policy_number'] date = request.args['date'] date = datetime.datetime.strptime(date, '%Y%m%d').date() policy = Policy.query.filter_by(policy_number=policy_number).one() pa = PolicyAccounting(policy.id) if policy is None: abort(404) return render_template('view-policy.html', policy=policy, date=date, pa=pa)
def test_quarterly_on_eff_date(self): self.policy.billing_schedule = "Quarterly" pa = PolicyAccounting(self.policy.id) self.assertEquals(pa.return_account_balance(date_cursor=self.policy.effective_date), 300)
def test_annual_on_eff_date(self): self.policy.billing_schedule = "Annual" pa = PolicyAccounting(self.policy.id) self.assertEquals(pa.return_account_balance(date_cursor=self.policy.effective_date), 1200)
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_quarterly_on_eff_date(self): self.policy.billing_schedule = "Quarterly" pa = PolicyAccounting(self.policy.id) self.assertEquals( pa.return_account_balance(date_cursor=self.policy.effective_date), 300)
def test_annual_on_eff_date(self): self.policy.billing_schedule = "Annual" pa = PolicyAccounting(self.policy.id) self.assertEquals( pa.return_account_balance(date_cursor=self.policy.effective_date), 1200)