예제 #1
0
class Policy(db.Model):
    __tablename__ = 'policies'

    __table_args__ = {}

    #column definitions
    id = db.Column(u'id', db.INTEGER(), primary_key=True, nullable=False)
    policy_number = db.Column(u'policy_number',
                              db.VARCHAR(length=128),
                              nullable=False)
    effective_date = db.Column(u'effective_date', db.DATE(), nullable=False)
    status = db.Column(u'status',
                       db.Enum(u'Active', u'Canceled', u'Expired'),
                       default=u'Active',
                       nullable=False)
    billing_schedule = db.Column(u'billing_schedule',
                                 db.Enum(u'Annual', u'Two-Pay', u'Quarterly',
                                         u'Monthly'),
                                 default=u'Annual',
                                 nullable=False)
    annual_premium = db.Column(u'annual_premium', db.INTEGER(), nullable=False)
    named_insured = db.Column(u'named_insured', db.INTEGER(),
                              db.ForeignKey('contacts.id'))
    agent = db.Column(u'agent', db.INTEGER(), db.ForeignKey('contacts.id'))
    policy_cancelation_description = db.Column(
        u'policy_cancelation_description', db.TEXT())
    cancelation_date = db.Column(u'cancelation_date', db.DATE())

    def __init__(self, policy_number, effective_date, annual_premium):
        self.policy_number = policy_number
        self.effective_date = effective_date
        self.annual_premium = annual_premium

    invoices = db.relation('Invoice',
                           primaryjoin="Invoice.policy_id==Policy.id")
예제 #2
0
class Payment(db.Model):
    __tablename__ = 'payments'

    __table_args__ = {}

    #column definitions
    id = db.Column(u'id', db.INTEGER(), primary_key=True, nullable=False)
    policy_id = db.Column(u'policy_id',
                          db.INTEGER(),
                          db.ForeignKey('policies.id'),
                          nullable=False)
    contact_id = db.Column(u'contact_id',
                           db.INTEGER(),
                           db.ForeignKey('contacts.id'),
                           nullable=False)
    amount_paid = db.Column(u'amount_paid', db.INTEGER(), nullable=False)
    transaction_date = db.Column(u'transaction_date',
                                 db.DATE(),
                                 nullable=False)

    def __init__(self, policy_id, contact_id, amount_paid, transaction_date):
        self.policy_id = policy_id
        self.contact_id = contact_id
        self.amount_paid = amount_paid
        self.transaction_date = transaction_date
예제 #3
0
class PolicyCancellation(db.Model):
    __tablename__ = 'policy_cancellations'

    __table_args__ = {}

    # column definitions
    policy_id = db.Column(u'policy_id',
                          db.ForeignKey('policies.id'),
                          primary_key=True)
    # Why was this policy cancelled
    reason = db.Column(u'reason',
                       db.Enum(u'Nonpayment', u'Underwriting', u'Client'),
                       nullable=False)
    date = db.Column(u'date', db.DATE(), nullable=False)
    notes = db.Column(u'notes',
                      db.VARCHAR(length=256),
                      nullable=False,
                      default='')

    def __init__(self, policy_id, reason, date, notes=None):
        self.policy_id = policy_id
        self.reason = reason
        self.date = date
        if notes is not None:
            self.notes = notes
예제 #4
0
class Contact(db.Model):
    __tablename__ = 'contacts'

    __table_args__ = {}

    #column definitions
    id = db.Column(u'id', db.INTEGER(), primary_key=True, nullable=False)
    name = db.Column(u'name', db.VARCHAR(length=128), nullable=False)
    role = db.Column(u'role', db.Enum(u'Named Insured', u'Agent'), nullable=False)

    def __init__(self, name, role):
        self.name = name
        self.role = role
