mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Allow orders' creation date edit via API (#6178)
* Add creation_date to the serializers of the Orders (to make it changeable by API) Fixes #6159 * Add API tests for the creation_date field * Fix missing , in test_api.py * Allow null to be passed (transleted to current date later) for creation_date of the Orders in the serializers too
This commit is contained in:
parent
c4a71a991a
commit
74d0eb729c
@ -211,7 +211,6 @@ class Order(
|
||||
Ensures that the reference field is rebuilt whenever the instance is saved.
|
||||
"""
|
||||
self.reference_int = self.rebuild_reference_field(self.reference)
|
||||
|
||||
if not self.creation_date:
|
||||
self.creation_date = datetime.now().date()
|
||||
|
||||
|
@ -97,6 +97,8 @@ class AbstractOrderSerializer(serializers.Serializer):
|
||||
|
||||
barcode_hash = serializers.CharField(read_only=True)
|
||||
|
||||
creation_date = serializers.DateField(required=False, allow_null=True)
|
||||
|
||||
def validate_reference(self, reference):
|
||||
"""Custom validation for the reference field."""
|
||||
self.Meta.model.validate_reference_field(reference)
|
||||
|
@ -357,6 +357,39 @@ class PurchaseOrderTest(OrderTest):
|
||||
expected_code=201,
|
||||
)
|
||||
|
||||
def test_po_creation_date(self):
|
||||
"""Test that we can create set the creation_date field of PurchaseOrder via the API."""
|
||||
self.assignRole('purchase_order.add')
|
||||
|
||||
response = self.post(
|
||||
reverse('api-po-list'),
|
||||
{
|
||||
'reference': 'PO-19881110',
|
||||
'supplier': 1,
|
||||
'description': 'PO created on 1988-11-10',
|
||||
'creation_date': '1988-11-10',
|
||||
},
|
||||
expected_code=201,
|
||||
)
|
||||
|
||||
po = models.PurchaseOrder.objects.get(pk=response.data['pk'])
|
||||
self.assertEqual(po.creation_date, datetime(1988, 11, 10).date())
|
||||
|
||||
"""Ensure if we do not pass the creation_date field than the current date will be saved"""
|
||||
creation_date = datetime.now().date()
|
||||
response = self.post(
|
||||
reverse('api-po-list'),
|
||||
{
|
||||
'reference': 'PO-11111111',
|
||||
'supplier': 1,
|
||||
'description': 'Check that the creation date is today',
|
||||
},
|
||||
expected_code=201,
|
||||
)
|
||||
|
||||
po = models.PurchaseOrder.objects.get(pk=response.data['pk'])
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user