def insert_data():
    #Contacts
    contacts = []
    john_doe_agent = Contact('John Doe', 'Agent')
    contacts.append(john_doe_agent)
    john_doe_insured = Contact('John Doe', 'Named Insured')
    contacts.append(john_doe_insured)
    bob_smith = Contact('Bob Smith', 'Agent')
    contacts.append(bob_smith)
    anna_white = Contact('Anna White', 'Named Insured')
    contacts.append(anna_white)
    joe_lee = Contact('Joe Lee', 'Agent')
    contacts.append(joe_lee)
    ryan_bucket = Contact('Ryan Bucket', 'Named Insured')
    contacts.append(ryan_bucket)

    for contact in contacts:
        db.session.add(contact)
    db.session.commit()

    policies = []
    p1 = Policy('Policy One', date(2015, 1, 1), 365)
    p1.billing_schedule = 'Annual'
    p1.named_insured = john_doe_insured.id # newly added for problem 6
    p1.agent = bob_smith.id
    policies.append(p1)

    p2 = Policy('Policy Two', date(2015, 2, 1), 1600)
    p2.billing_schedule = 'Quarterly'
    p2.named_insured = anna_white.id
    p2.agent = joe_lee.id
    policies.append(p2)

    p3 = Policy('Policy Three', date(2015, 1, 1), 1200)
    p3.billing_schedule = 'Monthly'
    p3.named_insured = ryan_bucket.id
    p3.agent = john_doe_agent.id
    policies.append(p3)

    # newly added for problem 5
    p4 = Policy( 'Policy Four', date( 2015, 2, 1 ), 500 )
    p4.billing_schedule = 'Two-Pay'
    p4.named_insured = ryan_bucket.id
    p4.agent = john_doe_agent.id
    policies.append(p4)

    for policy in policies:
        db.session.add(policy)
    db.session.commit()

    for policy in policies:
        PolicyAccounting(policy.id)

    payment_for_p2 = Payment(p2.id, anna_white.id, 400, date(2015, 2, 1))
    db.session.add(payment_for_p2)
    db.session.commit()
Exemple #2
0
def make_policy():
    schedules = ["Annual", "Two-Pay", "Quarterly", "Monthly"]
    i_contacts = Contact.query.filter(Contact.role == "Named Insured").all()
    a_contacts = Contact.query.filter(Contact.role == "Agent").all()

    if request.method == "POST":
        #try:
        p_num = request.form['policy_num']
        eff_date = request.form['date']
        bill_schedule = request.form['bill_schedule']
        premium = request.form['premium']
        policy = Policy(p_num, eff_date, premium)

        policy.billing_schedule = bill_schedule

        insured = request.form['insured']
        if insured > 0: # If a 'Named Insured' was selected, tie to policy
            policy.named_insured = insured
        
        agent = request.form['agent']
        policy.agent = agent

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

        # make PolicyAccounting object to initialize invoices
        pa = PolicyAccounting(policy.id)

        return redirect(url_for('getinvoices', p_id=policy.id))

#        except:
#           return render_template('create.html', schedules=schedules, insured_list=i_contacts, agent_list=a_contacts)

    else:
        return render_template('create.html', schedules=schedules, insured_list=i_contacts, agent_list=a_contacts)
Exemple #3
0
def new_policy(policy_number,
               effective_date,
               annual_premium,
               billing_schedule,
               agent=None,
               named_insured=None):

    try:

        # makes a new policy object
        new_policy = Policy(policy_number, effective_date, annual_premium)
        new_policy.billing_schedule = billing_schedule

        # check if a named_insured was passed, if it was passed get the reference object from the db
        if named_insured:
            named_insured_ = Contact.query.filter_by(
                name=named_insured, role="Named Insured").first()

            # if there is not a contact with this name a new one is created
            if not named_insured_:
                contact = Contact(named_insured, 'Named Insured')
                named_insured_ = contact
                db.session.add(contact)
                db.session.commit()
            named_insured = named_insured_.id

        # check if a agent was passed, if it was passed get the reference object from the db
        if agent:
            agent_ = Contact.query.filter_by(name=agent, role="Agent").first()

            # if there is not a contact with this name a new one is created
            if not agent_:
                contact = Contact(agent, 'Agent')
                agent_ = contact
                db.session.add(contact)
                db.session.commit()

            agent = agent_.id

        new_policy.named_insured = named_insured
        new_policy.agent = agent
        db.session.add(new_policy)
        db.session.commit()

    except Exception as error:
        logging.error(error)
def create_policy_four():
    # get contact whose name and Role are John Doe and role respectively
    john_doe_agent = Contact.query.filter_by(name="John Doe",
                                             role="Agent").one()
    # get contact whose name and Role are Ryan Bucket and Name Insured respectively
    ryan_bucket = Contact.query.filter_by(name="Ryan Bucket",
                                          role="Named Insured").one()
    #   create a policy instance for Policy Four with annual amount of $500
    p4 = Policy('Policy Four', date(2015, 2, 1), 500)
    p4.billing_schedule = 'Two-Pay'  # billing schedule
    p4.agent = john_doe_agent.id  # agent
    p4.named_insured = ryan_bucket.id  # named insured

    # save Policy Four to database
    db.session.add(p4)
    db.session.commit()

    # Use PolicyAccounting to create invoice(s) for Policy Four
    PolicyAccounting(p4.id)
    print "Policy Four Created and invoices are generated for it"
