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:
parent
f93fd7aefa
commit
63350469d0
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
# Copyright © 2010-2021 Lance Edgar
|
||||
#
|
||||
# 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_by_uuid': batch.executed_by_uuid,
|
||||
'executed_by_display': six.text_type(batch.executed_by or ''),
|
||||
'mutable': self.handler.is_mutable(batch),
|
||||
}
|
||||
|
||||
def create_object(self, data):
|
||||
|
@ -268,6 +269,7 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
|
|||
'batch_description': batch.description,
|
||||
'batch_complete': batch.complete,
|
||||
'batch_executed': bool(batch.executed),
|
||||
'batch_mutable': self.handler.is_mutable(batch),
|
||||
'sequence': row.sequence,
|
||||
'status_code': 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
|
||||
row's field data per usual.
|
||||
"""
|
||||
if not self.handler.is_mutable(row.batch):
|
||||
return {'error': "Batch is not mutable"}
|
||||
|
||||
# update row per usual
|
||||
row = super(APIBatchRowView, self).update_object(row, data)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
# Copyright © 2010-2021 Lance Edgar
|
||||
#
|
||||
# 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.
|
||||
"""
|
||||
if not self.handler.is_mutable(row.batch):
|
||||
return {'error': "Batch is not mutable"}
|
||||
|
||||
self.handler.update_row_quantity(row, **data)
|
||||
return row
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
# Copyright © 2010-2021 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -345,8 +345,12 @@ class APIMasterView(APIView):
|
|||
# assume our data comes only from 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)
|
||||
if isinstance(obj, dict) and 'error' in obj:
|
||||
return {'error': obj['error']}
|
||||
|
||||
# return data for object
|
||||
self.Session.flush()
|
||||
return self._get(obj)
|
||||
|
||||
|
|
Loading…
Reference in a new issue