Add LikeCode and ProductLikeCode models

This commit is contained in:
Lance Edgar 2020-04-10 14:09:38 -05:00
parent 87fd5367a1
commit 4b971c289e

View file

@ -270,6 +270,41 @@ class TaxRateComponent(Base):
description = sa.Column(sa.String(length=50), nullable=True) description = sa.Column(sa.String(length=50), nullable=True)
def __str__(self):
return self.description or ""
class LikeCode(Base):
"""
Represents a "like code" for sake of product pricing.
"""
__tablename__ = 'likeCodes'
likeCode = sa.Column(sa.Integer(), primary_key=True, autoincrement=False, nullable=False)
id = orm.synonym('likeCode')
description = sa.Column('likeCodeDesc', sa.String(length=50), nullable=True)
strict = sa.Column(sa.Boolean(), nullable=True, default=False)
organic = sa.Column(sa.Boolean(), nullable=True, default=False)
preferred_vendor_id = sa.Column('preferredVendorID', sa.Integer(), nullable=True, default=0)
multi_vendor = sa.Column('multiVendor', sa.Boolean(), nullable=True, default=False)
sort_retail = sa.Column('sortRetail', sa.String(length=255), nullable=True)
sort_internal = sa.Column('sortInternal', sa.String(length=255), nullable=True)
products = association_proxy(
'_products', 'product',
creator=lambda p: ProductLikeCode(product=p),
)
def __str__(self):
return self.description or ""
class Product(Base): class Product(Base):
""" """
@ -388,6 +423,11 @@ class Product(Base):
current_origin_id = sa.Column(sa.Integer(), nullable=True, default=0) current_origin_id = sa.Column(sa.Integer(), nullable=True, default=0)
like_code = association_proxy(
'_like_code', 'like_code',
creator=lambda lc: ProductLikeCode(like_code=lc),
)
@property @property
def full_description(self): def full_description(self):
fields = ['brand', 'description', 'size'] fields = ['brand', 'description', 'size']
@ -399,6 +439,42 @@ class Product(Base):
return self.description or '' return self.description or ''
class ProductLikeCode(Base):
"""
Represents the association between a product and like code.
"""
__tablename__ = 'upcLike'
__table_args__ = (
sa.ForeignKeyConstraint(['likeCode'], ['likeCodes.likeCode']),
)
upc = sa.Column(sa.String(length=13), primary_key=True, nullable=False)
product = orm.relationship(
Product,
primaryjoin=Product.upc == orm.foreign(upc),
doc="""
Reference to the product to which this association applies.
""",
backref=orm.backref(
'_like_code',
uselist=False,
doc="""
Reference to the like code association for the product.
"""))
like_code_id = sa.Column('likeCode', sa.Integer(), nullable=True)
like_code = orm.relationship(
LikeCode,
doc="""
Reference to the LikeCode to which this association applies.
""",
backref=orm.backref(
'_products',
doc="""
List of product associations for this like code.
"""))
class ProductFlag(Base): class ProductFlag(Base):
""" """
Represents a product flag attribute. Represents a product flag attribute.