Use new "download results" feature for CORE products

This commit is contained in:
Lance Edgar 2020-08-22 12:26:08 -05:00
parent 6270ec7d46
commit 622af7f23d
2 changed files with 24 additions and 53 deletions

View file

@ -36,10 +36,11 @@ from tailbone_corepos.db import CoreOfficeSession, ExtraCoreOfficeSessions
class CoreOfficeMasterView(MasterView):
"""
Master base class for Catapult views
Master base class for CORE-POS views
"""
supports_multiple_engines = True
engine_type_key = 'corepos'
has_local_times = True
labels = {
'id': "ID",
@ -66,11 +67,7 @@ class CoreOfficeMasterView(MasterView):
return CoreOfficeSession
def results_csv_session(self):
from corepos.db.office_op import Session as CoreSession
return CoreSession()
def results_xlsx_session(self):
def make_isolated_session(self):
from corepos.db.office_op import Session as CoreSession
return CoreSession()

View file

@ -40,8 +40,7 @@ class ProductView(CoreOfficeMasterView):
model_title = "CORE-POS Product"
url_prefix = '/core-pos/products'
route_prefix = 'corepos.products'
results_downloadable_csv = True
results_downloadable_xlsx = True
results_downloadable = True
labels = {
'id': "ID",
@ -142,13 +141,17 @@ class ProductView(CoreOfficeMasterView):
return '{}/item/ItemEditorPage.php?searchupc={}'.format(
office_url, product.upc)
def get_csv_fields(self):
fields = super(ProductView, self).get_csv_fields()
def download_results_fields_available(self, **kwargs):
fields = super(ProductView, self).download_results_fields_available(**kwargs)
# add our extra field
fields.append('superdepartment_number')
# but also, go ahead and cache the superdept mapping, for performance
return fields
def download_results_setup(self, fields, progress=None):
super(ProductView, self).download_results_setup(fields, progress=progress)
if 'superdepartment_number' in fields:
mapping = {}
super_departments = self.Session.query(corepos.SuperDepartment).all()
for superdept in super_departments:
@ -159,44 +162,15 @@ class ProductView(CoreOfficeMasterView):
mapping[superdept.child_id] = superdept.parent_id
self.supermap = mapping
return fields
def download_results_normalize(self, product, fields, **kwargs):
data = super(ProductView, self).download_results_normalize(product, fields, **kwargs)
def get_csv_row(self, product, fields):
row = super(ProductView, self).get_csv_row(product, fields)
row['superdepartment_number'] = None
if 'superdepartment_number' in fields:
data['superdepartment_number'] = None
if product.department_number in self.supermap:
row['superdepartment_number'] = self.supermap[product.department_number]
data['superdepartment_number'] = self.supermap[product.department_number]
return row
def get_xlsx_fields(self):
fields = super(ProductView, self).get_xlsx_fields()
# add our extra field
fields.append('superdepartment_number')
# but also, go ahead and cache the superdept mapping, for performance
mapping = {}
super_departments = self.Session.query(corepos.SuperDepartment).all()
for superdept in super_departments:
if superdept.child_id in mapping:
if superdept.parent_id < mapping[superdept.child_id]:
mapping[superdept.child_id] = superdept.parent_id
else:
mapping[superdept.child_id] = superdept.parent_id
self.supermap = mapping
return fields
def get_xlsx_row(self, product, fields):
row = super(ProductView, self).get_xlsx_row(product, fields)
row['superdepartment_number'] = None
if product.department_number in self.supermap:
row['superdepartment_number'] = self.supermap[product.department_number]
return row
return data
class ProductFlagView(CoreOfficeMasterView):