Changeset 225a0ba in rattail for rattail/db/model/batch/purchase.py


Ignore:
Timestamp:
05/18/18 15:44:02 (2 years ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
ddca6b7
Parents:
d3662fe
Message:

Add "most of" support for truck dump receiving

File:
1 edited

Legend:

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

    rd3662fe r225a0ba  
    3535                              PurchaseBase, PurchaseItemBase, PurchaseCreditBase,
    3636                              Purchase, PurchaseItem)
     37from rattail.db.model.batch import filename_column
    3738from rattail.util import pretty_quantity
    3839
     
    5253        return cls.__batch_table_args__() + cls.__purchase_table_args__() + (
    5354            sa.ForeignKeyConstraint(['purchase_uuid'], ['purchase.uuid'], name='purchase_batch_fk_purchase'),
     55            sa.ForeignKeyConstraint(['truck_dump_batch_uuid'], ['purchase_batch.uuid'], name='purchase_batch_fk_truck_dump_batch', use_alter=True),
    5456        )
    5557
    5658    STATUS_OK                   = 1
    5759    STATUS_UNKNOWN_PRODUCT      = 2
     60    STATUS_TRUCKDUMP_UNCLAIMED  = 3
     61    STATUS_TRUCKDUMP_CLAIMED    = 4
    5862
    5963    STATUS = {
    60         STATUS_OK:              "ok",
    61         STATUS_UNKNOWN_PRODUCT: "has unknown product(s)",
     64        STATUS_OK                       : "ok",
     65        STATUS_UNKNOWN_PRODUCT          : "has unknown product(s)",
     66        STATUS_TRUCKDUMP_UNCLAIMED      : "not yet fully claimed",
     67        STATUS_TRUCKDUMP_CLAIMED        : "fully claimed by child(ren)",
    6268    }
    6369
     
    8187    """)
    8288
    83     truck_dump = sa.Column(sa.Boolean(), nullable=True, doc="""
     89    invoice_file = filename_column(doc="Base name for the associated invoice file, if any.")
     90
     91    invoice_parser_key = sa.Column(sa.String(length=100), nullable=True, doc="""
     92    The key of the parser used to read the contents of the invoice file.
     93    """)
     94
     95    truck_dump = sa.Column(sa.Boolean(), nullable=True, default=False, doc="""
    8496    Flag indicating whether a "receiving" batch is of the "truck dump"
    8597    persuasion, i.e.  it does not correspond to a single purchase order but
    8698    rather is assumed to represent multiple orders.
    8799    """)
     100
     101    truck_dump_batch_uuid = sa.Column(sa.String(length=32), nullable=True)
     102    truck_dump_batch = orm.relationship(
     103        'PurchaseBatch',
     104        remote_side='PurchaseBatch.uuid',
     105        doc="""
     106        Reference to the "truck dump" receiving batch, for which the current
     107        batch represents a single invoice which partially "consumes" the truck
     108        dump.
     109        """,
     110        backref=orm.backref(
     111            'truck_dump_children',
     112            order_by='PurchaseBatch.id',
     113            doc="""
     114            List of batches which are "children" of the current batch, which is
     115            assumed to be a truck dump.
     116            """))
    88117
    89118
     
    107136    STATUS_INCOMPLETE                   = 5
    108137    STATUS_ORDERED_RECEIVED_DIFFER      = 6
     138    STATUS_TRUCKDUMP_UNCLAIMED          = 7
     139    STATUS_TRUCKDUMP_CLAIMED            = 8
     140    STATUS_TRUCKDUMP_OVERCLAIMED        = 9
    109141
    110142    STATUS = {
     
    115147        STATUS_INCOMPLETE               : "incomplete",
    116148        STATUS_ORDERED_RECEIVED_DIFFER  : "ordered / received differ",
     149        STATUS_TRUCKDUMP_UNCLAIMED      : "not yet fully claimed",
     150        STATUS_TRUCKDUMP_CLAIMED        : "fully claimed by child(ren)",
     151        STATUS_TRUCKDUMP_OVERCLAIMED    : "OVER claimed by child(ren)",
    117152    }
    118153
     
    125160        May be null, e.g. in the case of a "new purchase" batch.
    126161        """)
     162
     163
     164class PurchaseBatchRowClaim(Base):
     165    """
     166    Represents the connection between a row(s) from a truck dump batch, and the
     167    corresponding "child" batch row which claims it, as well as the claimed
     168    quantities etc.
     169    """
     170    __tablename__ = 'purchase_batch_row_claim'
     171    __table_args__ = (
     172        sa.ForeignKeyConstraint(['claiming_row_uuid'], ['purchase_batch_row.uuid'], name='purchase_batch_row_claim_fk_claiming_row'),
     173        sa.ForeignKeyConstraint(['claimed_row_uuid'], ['purchase_batch_row.uuid'], name='purchase_batch_row_claim_fk_claimed_row'),
     174    )
     175
     176    uuid = uuid_column()
     177
     178    claiming_row_uuid = sa.Column(sa.String(length=32), nullable=False)
     179    claiming_row = orm.relationship(
     180        PurchaseBatchRow,
     181        foreign_keys='PurchaseBatchRowClaim.claiming_row_uuid',
     182        doc="""
     183        Reference to the "child" row which is claiming some row from a truck
     184        dump batch.
     185        """,
     186        backref=orm.backref(
     187            'truck_dump_claims',
     188            cascade='all, delete-orphan',
     189            doc="""
     190            List of claims which this "child" row makes against rows within a
     191            truck dump batch.
     192            """))
     193
     194    claimed_row_uuid = sa.Column(sa.String(length=32), nullable=False)
     195    claimed_row = orm.relationship(
     196        PurchaseBatchRow,
     197        foreign_keys='PurchaseBatchRowClaim.claimed_row_uuid',
     198        doc="""
     199        Reference to the truck dump batch row which is claimed by the "child" row.
     200        """,
     201        backref=orm.backref(
     202            'claims',
     203            # cascade='all, delete-orphan',
     204            doc="""
     205            List of claims made by "child" rows against this truck dump batch row.
     206            """))
     207
     208    cases_received = sa.Column(sa.Numeric(precision=10, scale=4), nullable=True, doc="""
     209    Number of cases of product which were ultimately received, and are involved in the claim.
     210    """)
     211
     212    units_received = sa.Column(sa.Numeric(precision=10, scale=4), nullable=True, doc="""
     213    Number of units of product which were ultimately received, and are involved in the claim.
     214    """)
     215
     216    cases_damaged = sa.Column(sa.Numeric(precision=10, scale=4), nullable=True, doc="""
     217    Number of cases of product which were shipped damaged, and are involved in the claim.
     218    """)
     219
     220    units_damaged = sa.Column(sa.Numeric(precision=10, scale=4), nullable=True, doc="""
     221    Number of units of product which were shipped damaged, and are involved in the claim.
     222    """)
     223
     224    cases_expired = sa.Column(sa.Numeric(precision=10, scale=4), nullable=True, doc="""
     225    Number of cases of product which were shipped expired, and are involved in the claim.
     226    """)
     227
     228    units_expired = sa.Column(sa.Numeric(precision=10, scale=4), nullable=True, doc="""
     229    Number of units of product which were shipped expired, and are involved in the claim.
     230    """)
    127231
    128232
Note: See TracChangeset for help on using the changeset viewer.