Add admin bill generation endpoint
This commit is contained in:
parent
d47c94ba84
commit
cbba1f4169
2 changed files with 17 additions and 0 deletions
|
@ -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']
|
||||
|
||||
|
||||
###
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue