Add common logic to determine panel fields for product view

so we don't have to override templates, but just the view logic

more needed, but this proves the concept
This commit is contained in:
Lance Edgar 2022-12-08 22:00:57 -06:00
parent 273fa7eb55
commit 05a3e3f805
2 changed files with 53 additions and 22 deletions

View file

@ -93,21 +93,9 @@
</%def> </%def>
<%def name="render_main_fields(form)"> <%def name="render_main_fields(form)">
${form.render_field_readonly(product_key_field)} % for field in panel_fields['main']:
${form.render_field_readonly('brand')} ${form.render_field_readonly(field)}
${form.render_field_readonly('description')} % endfor
${form.render_field_readonly('size')}
${form.render_field_readonly('unit_size')}
${form.render_field_readonly('unit_of_measure')}
${form.render_field_readonly('average_weight')}
${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)} ${self.extra_main_fields(form)}
</%def> </%def>
@ -201,13 +189,9 @@
</%def> </%def>
<%def name="render_flag_fields(form)"> <%def name="render_flag_fields(form)">
${form.render_field_readonly('weighed')} % for field in panel_fields['flag']:
${form.render_field_readonly('discountable')} ${form.render_field_readonly(field)}
${form.render_field_readonly('special_order')} % endfor
${form.render_field_readonly('organic')}
${form.render_field_readonly('not_for_sale')}
${form.render_field_readonly('discontinued')}
${form.render_field_readonly('deleted')}
</%def> </%def>
<%def name="movement_panel()"> <%def name="movement_panel()">

View file

@ -1269,8 +1269,55 @@ class ProductView(MasterView):
kwargs['vendor_sources'] = self.get_context_vendor_sources(product) kwargs['vendor_sources'] = self.get_context_vendor_sources(product)
kwargs['lookup_codes'] = self.get_context_lookup_codes(product) kwargs['lookup_codes'] = self.get_context_lookup_codes(product)
kwargs['panel_fields'] = self.get_panel_fields(product)
return kwargs return kwargs
def get_panel_fields(self, product):
return {
'main': self.get_panel_fields_main(product),
'flag': self.get_panel_fields_flag(product),
}
def get_panel_fields_main(self, product):
key = self.rattail_config.product_key()
product_key_field = self.product_key_fields.get(key, key)
fields = [
product_key_field,
'brand',
'description',
'size',
'unit_size',
'unit_of_measure',
'average_weight',
'case_size',
]
if product.is_pack_item():
fields.extend([
'pack_size',
'unit',
'default_pack',
])
elif product.packs:
fields.append('packs')
for supp in self.iter_view_supplements():
if hasattr(supp, 'get_panel_fields_main'):
fields.extend(supp.get_panel_fields_main(product))
return fields
def get_panel_fields_flag(self, product):
return [
'weighed',
'discountable',
'special_order',
'organic',
'not_for_sale',
'discontinued',
'deleted',
]
def get_context_vendor_sources(self, product): def get_context_vendor_sources(self, product):
app = self.get_rattail_app() app = self.get_rattail_app()
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()