Use new "download results" feature for CORE products
This commit is contained in:
parent
6270ec7d46
commit
622af7f23d
|
@ -36,10 +36,11 @@ from tailbone_corepos.db import CoreOfficeSession, ExtraCoreOfficeSessions
|
||||||
|
|
||||||
class CoreOfficeMasterView(MasterView):
|
class CoreOfficeMasterView(MasterView):
|
||||||
"""
|
"""
|
||||||
Master base class for Catapult views
|
Master base class for CORE-POS views
|
||||||
"""
|
"""
|
||||||
supports_multiple_engines = True
|
supports_multiple_engines = True
|
||||||
engine_type_key = 'corepos'
|
engine_type_key = 'corepos'
|
||||||
|
has_local_times = True
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
'id': "ID",
|
'id': "ID",
|
||||||
|
@ -66,11 +67,7 @@ class CoreOfficeMasterView(MasterView):
|
||||||
|
|
||||||
return CoreOfficeSession
|
return CoreOfficeSession
|
||||||
|
|
||||||
def results_csv_session(self):
|
def make_isolated_session(self):
|
||||||
from corepos.db.office_op import Session as CoreSession
|
|
||||||
return CoreSession()
|
|
||||||
|
|
||||||
def results_xlsx_session(self):
|
|
||||||
from corepos.db.office_op import Session as CoreSession
|
from corepos.db.office_op import Session as CoreSession
|
||||||
return CoreSession()
|
return CoreSession()
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,7 @@ class ProductView(CoreOfficeMasterView):
|
||||||
model_title = "CORE-POS Product"
|
model_title = "CORE-POS Product"
|
||||||
url_prefix = '/core-pos/products'
|
url_prefix = '/core-pos/products'
|
||||||
route_prefix = 'corepos.products'
|
route_prefix = 'corepos.products'
|
||||||
results_downloadable_csv = True
|
results_downloadable = True
|
||||||
results_downloadable_xlsx = True
|
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
'id': "ID",
|
'id': "ID",
|
||||||
|
@ -142,61 +141,36 @@ class ProductView(CoreOfficeMasterView):
|
||||||
return '{}/item/ItemEditorPage.php?searchupc={}'.format(
|
return '{}/item/ItemEditorPage.php?searchupc={}'.format(
|
||||||
office_url, product.upc)
|
office_url, product.upc)
|
||||||
|
|
||||||
def get_csv_fields(self):
|
def download_results_fields_available(self, **kwargs):
|
||||||
fields = super(ProductView, self).get_csv_fields()
|
fields = super(ProductView, self).download_results_fields_available(**kwargs)
|
||||||
|
|
||||||
# add our extra field
|
|
||||||
fields.append('superdepartment_number')
|
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
|
return fields
|
||||||
|
|
||||||
def get_csv_row(self, product, fields):
|
def download_results_setup(self, fields, progress=None):
|
||||||
row = super(ProductView, self).get_csv_row(product, fields)
|
super(ProductView, self).download_results_setup(fields, progress=progress)
|
||||||
|
|
||||||
row['superdepartment_number'] = None
|
if 'superdepartment_number' in fields:
|
||||||
if product.department_number in self.supermap:
|
mapping = {}
|
||||||
row['superdepartment_number'] = self.supermap[product.department_number]
|
super_departments = self.Session.query(corepos.SuperDepartment).all()
|
||||||
|
for superdept in super_departments:
|
||||||
return row
|
if superdept.child_id in mapping:
|
||||||
|
if superdept.parent_id < mapping[superdept.child_id]:
|
||||||
def get_xlsx_fields(self):
|
mapping[superdept.child_id] = superdept.parent_id
|
||||||
fields = super(ProductView, self).get_xlsx_fields()
|
else:
|
||||||
|
|
||||||
# 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
|
mapping[superdept.child_id] = superdept.parent_id
|
||||||
else:
|
self.supermap = mapping
|
||||||
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_xlsx_row(self, product, fields):
|
if 'superdepartment_number' in fields:
|
||||||
row = super(ProductView, self).get_xlsx_row(product, fields)
|
data['superdepartment_number'] = None
|
||||||
|
if product.department_number in self.supermap:
|
||||||
|
data['superdepartment_number'] = self.supermap[product.department_number]
|
||||||
|
|
||||||
row['superdepartment_number'] = None
|
return data
|
||||||
if product.department_number in self.supermap:
|
|
||||||
row['superdepartment_number'] = self.supermap[product.department_number]
|
|
||||||
|
|
||||||
return row
|
|
||||||
|
|
||||||
|
|
||||||
class ProductFlagView(CoreOfficeMasterView):
|
class ProductFlagView(CoreOfficeMasterView):
|
||||||
|
|
Loading…
Reference in a new issue