Clean up Product model code a bit

This commit is contained in:
Lance Edgar 2016-12-14 22:05:29 -06:00
parent 874ba69813
commit 3d6ee12c0f
2 changed files with 49 additions and 54 deletions

View file

@ -106,11 +106,6 @@ class Family(Base):
code = sa.Column(sa.Integer())
name = sa.Column(sa.String(length=50))
products = relationship(
u'Product', back_populates=u'family', doc=u"""\
Collection of :class:`Product` instances which associate with this family.
""")
def __unicode__(self):
return unicode(self.name or '')
@ -129,11 +124,6 @@ class ReportCode(Base):
code = sa.Column(sa.Integer(), nullable=False)
name = sa.Column(sa.String(length=100), nullable=True)
products = relationship(
u'Product', back_populates=u'report_code', doc=u"""\
Collection of :class:`Product` instances which associate with this report code.
""")
def __unicode__(self):
if not self.code:
return ''

View file

@ -103,22 +103,22 @@ class Product(Base):
""")
deposit_link_uuid = sa.Column(sa.String(length=32), nullable=True, doc="""
UUID of the product's deposit link, if any.
""")
UUID of the product's deposit link, if any.
""")
deposit_link = orm.relationship('DepositLink', doc="""
Reference to the :class:`DepositLink` instance with which the product
associates, if any.
""")
Reference to the :class:`DepositLink` instance with which the product
associates, if any.
""")
tax_uuid = sa.Column(sa.String(length=32), nullable=True, doc="""
UUID of the product's tax, if any.
""")
UUID of the product's tax, if any.
""")
tax = orm.relationship(Tax, doc="""
Reference to the :class:`Tax` instance with which the product associates, if
any.
""")
Reference to the :class:`Tax` instance with which the product associates, if
any.
""")
brand_uuid = sa.Column(sa.String(length=32))
description = sa.Column(sa.String(length=60))
@ -126,49 +126,49 @@ any.
size = sa.Column(sa.String(length=30))
unit_size = sa.Column(sa.Numeric(precision=8, scale=3), nullable=True, doc="""
Unit size for product, as decimal. This refers to the numeric size of a unit
of the product, in terms of the :attr:`unit_of_measure`, and may be used for
smarter price comparisons etc.
""")
Unit size for product, as decimal. This refers to the numeric size of a unit
of the product, in terms of the :attr:`unit_of_measure`, and may be used for
smarter price comparisons etc.
""")
unit_of_measure = sa.Column(sa.String(length=4), nullable=False,
default=enum.UNIT_OF_MEASURE_NONE, doc="""
Code indicating the unit of measure for the product. Value should be one of
the keys of the ``rattail.enum.UNIT_OF_MEASURE`` dictionary.
""")
Code indicating the unit of measure for the product. Value should be one of
the keys of the ``rattail.enum.UNIT_OF_MEASURE`` dictionary.
""")
weighed = sa.Column(sa.Boolean(), nullable=False, default=False, doc="""
Whether or not the product must be weighed to determine its final price.
""")
Whether or not the product must be weighed to determine its final price.
""")
case_pack = sa.Column(sa.Integer(), nullable=True, doc="""
Pack size for the product, i.e. how many units are in a case.
""")
Pack size for the product, i.e. how many units are in a case.
""")
organic = sa.Column(sa.Boolean(), nullable=False, default=False, doc="""
Whether the item is organic.
""")
Whether the item is organic.
""")
not_for_sale = sa.Column(sa.Boolean(), nullable=False, default=False, doc="""
Flag to indicate items which are not available for sale.
""")
Flag to indicate items which are not available for sale.
""")
deleted = sa.Column(sa.Boolean(), nullable=False, default=False, doc="""
Flag to indicate items which have been deleted. Obviously this is implies
"false" deletion, where the record is actually kept on file. Whether or not
you use this is up to you.
""")
Flag to indicate items which have been deleted. Obviously this is implies
"false" deletion, where the record is actually kept on file. Whether or not
you use this is up to you.
""")
regular_price_uuid = sa.Column(sa.String(length=32))
current_price_uuid = sa.Column(sa.String(length=32))
discountable = sa.Column(sa.Boolean(), nullable=False, default=True, doc="""
Whether or not the product may be discounted in any way.
""")
Whether or not the product may be discounted in any way.
""")
special_order = sa.Column(sa.Boolean(), nullable=False, default=False, doc="""
Whether the product is available for special order.
""")
Whether the product is available for special order.
""")
food_stampable = sa.Column(sa.Boolean(), nullable=True, doc="""
Flag indicating whether food stamps are a valid form of payment for the item.
@ -187,18 +187,19 @@ Whether the product is available for special order.
""")
last_sold = sa.Column(sa.DateTime(), nullable=True, doc="""
UTC timestamp of the product's last sale event.
""")
UTC timestamp of the product's last sale event.
""")
department = orm.relationship(Department, order_by=Department.name)
subdepartment = orm.relationship(
Subdepartment,
order_by=Subdepartment.name,
backref=orm.backref('products', cascade='all'))
backref=orm.backref('products'))
category = orm.relationship(
Category, back_populates='products')
Category,
backref=orm.backref('products'))
brand = orm.relationship(Brand)
@ -208,7 +209,11 @@ UTC timestamp of the product's last sale event.
Reference to the :class:`Family` instance with which the product
associates, if any.
""",
back_populates='products')
backref=orm.backref(
'products',
doc="""
List of :class:`Product` objects which belong to this family.
"""))
report_code = orm.relationship(
'ReportCode',
@ -216,7 +221,11 @@ UTC timestamp of the product's last sale event.
Reference to the :class:`ReportCode` instance with which the product
associates, if any.
""",
back_populates='products')
backref=orm.backref(
'products',
doc="""
List of :class:`Product` objects which associate with this report code.
"""))
def __unicode__(self):
return self.full_description
@ -250,10 +259,6 @@ UTC timestamp of the product's last sale event.
return cost
Category.products = orm.relationship(
Product, back_populates='category')
class ProductCode(Base):
"""
Represents an arbitrary "code" for a product.