API: Add invoice line position to invoice object

This commit is contained in:
Raphael Michel
2019-11-07 15:43:22 +01:00
parent 3f7f04ed21
commit 25cfa8973c
3 changed files with 28 additions and 1 deletions

View File

@@ -905,10 +905,25 @@ class OrderCreateSerializer(I18nAwareModelSerializer):
return order
class LinePositionField(serializers.IntegerField):
"""
Internally, the position field is stored starting at 0, but for the API, starting at 1 makes it
more consistent with other models
"""
def to_representation(self, value):
return super().to_representation(value) + 1
def to_internal_value(self, data):
return super().to_internal_value(data) - 1
class InlineInvoiceLineSerializer(I18nAwareModelSerializer):
position = LinePositionField(read_only=True)
class Meta:
model = InvoiceLine
fields = ('description', 'gross_value', 'tax_value', 'tax_rate', 'tax_name')
fields = ('position', 'description', 'gross_value', 'tax_value', 'tax_rate', 'tax_name')
class InvoiceSerializer(I18nAwareModelSerializer):

View File

@@ -838,6 +838,7 @@ TEST_INVOICE_RES = {
"foreign_currency_rate_date": None,
"lines": [
{
"position": 1,
"description": "Budget Ticket<br />Attendee: Peter",
"gross_value": "23.00",
"tax_value": "0.00",
@@ -845,6 +846,7 @@ TEST_INVOICE_RES = {
"tax_rate": "0.00"
},
{
"position": 2,
"description": "Payment fee",
"gross_value": "0.25",
"tax_value": "0.05",
@@ -3674,6 +3676,7 @@ def test_order_create_invoice(token_client, organizer, event, order):
'footer_text': '',
'lines': [
{
'position': 1,
'description': 'Budget Ticket<br />Attendee: Peter',
'gross_value': '23.00',
'tax_value': '0.00',
@@ -3681,6 +3684,7 @@ def test_order_create_invoice(token_client, organizer, event, order):
'tax_name': ''
},
{
'position': 2,
'description': 'Payment fee',
'gross_value': '0.25',
'tax_value': '0.05',