diff --git a/rattail/batches/providers/__init__.py b/rattail/batches/providers/__init__.py index 729629dcff42b5c6561de9111b98ed39fc566d8d..610342dd11e1331a4b7a56759e874e2646324714 100644 --- a/rattail/batches/providers/__init__.py +++ b/rattail/batches/providers/__init__.py @@ -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 diff --git a/rattail/db/extension/model.py b/rattail/db/extension/model.py index a648794f0da6a387a6f90c5eee97626f35de9bc5..7165932c67b83901027df3df6d59971c1aa55c24 100644 --- a/rattail/db/extension/model.py +++ b/rattail/db/extension/model.py @@ -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 "" % (self.class_name, self.uuid) + status = 'deleted' if self.deleted else 'new/changed' + return "" % (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 diff --git a/rattail/sil/columns.py b/rattail/sil/columns.py index 4cc17afc8b81fe39c0296f6d3006f0db012c1d3f..53f4cfbe2df2f407769e8b575572b49cbf08f4f8 100644 --- a/rattail/sil/columns.py +++ b/rattail/sil/columns.py @@ -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"),