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
 
@@ -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):
rattail/db/extension/__init__.py
Show inline comments
 
@@ -32,4 +32,4 @@ 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
 
@@ -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
rattail/db/extension/model.py
Show inline comments
 
@@ -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 "<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.
 
@@ -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 "<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):
 
    """
 
@@ -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)
0 comments (0 inline, 0 general)