From 1dd254a3a7d61bed29232afbc650aedf25140146 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 20 Mar 2023 14:44:57 +0000 Subject: [PATCH] Validate payees --- core/views/linkgroups.py | 58 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/core/views/linkgroups.py b/core/views/linkgroups.py index 79dd792..fffdd5a 100644 --- a/core/views/linkgroups.py +++ b/core/views/linkgroups.py @@ -62,36 +62,38 @@ class LinkGroupInfo(LoginRequiredMixin, OTPRequiredMixin, ObjectRead): pay_list = {} platform_pay_list = [] - for payee in payees["platform"]: - cast = { - "name": payee.name, - "address": payee.address, - "amount": profit_platform / len(payees["platform"]), - "max": profit_platform, - } - if payee not in pay_list: - pay_list[payee] = {} - if "amount" in pay_list[payee]: - pay_list[payee]["amount"] += cast["amount"] - else: - pay_list[payee] = dict(cast) - platform_pay_list.append(cast) + if "platform" in payees: + for payee in payees["platform"]: + cast = { + "name": payee.name, + "address": payee.address, + "amount": profit_platform / len(payees["platform"]), + "max": profit_platform, + } + if payee not in pay_list: + pay_list[payee] = {} + if "amount" in pay_list[payee]: + pay_list[payee]["amount"] += cast["amount"] + else: + pay_list[payee] = dict(cast) + platform_pay_list.append(cast) requisition_pay_list = [] - for payee in payees["requisition"]: - cast = { - "name": payee.name, - "address": payee.address, - "amount": profit_requisition / len(payees["requisition"]), - "max": profit_requisition, - } - if payee not in pay_list: - pay_list[payee] = {} - if "amount" in pay_list[payee]: - pay_list[payee]["amount"] += cast["amount"] - else: - pay_list[payee] = dict(cast) - requisition_pay_list.append(cast) + if "requisition" in payees: + for payee in payees["requisition"]: + cast = { + "name": payee.name, + "address": payee.address, + "amount": profit_requisition / len(payees["requisition"]), + "max": profit_requisition, + } + if payee not in pay_list: + pay_list[payee] = {} + if "amount" in pay_list[payee]: + pay_list[payee]["amount"] += cast["amount"] + else: + pay_list[payee] = dict(cast) + requisition_pay_list.append(cast) simulation[("Platform", profit_platform)] = platform_pay_list simulation[("Requisition", profit_requisition)] = requisition_pay_list