Changeset eba0833 in rattail for rattail/db/model/batch/purchase.py


Ignore:
Timestamp:
11/20/16 17:46:12 (4 years ago)
Author:
Lance Edgar <ledgar@…>
Branches:
custorders, master
Children:
4592c96
Parents:
28d5bb3
Message:

Add mode, purchase relation to purchase batches

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail/db/model/batch/purchase.py

    r28d5bb3 reba0833  
    2828
    2929import sqlalchemy as sa
     30from sqlalchemy import orm
    3031from sqlalchemy.ext.declarative import declared_attr
    3132
    32 from rattail.db.model import Base, PurchaseBase, PurchaseItemBase, BatchMixin, BatchRowMixin
     33from rattail.db.model import Base, PurchaseBase, Purchase, PurchaseItemBase, BatchMixin, BatchRowMixin
    3334
    3435
     
    4344    @declared_attr
    4445    def __table_args__(cls):
    45         return cls.__batch_table_args__() + cls.__purchase_table_args__()
     46        return cls.__batch_table_args__() + cls.__purchase_table_args__() + (
     47            sa.ForeignKeyConstraint(['purchase_uuid'], ['purchase.uuid'], name='purchase_batch_fk_purchase'),
     48        )
     49
     50    purchase_uuid = sa.Column(sa.String(length=32), nullable=True)
     51
     52    purchase = orm.relationship(
     53        Purchase,
     54        doc="""
     55        Reference to the purchase with which the batch is associated.  May be
     56        null, e.g. in the case of a "new purchase" batch.
     57        """,
     58        backref=orm.backref(
     59            'batches',
     60            doc="""
     61            List of batches associated with the purchase.
     62            """))
     63
     64    mode = sa.Column(sa.Integer(), nullable=False, doc="""
     65    Numeric "mode" for the purchase batch, to indicate new/receiving etc.
     66    """)
    4667
    4768    complete = sa.Column(sa.Boolean(), nullable=True, doc="""
Note: See TracChangeset for help on using the changeset viewer.