Coverage for .tox / coverage / lib / python3.11 / site-packages / sideshow / db / model / batch / neworder.py: 100%
47 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-15 17:10 -0600
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-15 17:10 -0600
1# -*- coding: utf-8; -*-
2################################################################################
3#
4# Sideshow -- Case/Special Order Tracker
5# Copyright © 2024-2025 Lance Edgar
6#
7# This file is part of Sideshow.
8#
9# Sideshow is free software: you can redistribute it and/or modify it
10# under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# Sideshow is distributed in the hope that it will be useful, but
15# WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with Sideshow. If not, see <http://www.gnu.org/licenses/>.
21#
22################################################################################
23"""
24Data models for New Order Batch
26* :class:`NewOrderBatch`
27* :class:`NewOrderBatchRow`
28"""
30import sqlalchemy as sa
31from sqlalchemy import orm
32from sqlalchemy.ext.declarative import declared_attr
34from wuttjamaican.db import model
36from sideshow.db.model.orders import OrderMixin, OrderItemMixin
39class NewOrderBatch(model.BatchMixin, OrderMixin, model.Base):
40 """
41 :term:`Batch <batch>` used for entering new :term:`orders <order>`
42 into the system. Each batch ultimately becomes an
43 :class:`~sideshow.db.model.orders.Order`.
45 See also :class:`~sideshow.batch.neworder.NewOrderBatchHandler`
46 which is the default :term:`batch handler` for this :term:`batch
47 type`.
49 Generic batch attributes (undocumented below) are inherited from
50 :class:`~wuttjamaican:wuttjamaican.db.model.batch.BatchMixin`.
51 """
53 __tablename__ = "sideshow_batch_neworder"
54 __batchrow_class__ = "NewOrderBatchRow"
56 batch_type = "neworder"
57 """
58 Official :term:`batch type` key.
59 """
61 @declared_attr
62 def __table_args__(cls): # pylint: disable=no-self-argument
63 return cls.__default_table_args__() + (
64 sa.ForeignKeyConstraint(
65 ["local_customer_uuid"], ["sideshow_customer_local.uuid"]
66 ),
67 sa.ForeignKeyConstraint(
68 ["pending_customer_uuid"], ["sideshow_customer_pending.uuid"]
69 ),
70 )
72 STATUS_OK = 1
74 STATUS = {
75 STATUS_OK: "ok",
76 }
78 local_customer_uuid = sa.Column(model.UUID(), nullable=True)
80 @declared_attr
81 def local_customer( # pylint: disable=no-self-argument,missing-function-docstring
82 cls,
83 ):
84 return orm.relationship(
85 "LocalCustomer",
86 cascade_backrefs=False,
87 back_populates="new_order_batches",
88 doc="""
89 Reference to the
90 :class:`~sideshow.db.model.customers.LocalCustomer` record
91 for the order, if applicable.
93 See also :attr:`customer_id` and :attr:`pending_customer`.
94 """,
95 )
97 pending_customer_uuid = sa.Column(model.UUID(), nullable=True)
99 @declared_attr
100 def pending_customer( # pylint: disable=no-self-argument,missing-function-docstring
101 cls,
102 ):
103 return orm.relationship(
104 "PendingCustomer",
105 cascade_backrefs=False,
106 back_populates="new_order_batches",
107 doc="""
108 Reference to the
109 :class:`~sideshow.db.model.customers.PendingCustomer`
110 record for the order, if applicable.
112 See also :attr:`customer_id` and :attr:`local_customer`.
113 """,
114 )
117class NewOrderBatchRow(model.BatchRowMixin, OrderItemMixin, model.Base):
118 """
119 Row of data within a :class:`NewOrderBatch`. Each row ultimately
120 becomes an :class:`~sideshow.db.model.orders.OrderItem`.
122 Generic row attributes (undocumented below) are inherited from
123 :class:`~wuttjamaican:wuttjamaican.db.model.batch.BatchRowMixin`.
124 """
126 __tablename__ = "sideshow_batch_neworder_row"
127 __batch_class__ = NewOrderBatch
129 @declared_attr
130 def __table_args__(cls): # pylint: disable=no-self-argument
131 return cls.__default_table_args__() + (
132 sa.ForeignKeyConstraint(
133 ["local_product_uuid"], ["sideshow_product_local.uuid"]
134 ),
135 sa.ForeignKeyConstraint(
136 ["pending_product_uuid"], ["sideshow_product_pending.uuid"]
137 ),
138 )
140 STATUS_OK = 1
141 """
142 This is the default value for :attr:`status_code`. All rows are
143 considered "OK" if they have either a :attr:`product_id` or
144 :attr:`pending_product`.
145 """
147 STATUS_MISSING_PRODUCT = 2
148 """
149 Status code indicating the row has no :attr:`product_id` or
150 :attr:`pending_product` set.
151 """
153 STATUS_MISSING_ORDER_QTY = 3
154 """
155 Status code indicating the row has no :attr:`order_qty` and/or
156 :attr:`order_uom` set.
157 """
159 STATUS = {
160 STATUS_OK: "ok",
161 STATUS_MISSING_PRODUCT: "missing product",
162 STATUS_MISSING_ORDER_QTY: "missing order qty/uom",
163 }
164 """
165 Dict of possible status code -> label options.
166 """
168 local_product_uuid = sa.Column(model.UUID(), nullable=True)
170 @declared_attr
171 def local_product( # pylint: disable=no-self-argument,missing-function-docstring
172 cls,
173 ):
174 return orm.relationship(
175 "LocalProduct",
176 cascade_backrefs=False,
177 back_populates="new_order_batch_rows",
178 doc="""
179 Reference to the
180 :class:`~sideshow.db.model.products.LocalProduct` record
181 for the order item, if applicable.
183 See also :attr:`product_id` and :attr:`pending_product`.
184 """,
185 )
187 pending_product_uuid = sa.Column(model.UUID(), nullable=True)
189 @declared_attr
190 def pending_product( # pylint: disable=no-self-argument,missing-function-docstring
191 cls,
192 ):
193 return orm.relationship(
194 "PendingProduct",
195 cascade_backrefs=False,
196 back_populates="new_order_batch_rows",
197 doc="""
198 Reference to the
199 :class:`~sideshow.db.model.products.PendingProduct` record
200 for the order item, if applicable.
202 See also :attr:`product_id` and :attr:`local_product`.
203 """,
204 )
206 def __str__(self):
207 return str(self.pending_product or self.product_description or "")