tweak batches
This commit is contained in:
parent
0a94d1215d
commit
37ee8b2ba8
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"),
|
||||
|
|
Loading…
Reference in a new issue