From 2b70ed14071ba6607e0c448abf6eeee7ca402915 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 24 Feb 2020 13:38:58 -0600 Subject: [PATCH] Fix "edit row" logic for ordering batch previous logic allowed `colander.null` to be passed to batch handler, which caused an error. also it allowed editing "all" fields for the row, which we really don't need to do, so now we just support the order quantities --- docs/api/views/purchasing.ordering.rst | 2 ++ tailbone/views/purchasing/batch.py | 16 ++++++++-- tailbone/views/purchasing/ordering.py | 41 +++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/docs/api/views/purchasing.ordering.rst b/docs/api/views/purchasing.ordering.rst index 7dffd964..38d46b07 100644 --- a/docs/api/views/purchasing.ordering.rst +++ b/docs/api/views/purchasing.ordering.rst @@ -10,4 +10,6 @@ .. autoattribute:: default_handler_spec + .. automethod:: configure_row_form + .. automethod:: worksheet_update diff --git a/tailbone/views/purchasing/batch.py b/tailbone/views/purchasing/batch.py index d92ee03b..8b557188 100644 --- a/tailbone/views/purchasing/batch.py +++ b/tailbone/views/purchasing/batch.py @@ -922,9 +922,19 @@ class PurchasingBatchView(BatchMasterView): if batch.mode == self.enum.PURCHASE_BATCH_MODE_ORDERING: - # let handler update data, per given order quantities - data = self.form_deserialized - self.handler.update_row_quantity(row, **data) + # figure out which values need updating + form_data = self.form_deserialized + data = {} + for key in ('cases_ordered', 'units_ordered'): + if key in form_data: + # this is really to convert/avoid colander.null, but the + # handler method also assumes that if we pass a value, it + # will not be None + data[key] = form_data[key] or 0 + if data: + + # let handler do the actual updating + self.handler.update_row_quantity(row, **data) else: # *not* ordering mode diff --git a/tailbone/views/purchasing/ordering.py b/tailbone/views/purchasing/ordering.py index 68ec9f9d..15ce6f5b 100644 --- a/tailbone/views/purchasing/ordering.py +++ b/tailbone/views/purchasing/ordering.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2019 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -121,6 +121,23 @@ class OrderingBatchView(PurchasingBatchView): 'status_code', ] + row_form_fields = [ + 'item_entry', + 'item_id', + 'upc', + 'product', + 'brand_name', + 'description', + 'size', + 'case_quantity', + 'cases_ordered', + 'units_ordered', + 'po_line_number', + 'po_unit_cost', + 'po_total_calculated', + 'status_code', + ] + order_form_header_columns = [ "UPC", "Brand", @@ -147,6 +164,28 @@ class OrderingBatchView(PurchasingBatchView): kwargs['notes_to_vendor'] = batch.notes_to_vendor return kwargs + def configure_row_form(self, f): + """ + Supplements the default logic as follows: + + When editing, only these fields allow changes; all others are made + read-only: + + * ``cases_ordered`` + * ``units_ordered`` + """ + super(OrderingBatchView, self).configure_row_form(f) + + # when editing, only certain fields should allow changes + if self.editing: + editable_fields = [ + 'cases_ordered', + 'units_ordered', + ] + for field in f.fields: + if field not in editable_fields: + f.set_readonly(field) + def worksheet(self): """ View for editing batch row data as an order form worksheet.