Changeset b44f45b in rattail
- Timestamp:
- 08/01/2020 11:29:19 PM (3 years ago)
- Branches:
- master
- Children:
- 42d20a7
- Parents:
- e1f58209
- Location:
- rattail/db/model
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
rattail/db/model/__init__.py
re1f58209 rb44f45b 50 50 Purchase, PurchaseItem, PurchaseCredit) 51 51 52 from .custorders import CustomerOrder, CustomerOrderItem, CustomerOrderItemEvent 52 from .custorders import (CustomerOrderBase, CustomerOrderItemBase, 53 CustomerOrder, CustomerOrderItem, CustomerOrderItemEvent) 53 54 54 55 from .messages import Message, MessageRecipient -
rattail/db/model/custorders.py
re1f58209 rb44f45b 1 # -*- coding: utf-8 -*-1 # -*- coding: utf-8; -*- 2 2 ################################################################################ 3 3 # 4 4 # Rattail -- Retail Software Framework 5 # Copyright © 2010-20 17Lance Edgar5 # Copyright © 2010-2020 Lance Edgar 6 6 # 7 7 # This file is part of Rattail. … … 33 33 from sqlalchemy import orm 34 34 from sqlalchemy.ext.orderinglist import ordering_list 35 from sqlalchemy.ext.declarative import declared_attr 35 36 36 37 from rattail.db.model import Base, uuid_column … … 39 40 40 41 @six.python_2_unicode_compatible 41 class CustomerOrder(Base): 42 class CustomerOrderBase(object): 43 """ 44 Base class for customer orders; defines common fields. 45 """ 46 47 @declared_attr 48 def __table_args__(cls): 49 return cls.__customer_order_table_args__() 50 51 @classmethod 52 def __customer_order_table_args__(cls): 53 table_name = cls.__tablename__ 54 return ( 55 sa.ForeignKeyConstraint(['customer_uuid'], ['customer.uuid'], 56 name='{}_fk_customer'.format(table_name)), 57 sa.ForeignKeyConstraint(['person_uuid'], ['person.uuid'], 58 name='{}_fk_person'.format(table_name)), 59 ) 60 61 customer_uuid = sa.Column(sa.String(length=32), nullable=True) 62 63 @declared_attr 64 def customer(cls): 65 return orm.relationship( 66 Customer, 67 doc=""" 68 Reference to the customer account for which the order exists. 69 """) 70 71 person_uuid = sa.Column(sa.String(length=32), nullable=True) 72 73 @declared_attr 74 def person(cls): 75 return orm.relationship( 76 Person, 77 doc=""" 78 Reference to the person to whom the order applies. 79 """) 80 81 created = sa.Column(sa.DateTime(), nullable=False, default=datetime.datetime.utcnow, doc=""" 82 Date and time when the order/batch was first created. 83 """) 84 85 86 @six.python_2_unicode_compatible 87 class CustomerOrder(CustomerOrderBase, Base): 42 88 """ 43 89 Represents an order placed by the customer. 44 90 """ 45 91 __tablename__ = 'custorder' 46 __table_args__ = (47 sa.ForeignKeyConstraint(['customer_uuid'], ['customer.uuid'], name='custorder_fk_customer'),48 sa.ForeignKeyConstraint(['person_uuid'], ['person.uuid'], name='custorder_fk_person'),49 )50 92 51 93 uuid = uuid_column() … … 53 95 id = sa.Column(sa.Integer(), doc=""" 54 96 Numeric, auto-increment ID for the order. 55 """)56 57 customer_uuid = sa.Column(sa.String(length=32), nullable=True)58 59 customer = orm.relationship(Customer, doc="""60 Reference to the :class:`Customer` instance for whom the order exists.61 """)62 63 person_uuid = sa.Column(sa.String(length=32), nullable=True)64 65 person = orm.relationship(Person, doc="""66 Reference to the :class:`Person` instance for whom the order exists.67 """)68 69 created = sa.Column(sa.DateTime(), nullable=False, default=datetime.datetime.utcnow, doc="""70 Date and time when the order was first created.71 97 """) 72 98 … … 85 111 86 112 @six.python_2_unicode_compatible 87 class CustomerOrderItem(Base): 88 """ 89 Represents a particular line item (product) within a customer order. 90 """ 91 __tablename__ = 'custorder_item' 92 __table_args__ = ( 93 sa.ForeignKeyConstraint(['order_uuid'], ['custorder.uuid'], name='custorder_item_fk_order'), 94 sa.ForeignKeyConstraint(['product_uuid'], ['product.uuid'], name='custorder_item_fk_product'), 95 ) 96 97 uuid = uuid_column() 98 99 order_uuid = sa.Column(sa.String(length=32), nullable=False) 100 101 order = orm.relationship(CustomerOrder, back_populates='items', doc=""" 102 Reference to the :class:`CustomerOrder` instance to which the item belongs. 103 """) 113 class CustomerOrderItemBase(object): 114 """ 115 Base class for customer order line items. 116 """ 117 118 @declared_attr 119 def __table_args__(cls): 120 return cls.__customer_order_item_table_args__() 121 122 @classmethod 123 def __customer_order_item_table_args__(cls): 124 table_name = cls.__tablename__ 125 return ( 126 sa.ForeignKeyConstraint(['product_uuid'], ['product.uuid'], 127 name='{}_fk_product'.format(table_name)), 128 ) 104 129 105 130 sequence = sa.Column(sa.Integer(), nullable=False, doc=""" … … 111 136 product_uuid = sa.Column(sa.String(length=32), nullable=True) 112 137 113 product = orm.relationship(Product, doc=""" 114 Reference to the :class:`Product` instance for the item. 115 """) 138 @declared_attr 139 def product(cls): 140 return orm.relationship( 141 Product, 142 doc=""" 143 Reference to the master product record for the line item. 144 """) 116 145 117 146 product_brand = sa.Column(sa.String(length=100), nullable=True, doc=""" … … 185 214 """) 186 215 216 def __str__(self): 217 return str(self.product or "(no product)") 218 219 220 @six.python_2_unicode_compatible 221 class CustomerOrderItem(CustomerOrderItemBase, Base): 222 """ 223 Represents a particular line item (product) within a customer order. 224 """ 225 __tablename__ = 'custorder_item' 226 227 @declared_attr 228 def __table_args__(cls): 229 return cls.__customer_order_item_table_args__() + ( 230 sa.ForeignKeyConstraint(['order_uuid'], ['custorder.uuid'], 231 name='custorder_item_fk_order'), 232 ) 233 234 uuid = uuid_column() 235 236 order_uuid = sa.Column(sa.String(length=32), nullable=False) 237 order = orm.relationship(CustomerOrder, back_populates='items', doc=""" 238 Reference to the :class:`CustomerOrder` instance to which the item belongs. 239 """) 240 187 241 status_code = sa.Column(sa.Integer(), nullable=False) 188 189 # TODO190 def __str__(self):191 return str(self.product)192 242 193 243
Note: See TracChangeset
for help on using the changeset viewer.