Add Product.subdepartment relationship

This commit is contained in:
Lance Edgar 2020-03-29 23:36:29 -05:00
parent 9466b16b64
commit e0058c003d

View file

@ -242,6 +242,7 @@ class Product(Base):
__tablename__ = 'products'
__table_args__ = (
sa.ForeignKeyConstraint(['department'], ['departments.dept_no']),
sa.ForeignKeyConstraint(['subdept'], ['subdepts.subdept_no']),
sa.ForeignKeyConstraint(['tax'], ['taxrates.id']),
)
@ -276,6 +277,13 @@ class Product(Base):
end_date = sa.Column(sa.DateTime(), nullable=True)
department_number = sa.Column('department', sa.SmallInteger(), nullable=True)
department = orm.relationship(
Department,
primaryjoin=Department.number == department_number,
foreign_keys=[department_number],
doc="""
Reference to the :class:`Department` to which the product belongs.
""")
size = sa.Column(sa.String(length=9), nullable=True)
@ -317,6 +325,13 @@ class Product(Base):
flags = sa.Column('numflag', sa.Integer(), nullable=True, default=0)
subdepartment_number = sa.Column('subdept', sa.SmallInteger(), nullable=True)
subdepartment = orm.relationship(
Subdepartment,
primaryjoin=Subdepartment.number == subdepartment_number,
foreign_keys=[subdepartment_number],
doc="""
Reference to the :class:`Subdepartment` to which the product belongs.
""")
deposit = sa.Column(sa.Float(), nullable=True)
@ -325,17 +340,6 @@ class Product(Base):
store_id = sa.Column(sa.SmallInteger(), nullable=True, default=0)
default_vendor_id = sa.Column(sa.Integer(), nullable=True, default=0)
current_origin_id = sa.Column(sa.Integer(), nullable=True, default=0)
department = orm.relationship(
Department,
primaryjoin=Department.number == department_number,
foreign_keys=[department_number],
doc="""
Reference to the :class:`Department` to which the product belongs.
""")
vendor = orm.relationship(
Vendor,
primaryjoin=Vendor.id == default_vendor_id,
@ -344,6 +348,8 @@ class Product(Base):
Reference to the default :class:`Vendor` from which the product is obtained.
""")
current_origin_id = sa.Column(sa.Integer(), nullable=True, default=0)
@property
def full_description(self):
fields = ['brand', 'description', 'size']