Changeset - 37ee8b2ba82e
[Not reviewed]
0 3 0
Lance Edgar (lance) - 12 years ago 2012-09-28 09:53:20
lance@edbob.org
tweak batches
3 files changed with 42 insertions and 13 deletions:
0 comments (0 inline, 0 general)
rattail/batches/providers/__init__.py
Show inline comments
 
@@ -46,32 +46,49 @@ class BatchProvider(edbob.Object):
 
    action_type = None
 
    purge_date_offset = 90
 

	
 
    session = None
 

	
 
    def add_columns(self, batch):
 
        pass
 

	
 
    def add_rows_begin(self, batch):
 
    def add_rows_begin(self, batch, data):
 
        pass
 

	
 
    def add_rows(self, batch, query, progress=None):
 
        self.add_rows_begin(batch)
 
    def add_rows(self, batch, data, progress=None):
 

	
 
        result = self.add_rows_begin(batch, data)
 
        if result is not None and not result:
 
            return False
 

	
 
        prog = None
 
        if progress:
 
            prog = progress("Adding rows to batch \"%s\"" % batch.description,
 
                            query.count())
 
                            data.count())
 
        cancel = False
 
        for i, instance in enumerate(query, 1):
 
            self.add_row(batch, instance)
 
        for i, datum in enumerate(data, 1):
 
            self.add_row(batch, datum)
 
            if prog and not prog.update(i):
 
                cancel = True
 
                break
 
        if prog:
 
            prog.destroy()
 

	
 
        if not cancel:
 
            result = self.add_rows_end(batch, progress)
 
            if result is not None:
 
                cancel = not result
 

	
 
        return not cancel
 

	
 
    def add_rows_end(self, batch, progress=None):
 
        pass
 

	
 
    def execute(self, batch, progress=None):
 
        raise NotImplementedError
 

	
 
    def make_batch(self, session, data, progress=None):
 
        self.session = session
 

	
 
        batch = rattail.Batch()
 
        batch.provider = self.name
 
        batch.source = self.source
rattail/db/extension/model.py
Show inline comments
 
@@ -26,6 +26,8 @@
 
``rattail.db.extension.model`` -- Schema Definition
 
"""
 

	
 
import logging
 

	
 
from sqlalchemy import Column, ForeignKey
 
from sqlalchemy import String, Integer, DateTime, Date, Boolean, Numeric, Text
 
from sqlalchemy import types
 
@@ -47,11 +49,15 @@ from rattail.gpc import GPCType
 

	
 
__all__ = ['Change', 'Store', 'StoreEmailAddress', 'StorePhoneNumber',
 
           'Department', 'Subdepartment', 'Brand', 'Category', 'Vendor',
 
           'VendorContact', 'VendorPhoneNumber', 'Product', 'ProductCost',
 
           'ProductPrice', 'Customer', 'CustomerEmailAddress',
 
           'CustomerPhoneNumber', 'CustomerGroup', 'CustomerGroupAssignment',
 
           'CustomerPerson', 'Employee', 'EmployeeEmailAddress',
 
           'EmployeePhoneNumber', 'BatchColumn', 'Batch', 'LabelProfile']
 
           'VendorContact', 'VendorPhoneNumber', 'VendorEmailAddress',
 
           'Product', 'ProductCost', 'ProductPrice', 'Customer',
 
           'CustomerEmailAddress', 'CustomerPhoneNumber', 'CustomerGroup',
 
           'CustomerGroupAssignment', 'CustomerPerson', 'Employee',
 
           'EmployeeEmailAddress', 'EmployeePhoneNumber',
 
           'BatchColumn', 'Batch', 'LabelProfile']
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class Change(Base):
 
@@ -67,7 +73,8 @@ class Change(Base):
 
    deleted = Column(Boolean)
 

	
 
    def __repr__(self):
 
        return "<Change: %s, %s>" % (self.class_name, self.uuid)
 
        status = 'deleted' if self.deleted else 'new/changed'
 
        return "<Change: %s, %s, %s>" % (self.class_name, self.uuid, status)
 

	
 

	
 
class BatchColumn(Base):
 
@@ -205,15 +212,19 @@ class Batch(Base):
 
        Drops the batch's data table from the database.
 
        """
 

	
 
        log.debug("Batch.drop_table: Dropping table for batch: %s, %s (%s)"
 
                  % (self.id, self.description, self.uuid))
 
        session = object_session(self)
 
        self.rowclass.__table__.drop(session.bind)
 

	
 
    def execute(self, progress=None):
 
        provider = self.get_provider()
 
        assert provider
 
        provider.execute(self, progress)
 
        if not provider.execute(self, progress):
 
            return False
 
        self.executed = edbob.utc_time(naive=True)
 
        object_session(self).flush()
 
        return True
 

	
 
    def get_provider(self):
 
        assert self.provider
rattail/sil/columns.py
Show inline comments
 
@@ -71,6 +71,7 @@ def provide_columns():
 
        SC('F02',       'CHAR(20)',     "Descriptor",                           "Description"),
 
        SC('F04',       'NUMBER(4,0)',  "Sub-Department Number"),
 
        SC('F22',       'CHAR(30)',     "Size Description"),
 
        SC('F26',       'CHAR(15)',     "Primary Item Code (User)"),
 
        SC('F90',       'FLAG(1)',      "Authorized DSD Item"),
 
        SC('F94',       'NUMBER(2,0)',  "Shelf Tag Quantity"),
 
        SC('F95',       'CHAR(3)',      "Shelf Tag Type"),
0 comments (0 inline, 0 general)