Example #1
0
 def test_quarterly_on_last_installment_bill_date(self):
     self.policy.billing_schedule = "Quarterly"
     pa = PolicyAccounting(self.policy.id)
     invoices = (DBSession.query(Invoice).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)
Example #2
0
def policies():
    invoices_dict = []
    policies_dict = []
    policy = None
    date = None
    account_balance = 0

    if request.data:
        data = json.loads(request.data)
        if ('date' in data):
            date = data['date']

        print(data)
        if ('policy_number' in data):
            if data['policy_number']:
                try:
                    policy = Policy.query.filter_by(policy_number=data['policy_number']).one()
                    # Find Policy Accouning object & return account balance based on the provided date.
                    pa = PolicyAccounting(policy.id)
                    account_balance = pa.return_account_balance(date)
                except:
                    return jsonify(status=404, message=['Policy not found. \n Please try a different policy number.'])

    if policy:
        policies_dict = [dict(policy_number=policy.policy_number, effective_date=str(policy.effective_date))]
        invoices_dict = policy.invoices_dict

        return jsonify(status=200, message=['Policy found'], policies=policies_dict, invoices=invoices_dict,
                       account_balances=[{'account_balance': 'Account balance: {}'.format(
                           locale.currency(account_balance, grouping=True))}])
    else:
        return jsonify(status=404, message=['Policy not found. \n Please try a different policy number.'])
Example #3
0
def getPolicyByIdAndDate(id, date):

    try:
        # Validate date format
        dateTime = datetime.strptime(date, "%Y-%m-%d")
    except ValueError as error:
        return Response("Please enter a valid date format mm/dd/yyyy", status=404)

    try:
        id = int(id)
    except ValueError:
        return Response("Policy Id must be an int")

    try:
        # Get policy
        policy = Policy.query.filter_by(id=id).one()
    except sqlalchemy.orm.exc.NoResultFound as error:
        # Print not found
        return Response(None)

    try:
        # Get insured name
        insured = Contact.query.filter_by(id=policy.named_insured).one()
    except sqlalchemy.orm.exc.NoResultFound as error:
        return Response("Insured not found!", status=404)

    # Get agent name
    try:
        agent = Contact.query.filter_by(id=policy.agent).one()
    except sqlalchemy.orm.exc.NoResultFound as error:
        return Response("Agent not found!", status=404)

    # Serialize policy
    response = policy.serialize()

    # get policy accounting object and account balance
    pa = PolicyAccounting(policy.id)
    balance = pa.return_account_balance(dateTime)
    response['balance'] = balance

    # Add agent and insured names to response.
    response['agent_name'] = agent.name
    response['insured'] = insured.name

    # Get all payments for policy
    payments = Payment.query.filter_by(policy_id=policy.id).all()

    # Add payments
    all_payments = []
    for payment in payments:
        # Serialize payment and add to payments
        payment_response = payment.serialize()
        all_payments.append(payment_response)

    # Add payments to response.
    response['payments'] = all_payments

    return jsonify(response)
Example #4
0
 def test_quarterly_on_second_installment_bill_date_with_full_payment(self):
     self.policy.billing_schedule = "Quarterly"
     pa = PolicyAccounting(self.policy.id)
     invoices = (DBSession.query(Invoice).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 #5
0
 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)
Example #6
0
def get_tasks():
    policy_number = request.args.get("policy_number", None)
    try:
        date_cursor = datetime.strptime(request.args.get("date_cursor", None),
                                        "%Y-%m-%d")
    except ValueError:
        raise InvalidUsage("Bad date format", status_code=400)
    try:
        policy = (DBSession.query(Policy).filter(
            Policy.policy_number == policy_number).one())
    except NoResultFound:
        raise InvalidUsage("Policy Not Found", status_code=404)
    invoices = policy.invoices
    pa = PolicyAccounting(policy.id)
    balance = pa.return_account_balance(date_cursor=date_cursor)
    data = {
        "balance": str(balance),
        "invoices": [i.serialize() for i in invoices]
    }
    return jsonify(data)
 def setUp(self):
     pa = PolicyAccounting(self.policy.id)
Example #8
0
 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)
Example #9
0
 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)