From 658262c5993b2e3c18a9910920b09029cf2e948c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= <timothee.floure@posteo.net>
Date: Fri, 6 Mar 2020 09:39:41 +0100
Subject: [PATCH] Add human readable reference to bills

---
 uncloud/uncloud_pay/models.py      | 6 ++++++
 uncloud/uncloud_pay/serializers.py | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/uncloud/uncloud_pay/models.py b/uncloud/uncloud_pay/models.py
index 43064e4..32d3eac 100644
--- a/uncloud/uncloud_pay/models.py
+++ b/uncloud/uncloud_pay/models.py
@@ -180,6 +180,12 @@ class Bill(models.Model):
 
     valid = models.BooleanField(default=True)
 
+    @property
+    def reference(self):
+        return "{}_{}".format(
+                self.owner.username,
+                self.creation_date.strftime("%Y-%m-%d-%H%M"))
+
     @property
     def records(self):
         bill_records = []
diff --git a/uncloud/uncloud_pay/serializers.py b/uncloud/uncloud_pay/serializers.py
index d763590..60ddc75 100644
--- a/uncloud/uncloud_pay/serializers.py
+++ b/uncloud/uncloud_pay/serializers.py
@@ -83,5 +83,5 @@ class BillSerializer(serializers.ModelSerializer):
     records = BillRecordSerializer(many=True, read_only=True)
     class Meta:
         model = Bill
-        fields = ['owner', 'total', 'due_date', 'creation_date',
+        fields = ['reference', 'owner', 'total', 'due_date', 'creation_date',
                 'starting_date', 'ending_date', 'records', 'final']