mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-18 06:04:44 +00:00
[bug] prevent changing of order creation_date via API (#13284)
This commit is contained in:
1 parent
19dfb81bfb
commit
9e78e73a7c
2 files changed
+20
No files matched your search
@@ -200,6 +200,16 @@ class AbstractOrderSerializer(
|
||||
|
||||
return value
|
||||
|
||||
def get_fields(self):
|
||||
"""Dynamically set creation_date as read-only on update operations."""
|
||||
fields = super().get_fields()
|
||||
|
||||
# Make creation_date read-only when updating an existing order
|
||||
if self.instance is not None and 'creation_date' in fields:
|
||||
fields['creation_date'].read_only = True
|
||||
|
||||
return fields
|
||||
|
||||
@staticmethod
|
||||
def annotate_queryset(queryset):
|
||||
"""Add extra information to the queryset."""
|
||||
|
||||
@@ -634,6 +634,16 @@ class PurchaseOrderTest(OrderTest):
|
||||
po = models.PurchaseOrder.objects.get(pk=response.data['pk'])
|
||||
self.assertEqual(po.creation_date, creation_date)
|
||||
|
||||
# Next, check that the creation_date is read-only on update
|
||||
po_pk = po.pk
|
||||
response = self.patch(
|
||||
reverse('api-po-detail', kwargs={'pk': po_pk}),
|
||||
{'creation_date': '2000-01-01'},
|
||||
expected_code=200,
|
||||
)
|
||||
po.refresh_from_db()
|
||||
self.assertEqual(po.creation_date, creation_date)
|
||||
|
||||
def test_po_duplicate(self):
|
||||
"""Test that we can duplicate a PurchaseOrder via the API."""
|
||||
self.assignRole('purchase_order.add')
|
||||
|
||||
Reference in new issue
Block a user