From 3760c3239f7f45ad7879f8fe497770bfdf2b2369 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 7 Mar 2019 12:21:50 -0600 Subject: [PATCH] Improve display of purchase credit data esp. within a receiving batch row --- tailbone/views/purchases/credits.py | 49 +++++++++++++++++++++++++++-- tailbone/views/purchasing/batch.py | 34 +++++++++++++++++--- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/tailbone/views/purchases/credits.py b/tailbone/views/purchases/credits.py index d812fbe7..dafe5d5e 100644 --- a/tailbone/views/purchases/credits.py +++ b/tailbone/views/purchases/credits.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2019 Lance Edgar # # This file is part of Rattail. # @@ -47,6 +47,11 @@ class PurchaseCreditView(MasterView): editable = False checkboxes = True + labels = { + 'upc': "UPC", + 'mispick_upc': "Mispick UPC", + } + grid_columns = [ 'vendor', 'invoice_number', @@ -65,6 +70,35 @@ class PurchaseCreditView(MasterView): 'status', ] + form_fields = [ + 'store', + 'vendor', + 'invoice_number', + 'invoice_date', + 'date_ordered', + 'date_shipped', + 'date_received', + 'department_number', + 'department_name', + 'vendor_item_code', + 'upc', + 'product', + 'case_quantity', + 'credit_type', + 'cases_shorted', + 'units_shorted', + 'invoice_line_number', + 'invoice_case_cost', + 'invoice_unit_cost', + 'invoice_total', + 'credit_total', + 'mispick_upc', + 'mispick_product', + 'product_discarded', + 'expiration_date', + 'status', + ] + def configure_grid(self, g): super(PurchaseCreditView, self).configure_grid(g) @@ -86,15 +120,24 @@ class PurchaseCreditView(MasterView): g.set_type('credit_total', 'currency') g.set_label('invoice_number', "Invoice No.") - g.set_label('upc', "UPC") g.set_label('vendor_item_code', "Item Code") g.set_label('brand_name', "Brand") g.set_label('cases_shorted', "Cases") g.set_label('units_shorted', "Units") g.set_label('credit_type', "Type") - g.set_label('mispick_upc', "Mispick UPC") g.set_label('date_received', "Date") + g.set_link('upc') + g.set_link('vendor_item_code') + g.set_link('brand_name') + g.set_link('description') + + def configure_form(self, f): + super(PurchaseCreditView, self).configure_form(f) + + # status + f.set_enum('status', self.enum.PURCHASE_CREDIT_STATUS) + def change_status(self): if self.request.method != 'POST': self.request.session.flash("Sorry, you must POST to change credit status", 'error') diff --git a/tailbone/views/purchasing/batch.py b/tailbone/views/purchasing/batch.py index 92c787b8..50484583 100644 --- a/tailbone/views/purchasing/batch.py +++ b/tailbone/views/purchasing/batch.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2019 Lance Edgar # # This file is part of Rattail. # @@ -34,9 +34,9 @@ from rattail.time import localtime import colander from deform import widget as dfwidget from pyramid import httpexceptions -from webhelpers2.html import tags +from webhelpers2.html import tags, HTML -from tailbone import forms +from tailbone import forms, grids from tailbone.views.batch import BatchMasterView @@ -646,7 +646,6 @@ class PurchasingBatchView(BatchMasterView): # readonly fields f.set_readonly('case_quantity') - f.set_readonly('credits') # quantity fields f.set_type('case_quantity', 'quantity') @@ -670,6 +669,10 @@ class PurchasingBatchView(BatchMasterView): # upc f.set_type('upc', 'gpc') + # credits + f.set_readonly('credits') + f.set_renderer('credits', self.render_row_credits) + if self.creating: f.remove_fields( 'upc', @@ -704,6 +707,29 @@ class PurchasingBatchView(BatchMasterView): else: f.remove_field('product') + def render_row_credits(self, row, field): + if not row.credits: + return "" + + route_prefix = self.get_route_prefix() + columns = [ + 'credit_type', + 'cases_shorted', + 'units_shorted', + 'credit_total', + ] + g = grids.Grid( + key='{}.row_credits'.format(route_prefix), + data=row.credits, + columns=columns, + labels={'credit_type': "Type", + 'cases_shorted': "Cases", + 'units_shorted': "Units"}) + g.set_type('cases_shorted', 'quantity') + g.set_type('units_shorted', 'quantity') + g.set_type('credit_total', 'currency') + return HTML.literal(g.render_grid()) + def configure_mobile_row_form(self, f): super(PurchasingBatchView, self).configure_mobile_row_form(f) # row = f.model_instance