예제 #5
0
class Policy(db.Model):
    __tablename__ = 'policies'

    __table_args__ = {}

    # column definitions
    id = db.Column(u'id', db.INTEGER(), primary_key=True, nullable=False)
    policy_number = db.Column(u'policy_number',
                              db.VARCHAR(length=128),
                              nullable=False)
    effective_date = db.Column(u'effective_date', db.DATE(), nullable=False)
    status = db.Column(u'status',
                       db.Enum(u'Active', u'Canceled', u'Expired'),
                       default=u'Active',
                       nullable=False)
    billing_schedule = db.Column(u'billing_schedule',
                                 db.Enum(u'Annual', u'Two-Pay', u'Quarterly',
                                         u'Monthly'),
                                 default=u'Annual',
                                 nullable=False)
    annual_premium = db.Column(u'annual_premium', db.INTEGER(), nullable=False)
    named_insured = db.Column(u'named_insured', db.INTEGER(),
                              db.ForeignKey('contacts.id'))
    agent = db.Column(u'agent', db.INTEGER(), db.ForeignKey('contacts.id'))

    cancel_description = db.Column(u'cancel_description',
                                   db.VARCHAR(length=128),
                                   nullable=True)
    cancel_date = db.Column(u'cancel_date', db.DATE(), nullable=True)

    def __init__(self, policy_number, effective_date, annual_premium):
        self.policy_number = policy_number
        self.effective_date = effective_date
        self.annual_premium = annual_premium

    invoices = db.relation('Invoice',
                           primaryjoin="Invoice.policy_id==Policy.id")

    @property
    def invoices_dict(self):
        invoices = Invoice.query.filter_by(policy_id=self.id) \
            .order_by(Invoice.bill_date) \
            .all()

        invoices_dict = [
            dict(amount_due=invoice.amount_due,
                 bill_date=str(invoice.bill_date),
                 due_date=str(invoice.due_date)) for invoice in invoices
        ]
        print(invoices_dict)
        return invoices_dict
예제 #6
0
class Contact(db.Model):
    __tablename__ = "contacts"

    __table_args__ = {}

    # column definitions
    id = db.Column(u"id", db.INTEGER(), primary_key=True, nullable=False)
    name = db.Column(u"name", db.VARCHAR(length=128), nullable=False)
    role = db.Column(u"role",
                     db.Enum(u"Named Insured", u"Agent"),
                     nullable=False)

    def __init__(self, name, role):
        self.name = name
        self.role = role
예제 #7
0
class Cancelled_Policy(db.Model):
    __tablename__ = 'cancelled_policies'

    __table_args__ = {}

    id = db.Column(u'id', db.INTEGER(), primary_key=True, nullable=False)
    policy_id = db.Column(u'policy_id', db.INTEGER(), db.ForeignKey('policies.id'), nullable=False)
    policy_number = db.Column(u'policy_number', db.VARCHAR(length=128), nullable=False)
    cancellation_date = db.Column(u'cancellation_date', db.DATE(), nullable=False)
    cancellation_reason = db.Column(u'cancellation_reason', db.VARCHAR(length=128), default=u'No payment received', nullable=False)

    def __init__(self, policy_id, policy_number, cancellation_date, cancellation_reason):
        self.policy_id = policy_id
        self.policy_number = policy_number
        self.cancellation_date = cancellation_date
        self.cancellation_reason = cancellation_reason
예제 #8
0
class Invoice(db.Model):
    __tablename__ = 'invoices'

    __table_args__ = {}

    #column definitions
    id = db.Column(u'id', db.INTEGER(), primary_key=True, nullable=False)
    policy_id = db.Column(u'policy_id',
                          db.INTEGER(),
                          db.ForeignKey('policies.id'),
                          nullable=False)
    bill_date = db.Column(u'bill_date', db.DATE(), nullable=False)
    due_date = db.Column(u'due_date', db.DATE(), nullable=False)
    cancel_date = db.Column(u'cancel_date', db.DATE(), nullable=False)
    amount_due = db.Column(u'amount_due', db.INTEGER(), nullable=False)
    deleted = db.Column(u'deleted',
                        db.Boolean,
                        default=False,
                        server_default='0',
                        nullable=False)

    def __init__(self, policy_id, bill_date, due_date, cancel_date,
                 amount_due):
        self.policy_id = policy_id
        self.bill_date = bill_date
        self.due_date = due_date
        self.cancel_date = cancel_date
        self.amount_due = amount_due
예제 #9
0
class Invoice(db.Model):
    __tablename__ = "invoices"

    __table_args__ = {}

    # column definitions
    id = db.Column(u"id", db.INTEGER(), primary_key=True, nullable=False)
    policy_id = db.Column(u"policy_id",
                          db.INTEGER(),
                          db.ForeignKey("policies.id"),
                          nullable=False)
    bill_date = db.Column(u"bill_date", db.DATE(), nullable=False)
    due_date = db.Column(u"due_date", db.DATE(), nullable=False)
    cancel_date = db.Column(u"cancel_date", db.DATE(), nullable=False)
    amount_due = db.Column(u"amount_due", db.INTEGER(), nullable=False)
    deleted = db.Column(u"deleted",
                        db.Boolean,
                        default=False,
                        server_default="0",
                        nullable=False)

    def __init__(self, policy_id, bill_date, due_date, cancel_date,
                 amount_due):
        self.policy_id = policy_id
        self.bill_date = bill_date
        self.due_date = due_date
        self.cancel_date = cancel_date
        self.amount_due = amount_due
