From b1e27a6caf08d953d65524b952d40e60fdc68bdf Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 22 Nov 2018 12:19:24 -0600 Subject: [PATCH] Various tweaks for `str(model)` etc. --- corepos/db/model.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/corepos/db/model.py b/corepos/db/model.py index fa1ec5e..ad74a0f 100644 --- a/corepos/db/model.py +++ b/corepos/db/model.py @@ -26,6 +26,7 @@ CORE POS Data Model from __future__ import unicode_literals, absolute_import +import six import sqlalchemy as sa from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship @@ -35,6 +36,7 @@ from sqlalchemy.ext.associationproxy import association_proxy Base = declarative_base() +@six.python_2_unicode_compatible class Department(Base): """ Represents a department within the organization. @@ -67,7 +69,11 @@ class Department(Base): memberOnly = sa.Column(sa.SmallInteger(), nullable=False, default=0) + def __str__(self): + return self.dept_name or '' + +@six.python_2_unicode_compatible class Subdepartment(Base): """ Represents a subdepartment within the organization. @@ -88,7 +94,11 @@ class Subdepartment(Base): Reference to the parent :class:`Department` for this subdepartment. """) + def __str__(self): + return self.subdept_name or '' + +@six.python_2_unicode_compatible class Vendor(Base): """ Represents a vendor from which product may be purchased. @@ -129,8 +139,8 @@ class Vendor(Base): 'contact', 'notes', creator=lambda n: VendorContact(notes=n)) - def __unicode__(self): - return unicode(self.vendorName) + def __str__(self): + return self.vendorName or '' class VendorContact(Base): @@ -152,11 +162,15 @@ class VendorContact(Base): notes = sa.Column(sa.Text(), nullable=True) +@six.python_2_unicode_compatible class Product(Base): """ Represents a product, purchased and/or sold by the organization. """ __tablename__ = 'products' + __table_args__ = ( + sa.ForeignKeyConstraint(['department'], ['departments.dept_no']), + ) id = sa.Column(sa.Integer(), primary_key=True, autoincrement=True, nullable=False) @@ -263,8 +277,8 @@ class Product(Base): fields = filter(bool, fields) return ' '.join(fields) - def __unicode__(self): - return self.full_description + def __str__(self): + return self.description or '' class Employee(Base): @@ -325,10 +339,10 @@ class Customer(Base): personNum = sa.Column(sa.SmallInteger(), nullable=False, default=1) - LastName = sa.Column(sa.String(length=30), nullable=True) - FirstName = sa.Column(sa.String(length=30), nullable=True) + LastName = sa.Column(sa.String(length=30), nullable=True) + CashBack = sa.Column(sa.Float(), nullable=False, default=60) Balance = sa.Column(sa.Float(), nullable=False, default=0)