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) cancel_code = db.Column(u'cancel_code', db.Enum(u'Non-Pay', u'Underwriting', u'Insured Request'), nullable=True) cancel_description = db.Column(u'cancel_description', db.VARCHAR(length=255), nullable=True) cancel_date = db.Column(u'cancel_date', db.DATE(), nullable=True) 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") payments = db.relation('Payment', primaryjoin="Payment.policy_id==Policy.id") insured = db.relation('Contact', primaryjoin="Contact.id==Policy.named_insured")
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)
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')) cancelation_date = db.Column(u'cancelation_date', db.DATE(), nullable=True) cancellation_description = db.Column(u'cancellation_description', db.VARCHAR(length=128), nullable=True) cancelation_reason = db.Column(u'cancelation_reason', db.Enum(u'underwriting', u'unpaid', u'unauthorized'), 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 def serialize(self): return { 'id': self.id, 'policy_number': self.policy_number, 'effective_date': str(self.effective_date), 'cancelation_date': str(self.cancelation_date), 'status': self.status, '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] } invoices = db.relation('Invoice', primaryjoin="Invoice.policy_id==Policy.id")
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
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')) termination_date = db.Column(u'termination_date', db.DATE()) termination_comments = db.Column(u'termination_comments', db.TEXT()) 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", order_by="Invoice.deleted, Invoice.bill_date") payments = db.relation('Payment', primaryjoin="Payment.policy_id==Policy.id", order_by="Payment.transaction_date")
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) contact = db.relation('Contact', primaryjoin="Payment.contact_id==Contact.id") 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
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')) 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="and_(Invoice.policy_id==Policy.id, Invoice.deleted==False)" ) def cancel(self, description=None, cancelation_date=None): if not description: description = '' self.status = u'Canceled' cancelation = Cancelation(self.id, description, cancelation_date) db.session.add(self) db.session.add(cancelation) db.session.commit()
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) date_changed = db.Column(u'date_changed', db.DATE(), nullable=True, default=None) reason = db.Column(u'reason', db.VARCHAR(length=300), nullable=True, default='') 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 self.monthly_premium = annual_premium / 12 invoices = db.relation('Invoice', primaryjoin="Invoice.policy_id==Policy.id")
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")