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
This commit is contained in:
Lance Edgar 2020-02-24 13:38:58 -06:00
parent fc830f60e8
commit 2b70ed1407
3 changed files with 55 additions and 4 deletions

View file

@ -10,4 +10,6 @@
.. autoattribute:: default_handler_spec
.. automethod:: configure_row_form
.. automethod:: worksheet_update

View file

@ -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

View file

@ -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.