source: rattail/rattail/db/model/batch/purchase.py @ caa956b

custorders
Last change on this file since caa956b was caa956b, checked in by Lance Edgar <lance@…>, 3 years ago

Tweak model title for "Purchasing Batches"

  • Property mode set to 100644
File size: 4.1 KB
Line 
1# -*- coding: utf-8 -*-
2################################################################################
3#
4#  Rattail -- Retail Software Framework
5#  Copyright © 2010-2016 Lance Edgar
6#
7#  This file is part of Rattail.
8#
9#  Rattail is free software: you can redistribute it and/or modify it under the
10#  terms of the GNU Affero General Public License as published by the Free
11#  Software Foundation, either version 3 of the License, or (at your option)
12#  any later version.
13#
14#  Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
15#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16#  FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
17#  more details.
18#
19#  You should have received a copy of the GNU Affero General Public License
20#  along with Rattail.  If not, see <http://www.gnu.org/licenses/>.
21#
22################################################################################
23"""
24Models for purchase order batches
25"""
26
27from __future__ import unicode_literals, absolute_import
28
29import sqlalchemy as sa
30from sqlalchemy import orm
31from sqlalchemy.ext.declarative import declared_attr
32
33from rattail.db.model import (Base, PurchaseBase, PurchaseItemBase,
34                              Purchase, PurchaseItem,
35                              BatchMixin, BatchRowMixin)
36
37
38class PurchaseBatch(BatchMixin, PurchaseBase, Base):
39    """
40    Hopefully generic batch used for entering new purchases into the system, etc.?
41    """
42    batch_key = 'purchase'
43    __tablename__ = 'purchase_batch'
44    __batchrow_class__ = 'PurchaseBatchRow'
45    model_title = "Purchasing Batch"
46    model_title_plural = "Purchasing Batches"
47
48    @declared_attr
49    def __table_args__(cls):
50        return cls.__batch_table_args__() + cls.__purchase_table_args__() + (
51            sa.ForeignKeyConstraint(['purchase_uuid'], ['purchase.uuid'], name='purchase_batch_fk_purchase'),
52        )
53
54    purchase_uuid = sa.Column(sa.String(length=32), nullable=True)
55
56    purchase = orm.relationship(
57        Purchase,
58        doc="""
59        Reference to the purchase with which the batch is associated.  May be
60        null, e.g. in the case of a "new purchase" batch.
61        """,
62        backref=orm.backref(
63            'batches',
64            order_by='PurchaseBatch.id',
65            doc="""
66            List of batches associated with the purchase.
67            """))
68
69    mode = sa.Column(sa.Integer(), nullable=False, doc="""
70    Numeric "mode" for the purchase batch, to indicate new/receiving etc.
71    """)
72
73    complete = sa.Column(sa.Boolean(), nullable=True, doc="""
74    Flag to indicate whether the batch is complete.  This may be used to assist
75    with workflow when entering/executing new purchases.
76    """)
77
78
79class PurchaseBatchRow(BatchRowMixin, PurchaseItemBase, Base):
80    """
81    Row of data within a purchase batch.
82    """
83    __tablename__ = 'purchase_batch_row'
84    __batch_class__ = PurchaseBatch
85
86    @declared_attr
87    def __table_args__(cls):
88        return cls.__batchrow_table_args__() + cls.__purchaseitem_table_args__() + (
89            sa.ForeignKeyConstraint(['item_uuid'], ['purchase_item.uuid'], name='purchase_batch_row_fk_item'),
90        )
91
92    STATUS_OK                           = 1
93    STATUS_PRODUCT_NOT_FOUND            = 2
94    STATUS_COST_NOT_FOUND               = 3
95    STATUS_CASE_QUANTITY_UNKNOWN        = 4
96    STATUS_INCOMPLETE                   = 5
97    STATUS_ORDERED_RECEIVED_DIFFER      = 6
98
99    STATUS = {
100        STATUS_OK                       : "ok",
101        STATUS_PRODUCT_NOT_FOUND        : "product not found",
102        STATUS_COST_NOT_FOUND           : "product found but not cost",
103        STATUS_CASE_QUANTITY_UNKNOWN    : "case quantity not known",
104        STATUS_INCOMPLETE               : "incomplete",
105        STATUS_ORDERED_RECEIVED_DIFFER  : "ordered / received differ",
106    }
107
108    item_uuid = sa.Column(sa.String(length=32), nullable=True)
109
110    item = orm.relationship(
111        PurchaseItem,
112        doc="""
113        Reference to the purchase item with which the batch row is associated.
114        May be null, e.g. in the case of a "new purchase" batch.
115        """)
Note: See TracBrowser for help on using the repository browser.