Changeset - 0c9db819b7ae
[Not reviewed]
0 4 0
Lance Edgar (lance) - 12 years ago 2012-08-06 16:57:12
lance@edbob.org
add VendorPhone, VendorContact, Product.unit_of_measure
4 files changed with 88 insertions and 4 deletions:
0 comments (0 inline, 0 general)
rattail/db/cache.py
Show inline comments
 
@@ -53,13 +53,13 @@ class DataCacher(edbob.Object):
 
        count = query.count()
 
        if not count:
 
            return self.instances
 
        
 
        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):
 
            self.cache_instance(instance)
 
            if prog and not prog.update(i):
 
                cancel = True
rattail/db/extension/__init__.py
Show inline comments
 
@@ -29,7 +29,7 @@
 
from edbob.db.extensions import Extension
 

	
 

	
 
class RattailExtension(Extension):
 

	
 
    name = 'rattail'
 
    required_extensions = ['auth']
 
    required_extensions = ['contact', 'auth']
rattail/db/extension/enum.py
Show inline comments
 
@@ -73,12 +73,22 @@ PRICE_TYPE = {
 
    PRICE_TYPE_MANAGER_SPECIAL  : "Manager Special",
 
    PRICE_TYPE_ALTERNATE        : "Alternate Price",
 
    PRICE_TYPE_FREQUENT_SHOPPER : "Frequent Shopper",
 
    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
 
# VENDOR_CATALOG_PROCESSED        = 4
 

	
 
# VENDOR_CATALOG_STATUS = {
rattail/db/extension/model.py
Show inline comments
 
@@ -29,25 +29,27 @@
 
from __future__ import absolute_import
 

	
 
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+)?)\)$')
 

	
 

	
 
class SilColumn(Base):
 
    """
 
@@ -575,29 +577,90 @@ class Category(Base):
 
        return str(self.name or '')
 

	
 
    def __unicode__(self):
 
        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 "<VendorContact: %s, %s>" % (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.
 
    """
 

	
 
    __tablename__ = 'vendors'
 

	
 
    uuid = uuid_column()
 
    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 "<Vendor: %s>" % 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):
 
    """
 
    Represents a source from which a product may be obtained via purchase.
 
    """
 

	
 
@@ -667,12 +730,13 @@ class Product(Base):
 
    subdepartment_uuid = Column(String(32), ForeignKey('subdepartments.uuid'))
 
    category_uuid = Column(String(32), ForeignKey('categories.uuid'))
 
    brand_uuid = Column(String(32), ForeignKey('brands.uuid'))
 
    description = Column(String(60))
 
    description2 = Column(String(60))
 
    size = Column(String(30))
 
    unit_of_measure = Column(String(4))
 

	
 
    regular_price_uuid = Column(
 
        String(32),
 
        ForeignKey('product_prices.uuid',
 
                   use_alter=True,
 
                   name='products_regular_price_uuid_fkey'))
 
@@ -744,6 +808,16 @@ class Employee(Base):
 

	
 
    def __repr__(self):
 
        return "<Employee: %s>" % self.person
 

	
 
    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)
0 comments (0 inline, 0 general)