mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-24 08:46:39 +00:00
(cherry picked from commit 9e78e73a7c)
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
1 parent
f0c0b634ae
commit
04b2eb02a9
2 files changed
+20
No files matched your search
@@ -198,6 +198,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