Improve grids for custorder items

main grid as well as rows grid for Pending Product
This commit is contained in:
Lance Edgar 2023-09-11 15:24:00 -05:00
parent 67ec6f7773
commit e793ba6630
3 changed files with 103 additions and 58 deletions

View file

@ -3,27 +3,6 @@
<%def name="object_helpers()"> <%def name="object_helpers()">
${parent.object_helpers()} ${parent.object_helpers()}
% if instance.custorder_item_records:
<nav class="panel">
<p class="panel-heading">Cross-Reference</p>
<div class="panel-block">
<div style="display: flex; flex-direction: column;">
<p class="block">
This ${model_title} is referenced by the following<br />
Customer Order Items:
</p>
<ul class="list">
% for item in instance.custorder_item_records:
<li class="list-item">
${h.link_to('#{}-{}'.format(item.order.id, item.sequence), url('custorders.items.view', uuid=item.uuid))}
</li>
% endfor
</ul>
</div>
</div>
</nav>
% endif
% if instance.status_code == enum.PENDING_PRODUCT_STATUS_PENDING and master.has_perm('resolve_product'): % if instance.status_code == enum.PENDING_PRODUCT_STATUS_PENDING and master.has_perm('resolve_product'):
<nav class="panel"> <nav class="panel">
<p class="panel-heading">Tools</p> <p class="panel-heading">Tools</p>

View file

@ -58,14 +58,18 @@ class CustomerOrderItemView(MasterView):
grid_columns = [ grid_columns = [
'order_id', 'order_id',
'person', 'person',
'_product_key_',
'product_brand', 'product_brand',
'product_description', 'product_description',
'product_size', 'product_size',
'department_name',
'case_quantity',
'order_quantity', 'order_quantity',
'order_uom', 'order_uom',
'case_quantity', 'total_price',
'order_created', 'order_created',
'status_code', 'status_code',
'flagged',
] ]
has_rows = True has_rows = True
@ -114,42 +118,55 @@ class CustomerOrderItemView(MasterView):
.joinedload(model.CustomerOrder.person)) .joinedload(model.CustomerOrder.person))
def configure_grid(self, g): def configure_grid(self, g):
super(CustomerOrderItemView, self).configure_grid(g) super().configure_grid(g)
batch_handler = self.get_batch_handler()
# order_id
g.set_renderer('order_id', self.render_order_id) g.set_renderer('order_id', self.render_order_id)
g.set_link('order_id')
g.set_joiner('person', lambda q: q.outerjoin(model.Person)) # person
g.filters['person'] = g.make_filter('person', model.Person.display_name,
default_active=True, default_verb='contains')
g.set_sorter('person', model.Person.display_name)
g.set_sorter('order_created', model.CustomerOrder.created)
g.set_sort_defaults('order_created', 'desc')
g.set_type('case_quantity', 'quantity')
g.set_type('cases_ordered', 'quantity')
g.set_type('units_ordered', 'quantity')
g.set_type('total_price', 'currency')
g.set_type('order_quantity', 'quantity')
g.set_enum('order_uom', self.enum.UNIT_OF_MEASURE)
g.set_renderer('person', self.render_person_text)
g.set_renderer('order_created', self.render_order_created)
g.set_renderer('status_code', self.render_status_code_column)
g.set_label('person', "Person Name") g.set_label('person', "Person Name")
g.set_renderer('person', self.render_person_text)
g.set_link('person')
g.set_joiner('person', lambda q: q.outerjoin(model.Person))
g.set_sorter('person', model.Person.display_name)
g.set_filter('person', model.Person.display_name,
default_active=True, default_verb='contains')
# product_key
field = self.get_product_key_field()
g.set_renderer(field, lambda item, field: getattr(item, f'product_{field}'))
# product_*
g.set_label('product_brand', "Brand") g.set_label('product_brand', "Brand")
g.set_link('product_brand')
g.set_label('product_description', "Description") g.set_label('product_description', "Description")
g.set_link('product_description')
g.set_label('product_size', "Size") g.set_label('product_size', "Size")
g.set_link('order_id') # "numbers"
g.set_link('person') g.set_type('case_quantity', 'quantity')
g.set_link('product_brand') g.set_type('order_quantity', 'quantity')
g.set_link('product_description') g.set_type('total_price', 'currency')
# TODO: deprecate / remove these
g.set_type('cases_ordered', 'quantity')
g.set_type('units_ordered', 'quantity')
# order_uom
# nb. this is not relevant if "case orders only"
if not batch_handler.allow_unit_orders():
g.remove('order_uom')
else:
g.set_enum('order_uom', self.enum.UNIT_OF_MEASURE)
# order_created
g.set_renderer('order_created', self.render_order_created)
g.set_sorter('order_created', model.CustomerOrder.created)
g.set_sort_defaults('order_created', 'desc')
# status_code
g.set_renderer('status_code', self.render_status_code_column)
def render_order_id(self, item, field): def render_order_id(self, item, field):
return item.order.id return item.order.id

View file

@ -2257,15 +2257,28 @@ class PendingProductView(MasterView):
# TODO: add support for this someday # TODO: add support for this someday
rows_viewable = False rows_viewable = False
# TODO: this clearly needs help row_labels = {
'order_id': "Order ID",
'product_brand': "Brand",
'product_description': "Description",
'product_size': "Size",
'order_created': "Ordered",
'status_code': "Status",
}
row_grid_columns = [ row_grid_columns = [
# 'upc', 'order_id',
'brand_name', 'customer',
'description', 'person',
'size', '_product_key_',
'vendor_name', 'product_brand',
# 'regular_price', 'product_description',
# 'current_price', 'product_size',
'order_quantity',
'total_price',
'order_created',
'status_code',
'flagged',
] ]
def configure_grid(self, g): def configure_grid(self, g):
@ -2468,6 +2481,42 @@ class PendingProductView(MasterView):
def get_parent(self, item): def get_parent(self, item):
return item.pending_product return item.pending_product
def configure_row_grid(self, g):
super().configure_row_grid(g)
app = self.get_rattail_app()
# order_id
g.set_renderer('order_id', lambda item, field: item.order.id)
# contact
handler = app.get_batch_handler('custorder')
if handler.new_order_requires_customer():
g.remove('person')
g.set_renderer('customer', lambda item, field: item.order.customer)
else:
g.remove('customer')
g.set_renderer('person', lambda item, field: item.order.person)
# product_key
field = self.get_product_key_field()
if not self.rows_viewable:
g.set_link(field, False)
g.set_renderer(field, lambda item, field: getattr(item, f'product_{field}'))
# "numbers"
g.set_type('order_quantity', 'quantity')
g.set_type('total_price', 'currency')
# order_created
g.set_renderer('order_created',
lambda item, field: raw_datetime(self.rattail_config,
app.localtime(item.order.created,
from_utc=True),
as_date=True))
# status_code
g.set_enum('status_code', self.enum.CUSTORDER_ITEM_STATUS)
@classmethod @classmethod
def defaults(cls, config): def defaults(cls, config):
cls._defaults(config) cls._defaults(config)