Add admin bill generation endpoint

This commit is contained in:
fnux 2020-05-08 10:42:04 +02:00
parent d47c94ba84
commit cbba1f4169
2 changed files with 17 additions and 0 deletions

View file

@ -72,6 +72,7 @@ class OrderSerializer(serializers.ModelSerializer):
model = Order
fields = ['uuid', 'owner', 'description', 'creation_date', 'starting_date', 'ending_date',
'bill', 'recurring_period', 'recurring_price', 'one_time_price', 'replaced_by']
read_only_fields = ['replaced_by']
###

View file

@ -302,6 +302,22 @@ class AdminBillViewSet(BillViewSet):
serializer = self.get_serializer(unpaid_bills, many=True)
return Response(serializer.data)
@action(detail=False, methods=['post'])
def generate(self, request):
users = get_user_model().objects.all()
generated_bills = []
for user in users:
now = timezone.now()
generated_bills = generated_bills + Bill.generate_for(
year=now.year,
month=now.month,
user=user)
return Response(
map(lambda b: b.reference, generated_bills),
status=status.HTTP_200_OK)
class AdminOrderViewSet(mixins.ListModelMixin,
mixins.RetrieveModelMixin,
mixins.CreateModelMixin,