Exemple #5
0
def create_policy():
    data = request.json
    try:
        curr_date = datetime.strptime(data['date'], "%Y-%m-%d")
        policy_name = data['policy_name']
        existing_insured = data['existingInsured']
        existing_agent = data['existingAgent']
        insured = data['insured']
        agent = data['agent']
        billing_schedule = data['schedule']
        premium = int(data['premium'])
    except:
        abort(400)

    if not existing_insured:
        new_insured = Contact(insured, 'Named Insured')
        db.session.add(new_insured)
        db.session.commit()
        insured = new_insured.id
    else:
        insured = insured['id']

    if not existing_agent:
        new_agent = Contact(agent, 'Agent')
        db.session.add(new_agent)
        db.session.commit()
        agent = new_agent.id
    else:
        agent = agent['id']

    new_policy = Policy(policy_name, curr_date, premium)
    new_policy.billing_schedule = billing_schedule
    new_policy.named_insured = insured
    new_policy.agent = agent
    db.session.add(new_policy)
    db.session.commit()

    return "All good"
Exemple #6
0
    def test_evaluate_cancellation_pending(self):
        policy = Policy('Test Policy', date(2015, 1, 1), 1200)
        policy.named_insured = self.test_insured.id
        policy.agent = self.test_agent.id
        self.policies.append(policy)
        db.session.add(policy)
        db.session.commit()

        # Get the policy from the database
        policy.billing_schedule = "Annual"
        pa = PolicyAccounting(policy.id)
        # Evaluate status on eff date
        self.assertFalse(pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=date(2015, 1, 1)))
        # Evaluate status on due date
        self.assertFalse(pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=date(2015, 2, 1)))
        # Evaluate status after due date and before cancel date
        self.assertTrue(pa.evaluate_cancellation_pending_due_to_non_pay(date_cursor=date(2015, 2, 2)))

        # Need to test this with a different billing schedule to ensure that overlapping invoices
        # are not causing errors.
        policy.billing_schedule = "Monthly"
        pa.make_invoices()
        # Make a payment
        self.payments.append(pa.make_payment(date_cursor=date(2015, 01, 01), amount=100))
Exemple #7
0
def insert_data():
    #Contacts
    contacts = [] #Contact list to insert into db
    john_doe_agent = Contact('John Doe', 'Agent')
    contacts.append(john_doe_agent)
    john_doe_insured = Contact('John Doe', 'Named Insured')
    contacts.append(john_doe_insured)
    bob_smith = Contact('Bob Smith', 'Agent')
    contacts.append(bob_smith)
    anna_white = Contact('Anna White', 'Named Insured')
    contacts.append(anna_white)
    joe_lee = Contact('Joe Lee', 'Agent')
    contacts.append(joe_lee)
    ryan_bucket = Contact('Ryan Bucket', 'Named Insured')
    contacts.append(ryan_bucket)

    for contact in contacts:
        db.session.add(contact)
    db.session.commit()

    policies = [] #Policy list to insert into db
    p1 = Policy('Policy One', date(2015, 1, 1), 365)
    p1.billing_schedule = 'Annual'
    p1.agent = bob_smith.id
    policies.append(p1)

    p2 = Policy('Policy Three', date(2015, 2, 1), 1200)
    p2.billing_schedule = 'Monthly'
    p2.named_insured = anna_white.id
    p2.agent = joe_lee.id
    policies.append(p2)

    p3 = Policy('Policy Three', date(2015, 1, 1), 1200)
    p3.billing_schedule = 'Monthly'
    p3.named_insured = ryan_bucket.id
    p3.agent = john_doe_agent.id
    policies.append(p3)

    p4 = Policy('Policy Four', date(2015, 2, 1), 500) #creating policy 4 with given information
    p4.billing_schedule = 'Two-Pay'
    p4.name_insured = ryan_bucket.id
    p4.agent = john_doe_agent.id
    policies.append(p4)

    p5 = Policy('Policy Four', date(2015, 2, 1), 500) #Created another policy 4 for Bob Smith's client
    p5.bill_schedule = 'Two-Pay'
    p5.name_insured = john_doe_insured.id
    p5.agent = bob_smith.id
    policies.append(p5)

    for policy in policies:
        db.session.add(policy)
    db.session.commit()

    for policy in policies:
        PolicyAccounting(policy.id)

    payment_for_p2 = Payment(p2.id, anna_white.id, 400, date(2015, 2, 1))
    db.session.add(payment_for_p2)
    db.session.delete(invoice[0]) #Delete old Quarterly invoice
    db.session.commit()