Exemplo n.º 1
0
 def cancel_policy(self,
                   reason: str,
                   date_cursor: Union[str, date, datetime] = None):
     if not date_cursor:
         date_cursor = datetime.now().date()
     self.policy.cancel_reason = reason
     self.policy.cancel_date = date_cursor
     self.policy.status = "Canceled"
     DBSession.add(self.policy)
     DBSession.commit()
     self.policy = None
     print("Policy successfully canceled!")
Exemplo n.º 2
0
    def setUpClass(cls):
        cls.test_agent = Contact("Test Agent", "Agent")
        cls.test_insured = Contact("Test Insured", "Named Insured")
        DBSession.add(cls.test_agent)
        DBSession.add(cls.test_insured)
        DBSession.commit()

        cls.policy = Policy("Test Policy", date(2015, 1, 1), 1200)
        cls.policy.named_insured = cls.test_insured.id
        cls.policy.agent = cls.test_agent.id
        DBSession.add(cls.policy)
        DBSession.commit()
Exemplo n.º 3
0
    def make_payment(
            self,
            contact_id: int = 0,
            date_cursor: Union[str, date, datetime] = None,
            amount: Decimal = Decimal(0),
    ) -> Payment:
        """
        Creates a payment in a given point in time
        :param contact_id:
        :param date_cursor:
        :param amount:
        :return:
        """
        if not date_cursor:
            date_cursor = datetime.now().date()
        due_to_non_pay = self.evaluate_cancellation_pending_due_to_non_pay(
            date_cursor)
        if not contact_id:
            try:
                contact_id = self.policy.named_insured
            except:
                pass

        try:
            contact = DBSession.query(Contact).filter_by(id=contact_id).one()
        except NoResultFound:
            raise NoResultFound("We couldn't find any contact with this id")

        if due_to_non_pay and not contact.role == "Agent":
            raise UserWarning(
                "Policy has passed the due date without being "
                "paid in full, only an agent can't make a payment")

        payment = Payment(self.policy.id, contact_id, amount, date_cursor)
        DBSession.add(payment)
        DBSession.commit()

        return payment
Exemplo n.º 4
0
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:
        DBSession.add(contact)
    DBSession.commit()

    policies = []
    p1 = Policy("Policy One", date(2015, 1, 1), 365)
    p1.billing_schedule = "Annual"
    p1.named_insured = john_doe_insured.id
    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)

    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:
        DBSession.add(policy)
    DBSession.commit()

    for policy in policies:
        PolicyAccounting(policy.id)

    payment_for_p2 = Payment(p2.id, anna_white.id, 400, date(2015, 2, 1))
    DBSession.add(payment_for_p2)
    DBSession.commit()
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
 def tearDown(self):
     for invoice in self.policy.invoices:
         DBSession.delete(invoice)
     for payment in self.payments:
         DBSession.delete(payment)
     DBSession.commit()
Exemplo n.º 7
0
 def tearDownClass(cls):
     DBSession.delete(cls.test_insured)
     DBSession.delete(cls.test_agent)
     DBSession.delete(cls.policy)
     DBSession.commit()
Exemplo n.º 8
0
 def tearDown(self):
     for invoice in self.policy.invoices:
         DBSession.delete(invoice)
     DBSession.commit()