예제 #10
0
class Policy(db.Model, Serializable):
    __tablename__ = 'policies'

    __table_args__ = {}

    serializable_cols = {
        'id', 'policy_number', 'effective_date', 'status', 'billing_schedule',
        'annual_premium', 'named_insured', 'agent'
    }

    #column definitions
    id = db.Column(u'id', db.INTEGER(), primary_key=True, nullable=False)
    policy_number = db.Column(u'policy_number',
                              db.VARCHAR(length=128),
                              nullable=False)
    effective_date = db.Column(u'effective_date', db.DATE(), nullable=False)
    status = db.Column(u'status',
                       db.Enum(u'Active', u'Canceled', u'Expired'),
                       default=u'Active',
                       nullable=False)
    billing_schedule = db.Column(u'billing_schedule',
                                 db.Enum(u'Annual', u'Two-Pay', u'Quarterly',
                                         u'Monthly'),
                                 default=u'Annual',
                                 nullable=False)
    annual_premium = db.Column(u'annual_premium', db.INTEGER(), nullable=False)
    named_insured = db.Column(u'named_insured', db.INTEGER(),
                              db.ForeignKey('contacts.id'))
    agent = db.Column(u'agent', db.INTEGER(), db.ForeignKey('contacts.id'))

    def __init__(self, policy_number, effective_date, annual_premium):
        self.policy_number = policy_number
        self.effective_date = effective_date
        self.annual_premium = annual_premium

    @property
    def cancelled(self):
        return self.cancellation is not None

    invoices = db.relation('Invoice',
                           primaryjoin="Invoice.policy_id==Policy.id")
    cancellation = db.relation('PolicyCancellation',
                               backref="policy",
                               uselist=False)
    agent_relation = db.relation('Contact',
                                 primaryjoin="Contact.id == Policy.agent",
                                 uselist=False)
    named_insured_relation = db.relation(
        'Contact',
        primaryjoin="Contact.id == Policy.named_insured",
        uselist=False)
예제 #11
0
class CancelPolicy(db.Model):
    __tablename__ = "canceled"

    __table_args__ = {}

    # column definitions
    id = db.Column(u'id', db.INTEGER(), primary_key=True, nullable=False)
    policy_id = db.Column(u'policy_id',
                          db.INTEGER(),
                          db.ForeignKey('policies.id'),
                          nullable=False)
    cancel_reason = db.Column(u' cancel_reason',
                              db.String(150),
                              nullable=False)
    canceled_by = db.Column(u'cancel_by', db.String(50), nullable=False)
    cancel_date = db.Column(u'cancel_date', db.DATE(), nullable=False)

    def __init__(self, policy_id, cancel_reason, canceled_by, cancel_date):
        self.policy_id = policy_id
        self.cancel_reason = cancel_reason
        self.canceled_by = canceled_by
        self.cancel_date = cancel_date
예제 #12
0
class Policy(db.Model):
    __tablename__ = "policies"

    __table_args__ = {}

    # column definitions
    id = db.Column(u"id", db.INTEGER(), primary_key=True, nullable=False)
    policy_number = db.Column(u"policy_number",
                              db.VARCHAR(length=128),
                              nullable=False)
    effective_date = db.Column(u"effective_date", db.DATE(), nullable=False)
    status = db.Column(
        u"status",
        db.Enum(u"Active", u"Canceled", u"Expired"),
        default=u"Active",
        nullable=False,
    )
    status_change_description = db.Column(u"status_change_description",
                                          db.VARCHAR(length=128))
    status_change_date = db.Column(u"status_change_date", db.DATE())
    billing_schedule = db.Column(
        u"billing_schedule",
        db.Enum(u"Annual", u"Two-Pay", u"Quarterly", u"Monthly"),
        default=u"Annual",
        nullable=False,
    )
    annual_premium = db.Column(u"annual_premium", db.INTEGER(), nullable=False)
    named_insured = db.Column(u"named_insured", db.INTEGER(),
                              db.ForeignKey("contacts.id"))
    agent = db.Column(u"agent", db.INTEGER(), db.ForeignKey("contacts.id"))

    def __init__(self, policy_number, effective_date, annual_premium):
        self.policy_number = policy_number
        self.effective_date = effective_date
        self.annual_premium = annual_premium

    invoices = db.relation("Invoice",
                           primaryjoin="Invoice.policy_id==Policy.id")
