#31 API Deductions

* adds GET/POST/PUT/DELETE support for EcoAccountDeductions
This commit is contained in:
2022-01-28 15:44:09 +01:00
parent 5dc1b11ca1
commit c3a8631f03
4 changed files with 198 additions and 15 deletions

View File

@@ -132,6 +132,30 @@ class DeductableAPISerializerV1Mixin:
class Meta:
abstract = True
def _single_deduction_to_json(self, entry):
""" Serializes a single eco account deduction into json
Args:
entry (EcoAccountDeduction): An EcoAccountDeduction
Returns:
serialized_json (dict)
"""
return {
"id": entry.pk,
"eco_account": {
"id": entry.account.pk,
"identifier": entry.account.identifier,
"title": entry.account.title,
},
"surface": entry.surface,
"intervention": {
"id": entry.intervention.pk,
"identifier": entry.intervention.identifier,
"title": entry.intervention.title,
}
}
def _deductions_to_json(self, qs: QuerySet):
""" Serializes eco account deductions into json
@@ -142,20 +166,7 @@ class DeductableAPISerializerV1Mixin:
serialized_json (list)
"""
return [
{
"id": entry.pk,
"eco_account": {
"id": entry.account.pk,
"identifier": entry.account.identifier,
"title": entry.account.title,
},
"surface": entry.surface,
"intervention": {
"id": entry.intervention.pk,
"identifier": entry.intervention.identifier,
"title": entry.intervention.title,
}
}
self._single_deduction_to_json(entry)
for entry in qs
]