Add new base classes for customer order/item models
so that we can batch things out next
This commit is contained in:
parent
e1f58209d4
commit
b44f45b8fd
|
@ -49,7 +49,8 @@ from .products import (Brand, Tax, Product, ProductImage, ProductCode,
|
||||||
from .purchase import (PurchaseBase, PurchaseItemBase, PurchaseCreditBase,
|
from .purchase import (PurchaseBase, PurchaseItemBase, PurchaseCreditBase,
|
||||||
Purchase, PurchaseItem, PurchaseCredit)
|
Purchase, PurchaseItem, PurchaseCredit)
|
||||||
|
|
||||||
from .custorders import CustomerOrder, CustomerOrderItem, CustomerOrderItemEvent
|
from .custorders import (CustomerOrderBase, CustomerOrderItemBase,
|
||||||
|
CustomerOrder, CustomerOrderItem, CustomerOrderItemEvent)
|
||||||
|
|
||||||
from .messages import Message, MessageRecipient
|
from .messages import Message, MessageRecipient
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8; -*-
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2017 Lance Edgar
|
# Copyright © 2010-2020 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -32,21 +32,63 @@ import six
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
from sqlalchemy.ext.orderinglist import ordering_list
|
from sqlalchemy.ext.orderinglist import ordering_list
|
||||||
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
|
|
||||||
from rattail.db.model import Base, uuid_column
|
from rattail.db.model import Base, uuid_column
|
||||||
from rattail.db.model import Customer, Person, Product, User
|
from rattail.db.model import Customer, Person, Product, User
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
@six.python_2_unicode_compatible
|
||||||
class CustomerOrder(Base):
|
class CustomerOrderBase(object):
|
||||||
|
"""
|
||||||
|
Base class for customer orders; defines common fields.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def __table_args__(cls):
|
||||||
|
return cls.__customer_order_table_args__()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __customer_order_table_args__(cls):
|
||||||
|
table_name = cls.__tablename__
|
||||||
|
return (
|
||||||
|
sa.ForeignKeyConstraint(['customer_uuid'], ['customer.uuid'],
|
||||||
|
name='{}_fk_customer'.format(table_name)),
|
||||||
|
sa.ForeignKeyConstraint(['person_uuid'], ['person.uuid'],
|
||||||
|
name='{}_fk_person'.format(table_name)),
|
||||||
|
)
|
||||||
|
|
||||||
|
customer_uuid = sa.Column(sa.String(length=32), nullable=True)
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def customer(cls):
|
||||||
|
return orm.relationship(
|
||||||
|
Customer,
|
||||||
|
doc="""
|
||||||
|
Reference to the customer account for which the order exists.
|
||||||
|
""")
|
||||||
|
|
||||||
|
person_uuid = sa.Column(sa.String(length=32), nullable=True)
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def person(cls):
|
||||||
|
return orm.relationship(
|
||||||
|
Person,
|
||||||
|
doc="""
|
||||||
|
Reference to the person to whom the order applies.
|
||||||
|
""")
|
||||||
|
|
||||||
|
created = sa.Column(sa.DateTime(), nullable=False, default=datetime.datetime.utcnow, doc="""
|
||||||
|
Date and time when the order/batch was first created.
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
@six.python_2_unicode_compatible
|
||||||
|
class CustomerOrder(CustomerOrderBase, Base):
|
||||||
"""
|
"""
|
||||||
Represents an order placed by the customer.
|
Represents an order placed by the customer.
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'custorder'
|
__tablename__ = 'custorder'
|
||||||
__table_args__ = (
|
|
||||||
sa.ForeignKeyConstraint(['customer_uuid'], ['customer.uuid'], name='custorder_fk_customer'),
|
|
||||||
sa.ForeignKeyConstraint(['person_uuid'], ['person.uuid'], name='custorder_fk_person'),
|
|
||||||
)
|
|
||||||
|
|
||||||
uuid = uuid_column()
|
uuid = uuid_column()
|
||||||
|
|
||||||
|
@ -54,22 +96,6 @@ class CustomerOrder(Base):
|
||||||
Numeric, auto-increment ID for the order.
|
Numeric, auto-increment ID for the order.
|
||||||
""")
|
""")
|
||||||
|
|
||||||
customer_uuid = sa.Column(sa.String(length=32), nullable=True)
|
|
||||||
|
|
||||||
customer = orm.relationship(Customer, doc="""
|
|
||||||
Reference to the :class:`Customer` instance for whom the order exists.
|
|
||||||
""")
|
|
||||||
|
|
||||||
person_uuid = sa.Column(sa.String(length=32), nullable=True)
|
|
||||||
|
|
||||||
person = orm.relationship(Person, doc="""
|
|
||||||
Reference to the :class:`Person` instance for whom the order exists.
|
|
||||||
""")
|
|
||||||
|
|
||||||
created = sa.Column(sa.DateTime(), nullable=False, default=datetime.datetime.utcnow, doc="""
|
|
||||||
Date and time when the order was first created.
|
|
||||||
""")
|
|
||||||
|
|
||||||
status_code = sa.Column(sa.Integer(), nullable=False)
|
status_code = sa.Column(sa.Integer(), nullable=False)
|
||||||
|
|
||||||
items = orm.relationship('CustomerOrderItem', back_populates='order',
|
items = orm.relationship('CustomerOrderItem', back_populates='order',
|
||||||
|
@ -84,23 +110,22 @@ class CustomerOrder(Base):
|
||||||
|
|
||||||
|
|
||||||
@six.python_2_unicode_compatible
|
@six.python_2_unicode_compatible
|
||||||
class CustomerOrderItem(Base):
|
class CustomerOrderItemBase(object):
|
||||||
"""
|
"""
|
||||||
Represents a particular line item (product) within a customer order.
|
Base class for customer order line items.
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'custorder_item'
|
|
||||||
__table_args__ = (
|
|
||||||
sa.ForeignKeyConstraint(['order_uuid'], ['custorder.uuid'], name='custorder_item_fk_order'),
|
|
||||||
sa.ForeignKeyConstraint(['product_uuid'], ['product.uuid'], name='custorder_item_fk_product'),
|
|
||||||
)
|
|
||||||
|
|
||||||
uuid = uuid_column()
|
@declared_attr
|
||||||
|
def __table_args__(cls):
|
||||||
|
return cls.__customer_order_item_table_args__()
|
||||||
|
|
||||||
order_uuid = sa.Column(sa.String(length=32), nullable=False)
|
@classmethod
|
||||||
|
def __customer_order_item_table_args__(cls):
|
||||||
order = orm.relationship(CustomerOrder, back_populates='items', doc="""
|
table_name = cls.__tablename__
|
||||||
Reference to the :class:`CustomerOrder` instance to which the item belongs.
|
return (
|
||||||
""")
|
sa.ForeignKeyConstraint(['product_uuid'], ['product.uuid'],
|
||||||
|
name='{}_fk_product'.format(table_name)),
|
||||||
|
)
|
||||||
|
|
||||||
sequence = sa.Column(sa.Integer(), nullable=False, doc="""
|
sequence = sa.Column(sa.Integer(), nullable=False, doc="""
|
||||||
Numeric sequence for the item, i.e. its "line number". These values should
|
Numeric sequence for the item, i.e. its "line number". These values should
|
||||||
|
@ -110,9 +135,13 @@ class CustomerOrderItem(Base):
|
||||||
|
|
||||||
product_uuid = sa.Column(sa.String(length=32), nullable=True)
|
product_uuid = sa.Column(sa.String(length=32), nullable=True)
|
||||||
|
|
||||||
product = orm.relationship(Product, doc="""
|
@declared_attr
|
||||||
Reference to the :class:`Product` instance for the item.
|
def product(cls):
|
||||||
""")
|
return orm.relationship(
|
||||||
|
Product,
|
||||||
|
doc="""
|
||||||
|
Reference to the master product record for the line item.
|
||||||
|
""")
|
||||||
|
|
||||||
product_brand = sa.Column(sa.String(length=100), nullable=True, doc="""
|
product_brand = sa.Column(sa.String(length=100), nullable=True, doc="""
|
||||||
Brand name for the product being ordered. This should be a cache of the
|
Brand name for the product being ordered. This should be a cache of the
|
||||||
|
@ -184,11 +213,32 @@ class CustomerOrderItem(Base):
|
||||||
Transaction number in which payment for the order was taken, if applicable.
|
Transaction number in which payment for the order was taken, if applicable.
|
||||||
""")
|
""")
|
||||||
|
|
||||||
status_code = sa.Column(sa.Integer(), nullable=False)
|
|
||||||
|
|
||||||
# TODO
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.product)
|
return str(self.product or "(no product)")
|
||||||
|
|
||||||
|
|
||||||
|
@six.python_2_unicode_compatible
|
||||||
|
class CustomerOrderItem(CustomerOrderItemBase, Base):
|
||||||
|
"""
|
||||||
|
Represents a particular line item (product) within a customer order.
|
||||||
|
"""
|
||||||
|
__tablename__ = 'custorder_item'
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def __table_args__(cls):
|
||||||
|
return cls.__customer_order_item_table_args__() + (
|
||||||
|
sa.ForeignKeyConstraint(['order_uuid'], ['custorder.uuid'],
|
||||||
|
name='custorder_item_fk_order'),
|
||||||
|
)
|
||||||
|
|
||||||
|
uuid = uuid_column()
|
||||||
|
|
||||||
|
order_uuid = sa.Column(sa.String(length=32), nullable=False)
|
||||||
|
order = orm.relationship(CustomerOrder, back_populates='items', doc="""
|
||||||
|
Reference to the :class:`CustomerOrder` instance to which the item belongs.
|
||||||
|
""")
|
||||||
|
|
||||||
|
status_code = sa.Column(sa.Integer(), nullable=False)
|
||||||
|
|
||||||
|
|
||||||
class CustomerOrderItemEvent(Base):
|
class CustomerOrderItemEvent(Base):
|
||||||
|
|
Loading…
Reference in a new issue