diff --git a/store/backend.py b/store/backend.py index f048b2371765345e45d8c92761309b29e330f1ff..356e94061933bd4dde11abf2db1e4d7040b4886e 100644 --- a/store/backend.py +++ b/store/backend.py @@ -194,3 +194,20 @@ class PurchaseLogic: user.updateMoney(purchase.price) print("user_id:", user.id, "purchase_id:", purchase.id, "user.money:", user.money) + +class ChargeLogic: + + """ + Returns a list of the last charges of a specified user: [{'id': ..., 'amount': ...}, Decimal(...,...)] + @param user_id: the id of the specified user + @config-param max_charges: Number of charges to be shown. Depends on N_LAST_CHARGES + """ + def getLastChargesList(user_id): + max_charges = config['N_LAST_CHARGES'] + charges = Charge.objects.filter(user=user_id).values('id', 'amount') + if max_charges < 0: + charges = list(charges.order_by('time_stamp').reverse()) + else: + charges = list(charges.order_by('time_stamp').reverse())[:max_charges] + return charges + diff --git a/store/store_config.py b/store/store_config.py index a45ffa203f105cd00fda283adb226a4c11321c91..ac0b92cd70f81bd01a59d17cd1f78e5a65d30269 100644 --- a/store/store_config.py +++ b/store/store_config.py @@ -5,8 +5,10 @@ T_ANNULLABLE_PURCHASE_M: time of minutes a user has for a purchase to undo it N_MOST_BOUGHT_PRODUCTS: number of products to be shown in 'Häufig gekauft' T_MOST_BOUGHT_PRODUCTS_D: number of days in the past that are used as time intervall limit to search for 'Häufig gekauft' N_USERS_LOGIN: number of users that should be shown in the users list in the login-screen. A negative number means - 'all users are selected' + 'all users are selected' T_USERS_LOGIN_D: number of days in the past that are used as time intervall limit to search for users +N_LAST_CHARGES: number of charges that should be shown in 'Letzte Aufladungen'. A negative number means 'all users are + selected' """ KAFFEEKASSE = {'N_LAST_BOUGHT_PRODUCTS': 5, 'T_LAST_BOUGHT_PRODUCTS_D': 30, @@ -15,4 +17,5 @@ KAFFEEKASSE = {'N_LAST_BOUGHT_PRODUCTS': 5, 'T_MOST_BOUGHT_PRODUCTS_D': 30, 'N_USERS_LOGIN': -1, 'T_USERS_LOGIN_D': 356, + 'N_LAST_CHARGES': -1, }