Files
@ 527f617822ba
Branch filter:
Location: rattail-project/rattail/rattail/db/model/stores.py
527f617822ba
3.4 KiB
text/x-python
Update changelog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | # -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
# more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Data Models for Stores
"""
from __future__ import unicode_literals, absolute_import
import sqlalchemy as sa
from sqlalchemy.orm import relationship
from sqlalchemy.ext.orderinglist import ordering_list
from .core import Base, uuid_column
from .contact import PhoneNumber, EmailAddress
class Store(Base):
"""
Represents a store (physical or otherwise) within the organization.
"""
__tablename__ = 'store'
__versioned__ = {}
uuid = uuid_column()
id = sa.Column(sa.String(length=10))
name = sa.Column(sa.String(length=100))
database_key = sa.Column(sa.String(length=30))
def __unicode__(self):
return unicode(self.name or '')
def add_email_address(self, address, type='Info'):
email = StoreEmailAddress(address=address, type=type)
self.emails.append(email)
def add_phone_number(self, number, type='Voice'):
phone = StorePhoneNumber(number=number, type=type)
self.phones.append(phone)
class StorePhoneNumber(PhoneNumber):
"""
Represents a phone (or fax) number associated with a store.
"""
__mapper_args__ = {'polymorphic_identity': 'Store'}
Store.phones = relationship(
StorePhoneNumber,
backref='store',
primaryjoin=StorePhoneNumber.parent_uuid == Store.uuid,
foreign_keys=[StorePhoneNumber.parent_uuid],
collection_class=ordering_list('preference', count_from=1),
order_by=StorePhoneNumber.preference,
cascade='save-update, merge, delete, delete-orphan')
Store.phone = relationship(
StorePhoneNumber,
primaryjoin=sa.and_(
StorePhoneNumber.parent_uuid == Store.uuid,
StorePhoneNumber.preference == 1),
foreign_keys=[StorePhoneNumber.parent_uuid],
uselist=False,
viewonly=True)
class StoreEmailAddress(EmailAddress):
"""
Represents an email address associated with a store.
"""
__mapper_args__ = {'polymorphic_identity': 'Store'}
Store.emails = relationship(
StoreEmailAddress,
backref='store',
primaryjoin=StoreEmailAddress.parent_uuid == Store.uuid,
foreign_keys=[StoreEmailAddress.parent_uuid],
collection_class=ordering_list('preference', count_from=1),
order_by=StoreEmailAddress.preference,
cascade='save-update, merge, delete, delete-orphan')
Store.email = relationship(
StoreEmailAddress,
primaryjoin=sa.and_(
StoreEmailAddress.parent_uuid == Store.uuid,
StoreEmailAddress.preference == 1),
foreign_keys=[StoreEmailAddress.parent_uuid],
uselist=False,
viewonly=True)
|