Various tweaks for str(model) etc.

This commit is contained in:
Lance Edgar 2018-11-22 12:19:24 -06:00
parent abc291463f
commit b1e27a6caf

View file

@ -26,6 +26,7 @@ CORE POS Data Model
from __future__ import unicode_literals, absolute_import from __future__ import unicode_literals, absolute_import
import six
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
@ -35,6 +36,7 @@ from sqlalchemy.ext.associationproxy import association_proxy
Base = declarative_base() Base = declarative_base()
@six.python_2_unicode_compatible
class Department(Base): class Department(Base):
""" """
Represents a department within the organization. Represents a department within the organization.
@ -67,7 +69,11 @@ class Department(Base):
memberOnly = sa.Column(sa.SmallInteger(), nullable=False, default=0) 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): class Subdepartment(Base):
""" """
Represents a subdepartment within the organization. Represents a subdepartment within the organization.
@ -88,7 +94,11 @@ class Subdepartment(Base):
Reference to the parent :class:`Department` for this subdepartment. 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): class Vendor(Base):
""" """
Represents a vendor from which product may be purchased. Represents a vendor from which product may be purchased.
@ -129,8 +139,8 @@ class Vendor(Base):
'contact', 'notes', 'contact', 'notes',
creator=lambda n: VendorContact(notes=n)) creator=lambda n: VendorContact(notes=n))
def __unicode__(self): def __str__(self):
return unicode(self.vendorName) return self.vendorName or ''
class VendorContact(Base): class VendorContact(Base):
@ -152,11 +162,15 @@ class VendorContact(Base):
notes = sa.Column(sa.Text(), nullable=True) notes = sa.Column(sa.Text(), nullable=True)
@six.python_2_unicode_compatible
class Product(Base): class Product(Base):
""" """
Represents a product, purchased and/or sold by the organization. Represents a product, purchased and/or sold by the organization.
""" """
__tablename__ = 'products' __tablename__ = 'products'
__table_args__ = (
sa.ForeignKeyConstraint(['department'], ['departments.dept_no']),
)
id = sa.Column(sa.Integer(), primary_key=True, autoincrement=True, nullable=False) id = sa.Column(sa.Integer(), primary_key=True, autoincrement=True, nullable=False)
@ -263,8 +277,8 @@ class Product(Base):
fields = filter(bool, fields) fields = filter(bool, fields)
return ' '.join(fields) return ' '.join(fields)
def __unicode__(self): def __str__(self):
return self.full_description return self.description or ''
class Employee(Base): class Employee(Base):
@ -325,10 +339,10 @@ class Customer(Base):
personNum = sa.Column(sa.SmallInteger(), nullable=False, default=1) 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) 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) CashBack = sa.Column(sa.Float(), nullable=False, default=60)
Balance = sa.Column(sa.Float(), nullable=False, default=0) Balance = sa.Column(sa.Float(), nullable=False, default=0)