tweak batches
This commit is contained in:
parent
0a94d1215d
commit
37ee8b2ba8
|
@ -46,32 +46,49 @@ class BatchProvider(edbob.Object):
|
||||||
action_type = None
|
action_type = None
|
||||||
purge_date_offset = 90
|
purge_date_offset = 90
|
||||||
|
|
||||||
|
session = None
|
||||||
|
|
||||||
def add_columns(self, batch):
|
def add_columns(self, batch):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def add_rows_begin(self, batch):
|
def add_rows_begin(self, batch, data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def add_rows(self, batch, query, progress=None):
|
def add_rows(self, batch, data, progress=None):
|
||||||
self.add_rows_begin(batch)
|
|
||||||
|
result = self.add_rows_begin(batch, data)
|
||||||
|
if result is not None and not result:
|
||||||
|
return False
|
||||||
|
|
||||||
prog = None
|
prog = None
|
||||||
if progress:
|
if progress:
|
||||||
prog = progress("Adding rows to batch \"%s\"" % batch.description,
|
prog = progress("Adding rows to batch \"%s\"" % batch.description,
|
||||||
query.count())
|
data.count())
|
||||||
cancel = False
|
cancel = False
|
||||||
for i, instance in enumerate(query, 1):
|
for i, datum in enumerate(data, 1):
|
||||||
self.add_row(batch, instance)
|
self.add_row(batch, datum)
|
||||||
if prog and not prog.update(i):
|
if prog and not prog.update(i):
|
||||||
cancel = True
|
cancel = True
|
||||||
break
|
break
|
||||||
if prog:
|
if prog:
|
||||||
prog.destroy()
|
prog.destroy()
|
||||||
|
|
||||||
|
if not cancel:
|
||||||
|
result = self.add_rows_end(batch, progress)
|
||||||
|
if result is not None:
|
||||||
|
cancel = not result
|
||||||
|
|
||||||
return not cancel
|
return not cancel
|
||||||
|
|
||||||
|
def add_rows_end(self, batch, progress=None):
|
||||||
|
pass
|
||||||
|
|
||||||
def execute(self, batch, progress=None):
|
def execute(self, batch, progress=None):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def make_batch(self, session, data, progress=None):
|
def make_batch(self, session, data, progress=None):
|
||||||
|
self.session = session
|
||||||
|
|
||||||
batch = rattail.Batch()
|
batch = rattail.Batch()
|
||||||
batch.provider = self.name
|
batch.provider = self.name
|
||||||
batch.source = self.source
|
batch.source = self.source
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
``rattail.db.extension.model`` -- Schema Definition
|
``rattail.db.extension.model`` -- Schema Definition
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from sqlalchemy import Column, ForeignKey
|
from sqlalchemy import Column, ForeignKey
|
||||||
from sqlalchemy import String, Integer, DateTime, Date, Boolean, Numeric, Text
|
from sqlalchemy import String, Integer, DateTime, Date, Boolean, Numeric, Text
|
||||||
from sqlalchemy import types
|
from sqlalchemy import types
|
||||||
|
@ -47,11 +49,15 @@ from rattail.gpc import GPCType
|
||||||
|
|
||||||
__all__ = ['Change', 'Store', 'StoreEmailAddress', 'StorePhoneNumber',
|
__all__ = ['Change', 'Store', 'StoreEmailAddress', 'StorePhoneNumber',
|
||||||
'Department', 'Subdepartment', 'Brand', 'Category', 'Vendor',
|
'Department', 'Subdepartment', 'Brand', 'Category', 'Vendor',
|
||||||
'VendorContact', 'VendorPhoneNumber', 'Product', 'ProductCost',
|
'VendorContact', 'VendorPhoneNumber', 'VendorEmailAddress',
|
||||||
'ProductPrice', 'Customer', 'CustomerEmailAddress',
|
'Product', 'ProductCost', 'ProductPrice', 'Customer',
|
||||||
'CustomerPhoneNumber', 'CustomerGroup', 'CustomerGroupAssignment',
|
'CustomerEmailAddress', 'CustomerPhoneNumber', 'CustomerGroup',
|
||||||
'CustomerPerson', 'Employee', 'EmployeeEmailAddress',
|
'CustomerGroupAssignment', 'CustomerPerson', 'Employee',
|
||||||
'EmployeePhoneNumber', 'BatchColumn', 'Batch', 'LabelProfile']
|
'EmployeeEmailAddress', 'EmployeePhoneNumber',
|
||||||
|
'BatchColumn', 'Batch', 'LabelProfile']
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Change(Base):
|
class Change(Base):
|
||||||
|
@ -67,7 +73,8 @@ class Change(Base):
|
||||||
deleted = Column(Boolean)
|
deleted = Column(Boolean)
|
||||||
|
|
||||||
def __repr__(self):
|
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):
|
class BatchColumn(Base):
|
||||||
|
@ -205,15 +212,19 @@ class Batch(Base):
|
||||||
Drops the batch's data table from the database.
|
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)
|
session = object_session(self)
|
||||||
self.rowclass.__table__.drop(session.bind)
|
self.rowclass.__table__.drop(session.bind)
|
||||||
|
|
||||||
def execute(self, progress=None):
|
def execute(self, progress=None):
|
||||||
provider = self.get_provider()
|
provider = self.get_provider()
|
||||||
assert provider
|
assert provider
|
||||||
provider.execute(self, progress)
|
if not provider.execute(self, progress):
|
||||||
|
return False
|
||||||
self.executed = edbob.utc_time(naive=True)
|
self.executed = edbob.utc_time(naive=True)
|
||||||
object_session(self).flush()
|
object_session(self).flush()
|
||||||
|
return True
|
||||||
|
|
||||||
def get_provider(self):
|
def get_provider(self):
|
||||||
assert self.provider
|
assert self.provider
|
||||||
|
|
|
@ -71,6 +71,7 @@ def provide_columns():
|
||||||
SC('F02', 'CHAR(20)', "Descriptor", "Description"),
|
SC('F02', 'CHAR(20)', "Descriptor", "Description"),
|
||||||
SC('F04', 'NUMBER(4,0)', "Sub-Department Number"),
|
SC('F04', 'NUMBER(4,0)', "Sub-Department Number"),
|
||||||
SC('F22', 'CHAR(30)', "Size Description"),
|
SC('F22', 'CHAR(30)', "Size Description"),
|
||||||
|
SC('F26', 'CHAR(15)', "Primary Item Code (User)"),
|
||||||
SC('F90', 'FLAG(1)', "Authorized DSD Item"),
|
SC('F90', 'FLAG(1)', "Authorized DSD Item"),
|
||||||
SC('F94', 'NUMBER(2,0)', "Shelf Tag Quantity"),
|
SC('F94', 'NUMBER(2,0)', "Shelf Tag Quantity"),
|
||||||
SC('F95', 'CHAR(3)', "Shelf Tag Type"),
|
SC('F95', 'CHAR(3)', "Shelf Tag Type"),
|
||||||
|
|
Loading…
Reference in a new issue