From 0c9db819b7ae67c6e61857658c10523e8d85f73d 2012-08-06 16:57:12 From: Lance Edgar Date: 2012-08-06 16:57:12 Subject: [PATCH] add VendorPhone, VendorContact, Product.unit_of_measure --- diff --git a/rattail/db/cache.py b/rattail/db/cache.py index 640a99b154ed0b30c781d421885cb909cb30466d..9f0cbfa09c3dc39f2776e9739a72e80faa501bd0 100644 --- a/rattail/db/cache.py +++ b/rattail/db/cache.py @@ -56,7 +56,7 @@ class DataCacher(edbob.Object): prog = None if progress: - prog = progress("Reading Rattail %s records into cache" % self.name, count) + prog = progress("Reading %s records into cache" % self.name, count) cancel = False for i, instance in enumerate(query, 1): diff --git a/rattail/db/extension/__init__.py b/rattail/db/extension/__init__.py index 4cadb155b8096bca3f5d79527c7d905ea6944ec9..e244a448b05e7ae63dc7f00329d91b7531ac7e37 100644 --- a/rattail/db/extension/__init__.py +++ b/rattail/db/extension/__init__.py @@ -32,4 +32,4 @@ from edbob.db.extensions import Extension class RattailExtension(Extension): name = 'rattail' - required_extensions = ['auth'] + required_extensions = ['contact', 'auth'] diff --git a/rattail/db/extension/enum.py b/rattail/db/extension/enum.py index 02c5d8812981387e3dfeca0f07318a598dbb8d4e..f4ffd932914185c48c6ac53941163c8c48032d9f 100644 --- a/rattail/db/extension/enum.py +++ b/rattail/db/extension/enum.py @@ -76,6 +76,16 @@ PRICE_TYPE = { PRICE_TYPE_MFR_SUGGESTED : "Manufacturer's Suggested", } + +UNIT_OF_MEASURE_EACH = '01' +UNIT_OF_MEASURE_POUND = '49' + +UNIT_OF_MEASURE = { + UNIT_OF_MEASURE_EACH : "Each", + UNIT_OF_MEASURE_POUND : "Pound", + } + + # VENDOR_CATALOG_NOT_PARSED = 1 # VENDOR_CATALOG_PARSED = 2 # VENDOR_CATALOG_COGNIZED = 3 diff --git a/rattail/db/extension/model.py b/rattail/db/extension/model.py index 2fdcbfb258654281bcb4e0f4d015c133904c6ee2..326c98cae55bbe125c9f61406e6326f316a88ece 100644 --- a/rattail/db/extension/model.py +++ b/rattail/db/extension/model.py @@ -32,19 +32,21 @@ import re from sqlalchemy import (Column, String, Integer, Date, DateTime, Boolean, Text, ForeignKey, BigInteger, Numeric) +from sqlalchemy import and_ from sqlalchemy.orm import relationship, object_session from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.orderinglist import ordering_list import edbob from edbob.db.model import Base, uuid_column -from edbob.db.extensions.auth import Person +from edbob.db.extensions.contact import Person, Phone, PersonPhone __all__ = ['SilColumn', 'BatchDictionaryColumn', 'BatchDictionary', 'BatchTerminalColumn', 'BatchTerminal', 'BatchColumn', 'Batch', 'Brand', 'Department', 'Subdepartment', 'Category', - 'Product', 'Employee', 'Vendor', 'ProductCost', 'ProductPrice'] + 'Product', 'Employee', 'Vendor', 'VendorContact', 'VendorPhone', + 'ProductCost', 'ProductPrice'] sil_type_pattern = re.compile(r'^(CHAR|NUMBER)\((\d+(?:\,\d+)?)\)$') @@ -578,6 +580,36 @@ class Category(Base): return unicode(self.name or '') +class VendorPhone(Phone): + """ + Represents a phone (or fax) number associated with a :class:`Vendor`. + """ + + __mapper_args__ = {'polymorphic_identity': 'Vendor'} + + +class VendorContact(Base): + """ + Represents a point of contact (e.g. salesperson) for a vendor, from the + retailer's perspective. + """ + + __tablename__ = 'vendor_contacts' + + uuid = uuid_column() + vendor_uuid = Column(String(32), ForeignKey('vendors.uuid'), nullable=False) + person_uuid = Column(String(32), ForeignKey('people.uuid'), nullable=False) + preference = Column(Integer, nullable=False) + + person = relationship(Person) + + def __repr__(self): + return "" % (self.vendor, self.person) + + def __unicode__(self): + return unicode(self.person) + + class Vendor(Base): """ Represents a vendor from which products are purchased by the store. @@ -589,12 +621,43 @@ class Vendor(Base): id = Column(String(15)) name = Column(String(40)) + contacts = relationship(VendorContact, backref='vendor', + collection_class=ordering_list('preference', count_from=1), + order_by=VendorContact.preference) + def __repr__(self): return "" % self.name def __unicode__(self): return unicode(self.name or '') +Vendor.phones = relationship( + VendorPhone, + backref='vendor', + primaryjoin=VendorPhone.parent_uuid == Vendor.uuid, + foreign_keys=[VendorPhone.parent_uuid], + collection_class=ordering_list('preference', count_from=1), + order_by=VendorPhone.preference) + +Vendor.phone = relationship( + VendorPhone, + primaryjoin=and_( + VendorPhone.parent_uuid == Vendor.uuid, + VendorPhone.preference == 1, + ), + foreign_keys=[VendorPhone.parent_uuid], + uselist=False, + viewonly=True) + +Vendor.contact = relationship( + VendorContact, + primaryjoin=and_( + VendorContact.vendor_uuid == Vendor.uuid, + VendorContact.preference == 1, + ), + uselist=False, + viewonly=True) + class ProductCost(Base): """ @@ -670,6 +733,7 @@ class Product(Base): description = Column(String(60)) description2 = Column(String(60)) size = Column(String(30)) + unit_of_measure = Column(String(4)) regular_price_uuid = Column( String(32), @@ -747,3 +811,13 @@ class Employee(Base): def __unicode__(self): return unicode(self.person) + +Employee.phone = relationship( + PersonPhone, + primaryjoin=and_( + PersonPhone.parent_uuid == Employee.person_uuid, + PersonPhone.preference == 1, + ), + foreign_keys=[PersonPhone.parent_uuid], + uselist=False, + viewonly=True)