2014-07-23 16:24:56 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
2014-10-17 10:04:47 +00:00
|
|
|
from orchestra.api import router
|
2015-04-05 10:46:24 +00:00
|
|
|
from orchestra.contrib.accounts.models import Account
|
|
|
|
from orchestra.contrib.accounts.serializers import AccountSerializerMixin
|
2014-07-28 17:28:00 +00:00
|
|
|
|
2014-10-17 10:04:47 +00:00
|
|
|
from .models import Bill, BillLine, BillContact
|
2014-07-23 16:24:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BillLineSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = BillLine
|
|
|
|
|
|
|
|
|
2014-07-28 17:28:00 +00:00
|
|
|
|
|
|
|
class BillSerializer(AccountSerializerMixin, serializers.HyperlinkedModelSerializer):
|
2015-02-24 09:34:26 +00:00
|
|
|
# lines = BillLineSerializer(source='lines')
|
2014-07-23 16:24:56 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Bill
|
2014-07-28 17:28:00 +00:00
|
|
|
fields = (
|
2014-09-30 16:39:47 +00:00
|
|
|
'url', 'number', 'type', 'total', 'is_sent', 'created_on', 'due_on',
|
2015-02-24 09:34:26 +00:00
|
|
|
'comments',
|
|
|
|
# 'lines'
|
2014-07-28 17:28:00 +00:00
|
|
|
)
|
2014-10-17 10:04:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BillContactSerializer(AccountSerializerMixin, serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = BillContact
|
|
|
|
fields = ('name', 'address', 'city', 'zipcode', 'country', 'vat')
|
|
|
|
|
|
|
|
|
|
|
|
router.insert(Account, 'billcontact', BillContactSerializer, required=False)
|