Improve basic support for unit/pack info when viewing product details

This commit is contained in:
Lance Edgar 2018-07-08 00:01:14 -05:00
parent 9149902c78
commit 3dfdb26502
3 changed files with 55 additions and 14 deletions

View file

@ -102,8 +102,9 @@ class ProductsView(MasterView):
'unit_size',
'unit_of_measure',
'size',
'unit',
'packs',
'pack_size',
'unit',
'default_pack',
'case_size',
'weighed',
@ -510,14 +511,23 @@ class ProductsView(MasterView):
f.set_enum('unit_of_measure', self.enum.UNIT_OF_MEASURE)
f.set_label('unit_of_measure', "Unit of Measure")
# packs
if self.creating:
f.remove_field('packs')
elif self.viewing and product.packs:
f.set_renderer('packs', self.render_packs)
f.set_label('packs', "Pack Items")
else:
f.remove_field('packs')
# unit
if self.creating:
f.remove_field('unit')
elif self.viewing and not product.is_pack_item():
f.remove_field('unit')
else:
elif self.viewing and product.is_pack_item():
f.set_renderer('unit', self.render_unit)
f.set_label('unit', "Unit Item")
else:
f.remove_field('unit')
# pack_size
if self.viewing and not product.is_pack_item():
@ -619,12 +629,39 @@ class ProductsView(MasterView):
url = self.request.route_url('categories.view', uuid=category.uuid)
return tags.link_to(text, url)
def render_unit(self, product, field):
product = product.unit
if not product:
def render_packs(self, product, field):
if product.is_pack_item():
return ""
text = product.full_description
url = self.request.route_url('products.view', uuid=product.uuid)
links = []
for pack in product.packs:
if pack.upc:
code = pack.upc.pretty()
elif pack.scancode:
code = pack.scancode
else:
code = pack.item_id
text = "({}) {}".format(code, pack.full_description)
url = self.get_action_url('view', pack)
links.append(tags.link_to(text, url))
items = [HTML.tag('li', c=[link]) for link in links]
return HTML.tag('ul', c=items)
def render_unit(self, product, field):
unit = product.unit
if not unit:
return ""
if unit.upc:
code = unit.upc.pretty()
elif unit.scancode:
code = unit.scancode
else:
code = unit.item_id
text = "({}) {}".format(code, unit.full_description)
url = self.get_action_url('view', unit)
return tags.link_to(text, url)
def render_current_price_ends(self, product, field):