Prevent updates to batch rows, if batch is immutable

probably need a lot more support for this elsewhere; this is all i needed for
the moment though..
This commit is contained in:
Lance Edgar 2021-02-02 18:58:46 -06:00
parent f93fd7aefa
commit 63350469d0
3 changed files with 16 additions and 4 deletions

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar # Copyright © 2010-2021 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -117,6 +117,7 @@ class APIBatchView(APIBatchMixin, APIMasterView):
'executed_display': self.pretty_datetime(executed) if executed else None, 'executed_display': self.pretty_datetime(executed) if executed else None,
'executed_by_uuid': batch.executed_by_uuid, 'executed_by_uuid': batch.executed_by_uuid,
'executed_by_display': six.text_type(batch.executed_by or ''), 'executed_by_display': six.text_type(batch.executed_by or ''),
'mutable': self.handler.is_mutable(batch),
} }
def create_object(self, data): def create_object(self, data):
@ -268,6 +269,7 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
'batch_description': batch.description, 'batch_description': batch.description,
'batch_complete': batch.complete, 'batch_complete': batch.complete,
'batch_executed': bool(batch.executed), 'batch_executed': bool(batch.executed),
'batch_mutable': self.handler.is_mutable(batch),
'sequence': row.sequence, 'sequence': row.sequence,
'status_code': row.status_code, 'status_code': row.status_code,
'status_display': row.STATUS.get(row.status_code, six.text_type(row.status_code)), 'status_display': row.STATUS.get(row.status_code, six.text_type(row.status_code)),
@ -280,6 +282,9 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
Invokes the batch handler's ``refresh_row()`` method after updating the Invokes the batch handler's ``refresh_row()`` method after updating the
row's field data per usual. row's field data per usual.
""" """
if not self.handler.is_mutable(row.batch):
return {'error': "Batch is not mutable"}
# update row per usual # update row per usual
row = super(APIBatchRowView, self).update_object(row, data) row = super(APIBatchRowView, self).update_object(row, data)

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar # Copyright © 2010-2021 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -267,6 +267,9 @@ class OrderingBatchRowViews(APIBatchRowView):
Note that the "normal" logic for this method is not invoked at all. Note that the "normal" logic for this method is not invoked at all.
""" """
if not self.handler.is_mutable(row.batch):
return {'error': "Batch is not mutable"}
self.handler.update_row_quantity(row, **data) self.handler.update_row_quantity(row, **data)
return row return row

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar # Copyright © 2010-2021 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -345,8 +345,12 @@ class APIMasterView(APIView):
# assume our data comes only from request JSON body # assume our data comes only from request JSON body
data = self.request.json_body data = self.request.json_body
# update and return data for object # try to update data for object, returning error as necessary
obj = self.update_object(obj, data) obj = self.update_object(obj, data)
if isinstance(obj, dict) and 'error' in obj:
return {'error': obj['error']}
# return data for object
self.Session.flush() self.Session.flush()
return self._get(obj) return self._get(obj)