dynamically generate drinks table and add it to the finance context
This commit is contained in:
84
gaehsnitz/utils.py
Normal file
84
gaehsnitz/utils.py
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
from typing import List, Union
|
||||||
|
|
||||||
|
_crates = "crates"
|
||||||
|
_bottles_per_crate = "bottles_per_crate"
|
||||||
|
_bottle_size = "bottle_size"
|
||||||
|
_price_per_crate = "price_per_crate"
|
||||||
|
_deposit_per_crate = "deposit_per_crate"
|
||||||
|
|
||||||
|
drinks = {
|
||||||
|
"Sterni": {
|
||||||
|
_crates: 25, _bottles_per_crate: 20, _bottle_size: 0.5,
|
||||||
|
_price_per_crate: 8.90, _deposit_per_crate: 3.10,
|
||||||
|
},
|
||||||
|
"Uri": {
|
||||||
|
_crates: 15, _bottles_per_crate: 20, _bottle_size: 0.5,
|
||||||
|
_price_per_crate: 13.50, _deposit_per_crate: 3.10,
|
||||||
|
},
|
||||||
|
"Wasser": {
|
||||||
|
_crates: 12, _bottles_per_crate: 12, _bottle_size: 0.7,
|
||||||
|
_price_per_crate: 4.50, _deposit_per_crate: 3.30,
|
||||||
|
},
|
||||||
|
"Radler": {
|
||||||
|
_crates: 8, _bottles_per_crate: 20, _bottle_size: 0.5,
|
||||||
|
_price_per_crate: 13.00, _deposit_per_crate: 3.10,
|
||||||
|
},
|
||||||
|
"Mate": {
|
||||||
|
_crates: 5, _bottles_per_crate: 20, _bottle_size: 0.5,
|
||||||
|
_price_per_crate: 17.00, _deposit_per_crate: 4.50,
|
||||||
|
},
|
||||||
|
"Vita-Cola": {
|
||||||
|
_crates: 2, _bottles_per_crate: 12, _bottle_size: 1,
|
||||||
|
_price_per_crate: 10.00, _deposit_per_crate: 3.30,
|
||||||
|
},
|
||||||
|
"Pepsi": {
|
||||||
|
_crates: 2, _bottles_per_crate: 12, _bottle_size: 1,
|
||||||
|
_price_per_crate: 12.00, _deposit_per_crate: 3.30,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def generate_drinks_table() -> List[List[Union[str, int, float]]]:
|
||||||
|
table_data = [
|
||||||
|
[
|
||||||
|
"Getränk", "Kästen",
|
||||||
|
"Fl. / K.", "Fl. ges.",
|
||||||
|
"Menge / Fl.", "Menge / K.", "Menge ges.",
|
||||||
|
"Preis / Fl.", "Preis / K.", "Preis ges.",
|
||||||
|
"Pfand / K.", "Pfand ges.",
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
total_crates = total_bottles = total_amount = total_price = total_deposit = 0
|
||||||
|
|
||||||
|
for name, details in drinks.items():
|
||||||
|
bottles = details[_crates] * details[_bottles_per_crate]
|
||||||
|
amount_per_crate = details[_bottle_size] * details[_bottles_per_crate]
|
||||||
|
amount = amount_per_crate * details[_crates]
|
||||||
|
price_per_bottle = details[_price_per_crate] / details[_bottles_per_crate]
|
||||||
|
price = details[_price_per_crate] * details[_crates]
|
||||||
|
deposit = details[_deposit_per_crate] * details[_crates]
|
||||||
|
|
||||||
|
table_data.append([
|
||||||
|
name, str(details[_crates]),
|
||||||
|
str(details[_bottles_per_crate]), str(bottles),
|
||||||
|
f"{details[_bottle_size]:.1f}l", f"{amount_per_crate:.1f}l", f"{amount:.1f}l",
|
||||||
|
f"{price_per_bottle:.2f}€", f"{details[_price_per_crate]:.2f}€", f"{price:.2f}€",
|
||||||
|
f"{details[_deposit_per_crate]:.2f}€", f"{deposit:.2f}€",
|
||||||
|
])
|
||||||
|
|
||||||
|
total_crates += details[_crates]
|
||||||
|
total_bottles += bottles
|
||||||
|
total_amount += amount
|
||||||
|
total_price += price
|
||||||
|
total_deposit += deposit
|
||||||
|
|
||||||
|
table_data.append([
|
||||||
|
"Summe", str(total_crates),
|
||||||
|
"", str(total_bottles),
|
||||||
|
"", "", f"{total_amount:.1f}l",
|
||||||
|
"", "", f"{total_price:.2f}€",
|
||||||
|
"", f"{total_deposit:.2f}€",
|
||||||
|
])
|
||||||
|
|
||||||
|
return table_data
|
||||||
@@ -5,6 +5,7 @@ from django.utils import timezone
|
|||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
from gaehsnitz.models import Payment
|
from gaehsnitz.models import Payment
|
||||||
|
from gaehsnitz.utils import generate_drinks_table
|
||||||
|
|
||||||
festival_start_date, festival_end_date = date(2022, 8, 25), date(2022, 8, 28)
|
festival_start_date, festival_end_date = date(2022, 8, 25), date(2022, 8, 28)
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ class FinanceView(GaehsnitzTemplateView):
|
|||||||
"balance_dict": dict(balance_dict),
|
"balance_dict": dict(balance_dict),
|
||||||
"overall_sum": overall_sum,
|
"overall_sum": overall_sum,
|
||||||
"detailed_payments": dict(detailed_payments),
|
"detailed_payments": dict(detailed_payments),
|
||||||
|
"drinks_table": generate_drinks_table(),
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user