예제 #13
0
class Policy(db.Model):
    __tablename__ = 'policies'

    __table_args__ = {}

    #column definitions
    id = db.Column(u'id', db.INTEGER(), primary_key=True, nullable=False)
    policy_number = db.Column(u'policy_number', db.VARCHAR(length=128), nullable=False)
    effective_date = db.Column(u'effective_date', db.DATE(), nullable=False)
    status = db.Column(u'status', db.Enum(u'Active', u'Canceled', u'Expired'), default=u'Active', nullable=False)
    billing_schedule = db.Column(u'billing_schedule', db.Enum(u'Annual', u'Two-Pay', u'Quarterly', u'Monthly'), default=u'Annual', nullable=False)
    annual_premium = db.Column(u'annual_premium', db.INTEGER(), nullable=False)
    named_insured = db.Column(u'named_insured', db.INTEGER(), db.ForeignKey('contacts.id'), nullable=False)
    agent = db.Column(u'agent', db.INTEGER(), db.ForeignKey('contacts.id'))
    cancel_date = db.Column(u'cancel_date', db.DATE())
    cancel_desc = db.Column(u'cancel_desc', db.VARCHAR(length=128))

    def __init__(self, policy_number, effective_date, annual_premium):
        self.policy_number = policy_number
        self.effective_date = effective_date
        self.annual_premium = annual_premium

    def serialize(self):
        return {
                 'id': self.id,
                 'policy_number': self.policy_number,
                 'effective_date': str(self.effective_date),
                 'status': self.status,
                 'cancel_date': str(self.cancel_date),
                 'cancel_desc': self.cancel_desc,
                 'billing_schedule': self.billing_schedule,
                 'annual_premium': self.annual_premium,
                 'named_insured': self.named_insured,
                 'agent': self.agent,
                 'invoices': [i.serialize() for i in self.invoices if not i.deleted]
        }

    invoices = db.relation('Invoice', primaryjoin="Invoice.policy_id==Policy.id")
예제 #14
0
파일: models.py 프로젝트: arcegk/policyTest
class Cancelation(db.Model):
    __tablename__ = 'cancelations'

    __table_args__ = {}

    id = db.Column(u'id', db.INTEGER(), primary_key=True, nullable=False)
    policy_id = db.Column(u'policy_id',
                          db.INTEGER(),
                          db.ForeignKey('policies.id'),
                          nullable=False)
    description = db.Column(u'description',
                            db.TEXT(),
                            default='',
                            nullable=False)
    cancelation_date = db.Column(u'cancelation_date',
                                 db.DATE(),
                                 nullable=False)

    def __init__(self, policy_id, description, cancelation_date=None):
        if not cancelation_date:
            cancelation_date = datetime.datetime.now().date()
        self.cancelation_date = cancelation_date
        self.policy_id = policy_id
        self.description = description
예제 #15
0
파일: models.py 프로젝트: arcegk/policyTest
class Invoice(db.Model):
    __tablename__ = 'invoices'

    __table_args__ = {}

    #column definitions
    id = db.Column(u'id', db.INTEGER(), primary_key=True, nullable=False)
    policy_id = db.Column(u'policy_id',
                          db.INTEGER(),
                          db.ForeignKey('policies.id'),
                          nullable=False)
    bill_date = db.Column(u'bill_date', db.DATE(), nullable=False)
    due_date = db.Column(u'due_date', db.DATE(), nullable=False)
    cancel_date = db.Column(u'cancel_date', db.DATE(), nullable=False)
    amount_due = db.Column(u'amount_due', db.INTEGER(), nullable=False)
    deleted = db.Column(u'deleted',
                        db.Boolean,
                        default=False,
                        server_default='0',
                        nullable=False)

    def __init__(self, policy_id, bill_date, due_date, cancel_date,
                 amount_due):
        self.policy_id = policy_id
        self.bill_date = bill_date
        self.due_date = due_date
        self.cancel_date = cancel_date
        self.amount_due = amount_due

    def delete(self):
        self.deleted = True
        db.session.add(self)
        db.session.commit()

    @property
    def serialize(self):
        return {
            'id': self.id,
            'bill_date': str(self.bill_date),
            'due_date': str(self.due_date),
            'amount_due': self.amount_due
        }