Coverage for .tox/coverage/lib/python3.11/site-packages/sideshow/db/model/customers.py: 100%
29 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-09 12:58 -0600
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-09 12:58 -0600
1# -*- coding: utf-8; -*-
2################################################################################
3#
4# Sideshow -- Case/Special Order Tracker
5# Copyright © 2024 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 datetime
29import sqlalchemy as sa
30from sqlalchemy import orm
32from wuttjamaican.db import model
34from sideshow.enum import PendingCustomerStatus
37class CustomerMixin:
38 """
39 Base class for customer tables. This has shared columns, used by e.g.:
41 * :class:`LocalCustomer`
42 * :class:`PendingCustomer`
43 """
45 full_name = sa.Column(sa.String(length=100), nullable=True, doc="""
46 Full display name for the customer account.
47 """)
49 first_name = sa.Column(sa.String(length=50), nullable=True, doc="""
50 First name of the customer.
51 """)
53 last_name = sa.Column(sa.String(length=50), nullable=True, doc="""
54 Last name of the customer.
55 """)
57 phone_number = sa.Column(sa.String(length=20), nullable=True, doc="""
58 Phone number for the customer.
59 """)
61 email_address = sa.Column(sa.String(length=255), nullable=True, doc="""
62 Email address for the customer.
63 """)
65 def __str__(self):
66 return self.full_name or ""
69class LocalCustomer(CustomerMixin, model.Base):
70 """
71 This table contains the :term:`local customer` records.
73 Sideshow will do customer lookups against this table by default,
74 unless it's configured to use :term:`external customers <external
75 customer>` instead.
77 Also by default, when a :term:`new order batch` with a
78 :term:`pending customer` is executed, a new record is added to
79 this local customers table, for lookup next time.
80 """
81 __tablename__ = 'sideshow_customer_local'
83 uuid = model.uuid_column()
85 external_id = sa.Column(sa.String(length=20), nullable=True, doc="""
86 ID of the proper customer account associated with this record, if
87 applicable.
88 """)
90 orders = orm.relationship(
91 'Order',
92 order_by='Order.order_id.desc()',
93 back_populates='local_customer',
94 cascade_backrefs=False,
95 doc="""
96 List of :class:`~sideshow.db.model.orders.Order` records
97 associated with this customer.
98 """)
100 new_order_batches = orm.relationship(
101 'NewOrderBatch',
102 order_by='NewOrderBatch.id.desc()',
103 back_populates='local_customer',
104 cascade_backrefs=False,
105 doc="""
106 List of
107 :class:`~sideshow.db.model.batch.neworder.NewOrderBatch`
108 records associated with this customer.
109 """)
112class PendingCustomer(CustomerMixin, model.Base):
113 """
114 This table contains the :term:`pending customer` records, used
115 when creating an :term:`order` for new/unknown customer.
117 Sideshow will automatically create and (hopefully) delete these
118 records as needed.
120 By default, when a :term:`new order batch` with a pending customer
121 is executed, a new record is added to the :term:`local customers
122 <local customer>` table, for lookup next time.
123 """
124 __tablename__ = 'sideshow_customer_pending'
126 uuid = model.uuid_column()
128 customer_id = sa.Column(sa.String(length=20), nullable=True, doc="""
129 ID of the proper customer account associated with this record, if
130 applicable.
131 """)
133 status = sa.Column(sa.Enum(PendingCustomerStatus), nullable=False, doc="""
134 Status code for the customer record.
135 """)
137 created = sa.Column(sa.DateTime(timezone=True), nullable=False,
138 default=datetime.datetime.now, doc="""
139 Timestamp when the customer record was created.
140 """)
142 created_by_uuid = model.uuid_fk_column('user.uuid', nullable=False)
143 created_by = orm.relationship(
144 model.User,
145 cascade_backrefs=False,
146 doc="""
147 Reference to the
148 :class:`~wuttjamaican:wuttjamaican.db.model.auth.User` who
149 created the customer record.
150 """)
152 orders = orm.relationship(
153 'Order',
154 order_by='Order.order_id.desc()',
155 cascade_backrefs=False,
156 back_populates='pending_customer',
157 doc="""
158 List of :class:`~sideshow.db.model.orders.Order` records
159 associated with this customer.
160 """)
162 new_order_batches = orm.relationship(
163 'NewOrderBatch',
164 order_by='NewOrderBatch.id.desc()',
165 cascade_backrefs=False,
166 back_populates='pending_customer',
167 doc="""
168 List of
169 :class:`~sideshow.db.model.batch.neworder.NewOrderBatch`
170 records associated with this customer.
171 """)