source: rattail/rattail/db/model/batch/purchase.py @ 4592c96

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

Add support for 'receiving' mode for purchase batches

  • Property mode set to 100644
File size: 4.0 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
46    @declared_attr
47    def __table_args__(cls):
48        return cls.__batch_table_args__() + cls.__purchase_table_args__() + (
49            sa.ForeignKeyConstraint(['purchase_uuid'], ['purchase.uuid'], name='purchase_batch_fk_purchase'),
50        )
51
52    purchase_uuid = sa.Column(sa.String(length=32), nullable=True)
53
54    purchase = orm.relationship(
55        Purchase,
56        doc="""
57        Reference to the purchase with which the batch is associated.  May be
58        null, e.g. in the case of a "new purchase" batch.
59        """,
60        backref=orm.backref(
61            'batches',
62            order_by='PurchaseBatch.id',
63            doc="""
64            List of batches associated with the purchase.
65            """))
66
67    mode = sa.Column(sa.Integer(), nullable=False, doc="""
68    Numeric "mode" for the purchase batch, to indicate new/receiving etc.
69    """)
70
71    complete = sa.Column(sa.Boolean(), nullable=True, doc="""
72    Flag to indicate whether the batch is complete.  This may be used to assist
73    with workflow when entering/executing new purchases.
74    """)
75
76
77class PurchaseBatchRow(BatchRowMixin, PurchaseItemBase, Base):
78    """
79    Row of data within a purchase batch.
80    """
81    __tablename__ = 'purchase_batch_row'
82    __batch_class__ = PurchaseBatch
83
84    @declared_attr
85    def __table_args__(cls):
86        return cls.__batchrow_table_args__() + cls.__purchaseitem_table_args__() + (
87            sa.ForeignKeyConstraint(['item_uuid'], ['purchase_item.uuid'], name='purchase_batch_row_fk_item'),
88        )
89
90    STATUS_OK                           = 1
91    STATUS_PRODUCT_NOT_FOUND            = 2
92    STATUS_COST_NOT_FOUND               = 3
93    STATUS_CASE_QUANTITY_UNKNOWN        = 4
94    STATUS_INCOMPLETE                   = 5
95    STATUS_ORDERED_RECEIVED_DIFFER      = 6
96
97    STATUS = {
98        STATUS_OK                       : "ok",
99        STATUS_PRODUCT_NOT_FOUND        : "product not found",
100        STATUS_COST_NOT_FOUND           : "product found but not cost",
101        STATUS_CASE_QUANTITY_UNKNOWN    : "case quantity not known",
102        STATUS_INCOMPLETE               : "incomplete",
103        STATUS_ORDERED_RECEIVED_DIFFER  : "ordered / received differ",
104    }
105
106    item_uuid = sa.Column(sa.String(length=32), nullable=True)
107
108    item = orm.relationship(
109        PurchaseItem,
110        doc="""
111        Reference to the purchase item with which the batch row is associated.
112        May be null, e.g. in the case of a "new purchase" batch.
113        """)
Note: See TracBrowser for help on using the repository browser.