Add products API route to fetch label profiles for use w/ printing

This commit is contained in:
Lance Edgar 2023-09-02 10:56:06 -05:00
parent de373a683b
commit 75caface6b
2 changed files with 29 additions and 7 deletions

View file

@ -125,6 +125,24 @@ class ProductView(APIMasterView):
return {'ok': True,
'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):
app = self.get_rattail_app()
label_handler = app.get_label_handler()
@ -176,6 +194,13 @@ class ProductView(APIMasterView):
permission='{}.list'.format(permission_prefix))
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 = Service(name='{}.print_labels'.format(route_prefix),
path='{}/print-labels'.format(collection_url_prefix))

View file

@ -658,16 +658,13 @@ class ProductView(MasterView):
return pretty_quantity(inventory.on_order)
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
if self.expose_label_printing:
kwargs['label_profiles'] = self.Session.query(model.LabelProfile)\
.filter(model.LabelProfile.visible == True)\
.order_by(model.LabelProfile.ordinal)\
.all()
kwargs['label_profiles'] = label_handler.get_label_profiles(self.Session())
kwargs['quick_label_speedbump_threshold'] = self.rattail_config.getint(
'tailbone', 'products.quick_labels.speedbump_threshold')