Add products API route to fetch label profiles for use w/ printing
This commit is contained in:
parent
de373a683b
commit
75caface6b
|
@ -125,6 +125,24 @@ class ProductView(APIMasterView):
|
||||||
return {'ok': True,
|
return {'ok': True,
|
||||||
'product': self.normalize(product)}
|
'product': self.normalize(product)}
|
||||||
|
|
||||||
|
def label_profiles(self):
|
||||||
|
"""
|
||||||
|
Returns the set of label profiles available for use with
|
||||||
|
printing label for product.
|
||||||
|
"""
|
||||||
|
app = self.get_rattail_app()
|
||||||
|
label_handler = app.get_label_handler()
|
||||||
|
model = self.model
|
||||||
|
|
||||||
|
profiles = []
|
||||||
|
for profile in label_handler.get_label_profiles(self.Session()):
|
||||||
|
profiles.append({
|
||||||
|
'uuid': profile.uuid,
|
||||||
|
'description': profile.description,
|
||||||
|
})
|
||||||
|
|
||||||
|
return {'label_profiles': profiles}
|
||||||
|
|
||||||
def print_labels(self):
|
def print_labels(self):
|
||||||
app = self.get_rattail_app()
|
app = self.get_rattail_app()
|
||||||
label_handler = app.get_label_handler()
|
label_handler = app.get_label_handler()
|
||||||
|
@ -176,6 +194,13 @@ class ProductView(APIMasterView):
|
||||||
permission='{}.list'.format(permission_prefix))
|
permission='{}.list'.format(permission_prefix))
|
||||||
config.add_cornice_service(quick_lookup)
|
config.add_cornice_service(quick_lookup)
|
||||||
|
|
||||||
|
# label profiles
|
||||||
|
label_profiles = Service(name=f'{route_prefix}.label_profiles',
|
||||||
|
path=f'{collection_url_prefix}/label-profiles')
|
||||||
|
label_profiles.add_view('GET', 'label_profiles', klass=cls,
|
||||||
|
permission=f'{permission_prefix}.print_labels')
|
||||||
|
config.add_cornice_service(label_profiles)
|
||||||
|
|
||||||
# print labels
|
# print labels
|
||||||
print_labels = Service(name='{}.print_labels'.format(route_prefix),
|
print_labels = Service(name='{}.print_labels'.format(route_prefix),
|
||||||
path='{}/print-labels'.format(collection_url_prefix))
|
path='{}/print-labels'.format(collection_url_prefix))
|
||||||
|
|
|
@ -658,16 +658,13 @@ class ProductView(MasterView):
|
||||||
return pretty_quantity(inventory.on_order)
|
return pretty_quantity(inventory.on_order)
|
||||||
|
|
||||||
def template_kwargs_index(self, **kwargs):
|
def template_kwargs_index(self, **kwargs):
|
||||||
kwargs = super(ProductView, self).template_kwargs_index(**kwargs)
|
kwargs = super().template_kwargs_index(**kwargs)
|
||||||
|
app = self.get_rattail_app()
|
||||||
|
label_handler = app.get_label_handler()
|
||||||
model = self.model
|
model = self.model
|
||||||
|
|
||||||
if self.expose_label_printing:
|
if self.expose_label_printing:
|
||||||
|
kwargs['label_profiles'] = label_handler.get_label_profiles(self.Session())
|
||||||
kwargs['label_profiles'] = self.Session.query(model.LabelProfile)\
|
|
||||||
.filter(model.LabelProfile.visible == True)\
|
|
||||||
.order_by(model.LabelProfile.ordinal)\
|
|
||||||
.all()
|
|
||||||
|
|
||||||
kwargs['quick_label_speedbump_threshold'] = self.rattail_config.getint(
|
kwargs['quick_label_speedbump_threshold'] = self.rattail_config.getint(
|
||||||
'tailbone', 'products.quick_labels.speedbump_threshold')
|
'tailbone', 'products.quick_labels.speedbump_threshold')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue