mirror of
https://github.com/inventree/InvenTree.git
synced 2025-09-18 08:31:33 +00:00
Specify order currency (#4698)
* Add 'order_currency' to the various external order models - By default will use the currency specified for the supplier (or customer) - Can be specified per order, also * Display order currency on order pgae * Add 'order_currency' field * Enable "blank" currency option (to default to the currency specified by the referenced company * Fix default currency code when adding line items * Remove 'total_price_currency' serializer field - Now replaced with 'order_currency' for greater flexibility * Bump api_version.py * Update default order report templates * Updated docs * More docs updaes * Adjust unit tests * Use 'order_currency' in order tables * Update purchase order api unit tests
This commit is contained in:
@@ -60,6 +60,50 @@ class PurchaseOrderTest(OrderTest):
|
||||
|
||||
LIST_URL = reverse('api-po-list')
|
||||
|
||||
def test_options(self):
|
||||
"""Test the PurchaseOrder OPTIONS endpoint."""
|
||||
|
||||
self.assignRole('purchase_order.add')
|
||||
|
||||
response = self.options(self.LIST_URL, expected_code=200)
|
||||
|
||||
data = response.data
|
||||
self.assertEqual(data['name'], 'Purchase Order List')
|
||||
|
||||
post = data['actions']['POST']
|
||||
|
||||
def check_options(data, field_name, spec):
|
||||
"""Helper function to check that the options are configured correctly."""
|
||||
field_data = data[field_name]
|
||||
|
||||
for k, v in spec.items():
|
||||
self.assertIn(k, field_data)
|
||||
self.assertEqual(field_data[k], v)
|
||||
|
||||
# Checks for the 'order_currency' field
|
||||
check_options(post, 'order_currency', {
|
||||
'type': 'choice',
|
||||
'required': False,
|
||||
'read_only': False,
|
||||
'label': 'Order Currency',
|
||||
'help_text': 'Currency for this order (leave blank to use company default)',
|
||||
})
|
||||
|
||||
# Checks for the 'reference' field
|
||||
check_options(post, 'reference', {
|
||||
'type': 'string',
|
||||
'required': True,
|
||||
'read_only': False,
|
||||
'label': 'Reference',
|
||||
})
|
||||
|
||||
# Checks for the 'supplier' field
|
||||
check_options(post, 'supplier', {
|
||||
'type': 'related field',
|
||||
'required': True,
|
||||
'api_url': '/api/company/',
|
||||
})
|
||||
|
||||
def test_po_list(self):
|
||||
"""Test the PurchaseOrder list API endpoint"""
|
||||
# List *ALL* PurchaseOrder items
|
||||
@@ -155,7 +199,7 @@ class PurchaseOrderTest(OrderTest):
|
||||
|
||||
for result in response.data['results']:
|
||||
self.assertIn('total_price', result)
|
||||
self.assertIn('total_price_currency', result)
|
||||
self.assertIn('order_currency', result)
|
||||
|
||||
def test_overdue(self):
|
||||
"""Test "overdue" status."""
|
||||
@@ -323,13 +367,18 @@ class PurchaseOrderTest(OrderTest):
|
||||
|
||||
self.assertTrue(po.lines.count() > 0)
|
||||
|
||||
lines = []
|
||||
|
||||
# Add some extra line items to this order
|
||||
for idx in range(5):
|
||||
models.PurchaseOrderExtraLine.objects.create(
|
||||
lines.append(models.PurchaseOrderExtraLine(
|
||||
order=po,
|
||||
quantity=idx + 10,
|
||||
reference='some reference',
|
||||
)
|
||||
))
|
||||
|
||||
# bulk create orders
|
||||
models.PurchaseOrderExtraLine.objects.bulk_create(lines)
|
||||
|
||||
data = self.get(reverse('api-po-detail', kwargs={'pk': 1})).data
|
||||
|
||||
@@ -1157,7 +1206,7 @@ class SalesOrderTest(OrderTest):
|
||||
|
||||
for result in response.data['results']:
|
||||
self.assertIn('total_price', result)
|
||||
self.assertIn('total_price_currency', result)
|
||||
self.assertIn('order_currency', result)
|
||||
|
||||
def test_overdue(self):
|
||||
"""Test "overdue" status."""
|
||||
|
Reference in New Issue
Block a user