Coverage for src/sideshow/db/model/customers.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-06 15:04 -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""" 

26 

27import datetime 

28 

29import sqlalchemy as sa 

30from sqlalchemy import orm 

31 

32from wuttjamaican.db import model 

33 

34from sideshow.enum import PendingCustomerStatus 

35 

36 

37class PendingCustomer(model.Base): 

38 """ 

39 A "pending" customer record, used when entering an :term:`order` 

40 for new/unknown customer. 

41 """ 

42 __tablename__ = 'sideshow_pending_customer' 

43 

44 uuid = model.uuid_column() 

45 

46 customer_id = sa.Column(sa.String(length=20), nullable=True, doc=""" 

47 ID of the proper customer account associated with this record, if 

48 applicable. 

49 """) 

50 

51 full_name = sa.Column(sa.String(length=100), nullable=True, doc=""" 

52 Full display name for the customer account. 

53 """) 

54 

55 first_name = sa.Column(sa.String(length=50), nullable=True, doc=""" 

56 First name of the customer. 

57 """) 

58 

59 last_name = sa.Column(sa.String(length=50), nullable=True, doc=""" 

60 Last name of the customer. 

61 """) 

62 

63 phone_number = sa.Column(sa.String(length=20), nullable=True, doc=""" 

64 Phone number for the customer. 

65 """) 

66 

67 email_address = sa.Column(sa.String(length=255), nullable=True, doc=""" 

68 Email address for the customer. 

69 """) 

70 

71 status = sa.Column(sa.Enum(PendingCustomerStatus), nullable=False, doc=""" 

72 Status code for the customer record. 

73 """) 

74 

75 created = sa.Column(sa.DateTime(timezone=True), nullable=False, 

76 default=datetime.datetime.now, doc=""" 

77 Timestamp when the customer record was created. 

78 """) 

79 

80 created_by_uuid = model.uuid_fk_column('user.uuid', nullable=False) 

81 created_by = orm.relationship( 

82 model.User, 

83 cascade_backrefs=False, 

84 doc=""" 

85 Reference to the 

86 :class:`~wuttjamaican:wuttjamaican.db.model.auth.User` who 

87 created the customer record. 

88 """) 

89 

90 orders = orm.relationship( 

91 'Order', 

92 order_by='Order.order_id.desc()', 

93 cascade_backrefs=False, 

94 back_populates='pending_customer', 

95 doc=""" 

96 List of :class:`~sideshow.db.model.orders.Order` records 

97 associated with this customer. 

98 """) 

99 

100 new_order_batches = orm.relationship( 

101 'NewOrderBatch', 

102 order_by='NewOrderBatch.id.desc()', 

103 cascade_backrefs=False, 

104 back_populates='pending_customer', 

105 doc=""" 

106 List of 

107 :class:`~sideshow.db.model.batch.neworder.NewOrderBatch` 

108 records associated with this customer. 

109 """) 

110 

111 def __str__(self): 

112 return self.full_name or ""