Improve basic support for unit/pack info when viewing product details
This commit is contained in:
parent
9149902c78
commit
3dfdb26502
|
@ -728,6 +728,8 @@ class Form(object):
|
|||
return True
|
||||
|
||||
def render_field_readonly(self, field_name, **kwargs):
|
||||
if field_name not in self.fields:
|
||||
return ''
|
||||
label = HTML.tag('label', self.get_label(field_name), for_=field_name)
|
||||
field = self.render_field_value(field_name) or ''
|
||||
field_div = HTML.tag('div', class_='field', c=[field])
|
||||
|
|
|
@ -68,12 +68,14 @@
|
|||
${form.render_field_readonly('size')}
|
||||
${form.render_field_readonly('unit_size')}
|
||||
${form.render_field_readonly('unit_of_measure')}
|
||||
% if instance.is_pack_item():
|
||||
${form.render_field_readonly('unit')}
|
||||
${form.render_field_readonly('pack_size')}
|
||||
${form.render_field_readonly('default_pack')}
|
||||
% endif
|
||||
${form.render_field_readonly('case_size')}
|
||||
% if instance.is_pack_item():
|
||||
${form.render_field_readonly('pack_size')}
|
||||
${form.render_field_readonly('unit')}
|
||||
${form.render_field_readonly('default_pack')}
|
||||
% elif instance.packs:
|
||||
${form.render_field_readonly('packs')}
|
||||
% endif
|
||||
${self.extra_main_fields(form)}
|
||||
</%def>
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue