Coverage for .tox / coverage / lib / python3.11 / site-packages / sideshow / db / model / customers.py: 100%
29 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 Customers
25"""
27import sqlalchemy as sa
28from sqlalchemy import orm
30from wuttjamaican.db import model
31from wuttjamaican.util import make_utc
33from sideshow.enum import PendingCustomerStatus
36class CustomerMixin: # pylint: disable=too-few-public-methods
37 """
38 Base class for customer tables. This has shared columns, used by e.g.:
40 * :class:`LocalCustomer`
41 * :class:`PendingCustomer`
42 """
44 full_name = sa.Column(
45 sa.String(length=100),
46 nullable=True,
47 doc="""
48 Full display name for the customer account.
49 """,
50 )
52 first_name = sa.Column(
53 sa.String(length=50),
54 nullable=True,
55 doc="""
56 First name of the customer.
57 """,
58 )
60 last_name = sa.Column(
61 sa.String(length=50),
62 nullable=True,
63 doc="""
64 Last name of the customer.
65 """,
66 )
68 phone_number = sa.Column(
69 sa.String(length=20),
70 nullable=True,
71 doc="""
72 Phone number for the customer.
73 """,
74 )
76 email_address = sa.Column(
77 sa.String(length=255),
78 nullable=True,
79 doc="""
80 Email address for the customer.
81 """,
82 )
84 def __str__(self):
85 return self.full_name or ""
88class LocalCustomer( # pylint: disable=too-few-public-methods
89 CustomerMixin, model.Base
90):
91 """
92 This table contains the :term:`local customer` records.
94 Sideshow will do customer lookups against this table by default,
95 unless it's configured to use :term:`external customers <external
96 customer>` instead.
98 Also by default, when a :term:`new order batch` with a
99 :term:`pending customer` is executed, a new record is added to
100 this local customers table, for lookup next time.
101 """
103 __tablename__ = "sideshow_customer_local"
105 uuid = model.uuid_column()
107 external_id = sa.Column(
108 sa.String(length=20),
109 nullable=True,
110 doc="""
111 ID of the proper customer account associated with this record, if
112 applicable.
113 """,
114 )
116 orders = orm.relationship(
117 "Order",
118 order_by="Order.order_id.desc()",
119 back_populates="local_customer",
120 cascade_backrefs=False,
121 doc="""
122 List of :class:`~sideshow.db.model.orders.Order` records
123 associated with this customer.
124 """,
125 )
127 new_order_batches = orm.relationship(
128 "NewOrderBatch",
129 order_by="NewOrderBatch.id.desc()",
130 back_populates="local_customer",
131 cascade_backrefs=False,
132 doc="""
133 List of
134 :class:`~sideshow.db.model.batch.neworder.NewOrderBatch`
135 records associated with this customer.
136 """,
137 )
140class PendingCustomer( # pylint: disable=too-few-public-methods
141 CustomerMixin, model.Base
142):
143 """
144 This table contains the :term:`pending customer` records, used
145 when creating an :term:`order` for new/unknown customer.
147 Sideshow will automatically create and (hopefully) delete these
148 records as needed.
150 By default, when a :term:`new order batch` with a pending customer
151 is executed, a new record is added to the :term:`local customers
152 <local customer>` table, for lookup next time.
153 """
155 __tablename__ = "sideshow_customer_pending"
157 uuid = model.uuid_column()
159 customer_id = sa.Column(
160 sa.String(length=20),
161 nullable=True,
162 doc="""
163 ID of the proper customer account associated with this record, if
164 applicable.
165 """,
166 )
168 status = sa.Column(
169 sa.Enum(PendingCustomerStatus),
170 nullable=False,
171 doc="""
172 Status code for the customer record.
173 """,
174 )
176 created = sa.Column(
177 sa.DateTime(),
178 nullable=False,
179 default=make_utc,
180 doc="""
181 Timestamp when the customer record was created.
182 """,
183 )
185 created_by_uuid = model.uuid_fk_column("user.uuid", nullable=False)
186 created_by = orm.relationship(
187 model.User,
188 cascade_backrefs=False,
189 doc="""
190 Reference to the
191 :class:`~wuttjamaican:wuttjamaican.db.model.auth.User` who
192 created the customer record.
193 """,
194 )
196 orders = orm.relationship(
197 "Order",
198 order_by="Order.order_id.desc()",
199 cascade_backrefs=False,
200 back_populates="pending_customer",
201 doc="""
202 List of :class:`~sideshow.db.model.orders.Order` records
203 associated with this customer.
204 """,
205 )
207 new_order_batches = orm.relationship(
208 "NewOrderBatch",
209 order_by="NewOrderBatch.id.desc()",
210 cascade_backrefs=False,
211 back_populates="pending_customer",
212 doc="""
213 List of
214 :class:`~sideshow.db.model.batch.neworder.NewOrderBatch`
215 records associated with this customer.
216 """,
217 )