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

custorders
Last change on this file since eba0833 was eba0833, checked in by Lance Edgar <ledgar@…>, 4 years ago

Add mode, purchase relation to purchase batches

  • Property mode set to 100644
File size: 3.3 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, Purchase, PurchaseItemBase, BatchMixin, BatchRowMixin
34
35
36class PurchaseBatch(BatchMixin, PurchaseBase, Base):
37    """
38    Hopefully generic batch used for entering new purchases into the system, etc.?
39    """
40    batch_key = 'purchase'
41    __tablename__ = 'purchase_batch'
42    __batchrow_class__ = 'PurchaseBatchRow'
43
44    @declared_attr
45    def __table_args__(cls):
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    """)
67
68    complete = sa.Column(sa.Boolean(), nullable=True, doc="""
69    Flag to indicate whether the batch is complete.  This may be used to assist
70    with workflow when entering/executing new purchases.
71    """)
72
73
74class PurchaseBatchRow(BatchRowMixin, PurchaseItemBase, Base):
75    """
76    Row of data within a purchase batch.
77    """
78    __tablename__ = 'purchase_batch_row'
79    __batch_class__ = PurchaseBatch
80
81    @declared_attr
82    def __table_args__(cls):
83        return cls.__batchrow_table_args__() + cls.__purchaseitem_table_args__()
84
85    STATUS_OK                           = 1
86    STATUS_PRODUCT_NOT_FOUND            = 2
87    STATUS_COST_NOT_FOUND               = 3
88    STATUS_CASE_QUANTITY_UNKNOWN        = 4
89
90    STATUS = {
91        STATUS_OK                       : "ok",
92        STATUS_PRODUCT_NOT_FOUND        : "product not found",
93        STATUS_COST_NOT_FOUND           : "product found but not cost",
94        STATUS_CASE_QUANTITY_UNKNOWN    : "case quantity not known",
95    }
Note: See TracBrowser for help on using the repository browser.