From e0058c003ddba043b9f99c7042813cae959dc546 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 29 Mar 2020 23:36:29 -0500 Subject: [PATCH] Add `Product.subdepartment` relationship --- corepos/db/office_op/model.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/corepos/db/office_op/model.py b/corepos/db/office_op/model.py index 1b2384a..99dee9f 100644 --- a/corepos/db/office_op/model.py +++ b/corepos/db/office_op/model.py @@ -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']