From 001604f6a8db17d4336bcfed1fc092db532d052a Mon Sep 17 00:00:00 2001 From: well Date: Thu, 26 Sep 2024 21:41:15 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=D0=BE=D0=B4=D0=B8=D0=BD=D0=B0=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=D1=8B=D0=B5=20=D1=83=D1=81=D0=BB=D1=83=D0=B3=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cash_registers/views.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/cash_registers/views.py b/cash_registers/views.py index 30bb1a47b1..572a4c7f5f 100644 --- a/cash_registers/views.py +++ b/cash_registers/views.py @@ -101,25 +101,30 @@ def get_service_coasts(directions_ids: list): result = {"ok": False, "message": "Не указан источник финансирования для оплаты", "data": {}} return result services = sql_func.get_services_by_directions(directions_ids_typle, PAY_FIN_SOURCE_ID) + print(services) if not services: result = {"ok": False, "message": "Выбранные направления нельзя оплатить", "data": {}} return result paid_directions_ids = [service.id for service in services] services_ids = tuple([service.id for service in services]) - services_coasts = { - service.id: { - "id": service.id, - "title": service.title, - "coast": 0, - "discountRelative": service.def_discount, - "discountAbsolute": 0, - "discountedCoast": 0, - "discountStatic": service.prior_discount, - "count": 1, - "total": 0, - } - for service in services - } + services_coasts = {} + for service in services: + if services_coasts.get(service.id): + service_coast = services_coasts[service.id] + count = service_coast["count"] + 1 + service_coast["count"] = count + else: + services_coasts[service.id] = { + "id": service.id, + "title": service.title, + "coast": 0, + "discountRelative": service.def_discount, + "discountAbsolute": 0, + "discountedCoast": 0, + "discountStatic": service.prior_discount, + "count": 1, + "total": 0, + } pay_fin_source: IstochnikiFinansirovaniya = IstochnikiFinansirovaniya.objects.filter(pk=PAY_FIN_SOURCE_ID).select_related('contracts').first() if pay_fin_source: @@ -134,10 +139,11 @@ def get_service_coasts(directions_ids: list): services_coasts[coast.research_id]["coast"] = service_coast services_coasts[coast.research_id]["discountAbsolute"] = discount_absolute services_coasts[coast.research_id]["discountedCoast"] = discounted_coast - services_coasts[coast.research_id]["total"] = discounted_coast + total = services_coasts[coast.research_id]["count"] * discounted_coast + services_coasts[coast.research_id]["total"] = total summ += coast.coast - if len(coasts) < len(services): + if len(coasts) < len(services_coasts): service_without_coast = True service_coasts = [i for i in services_coasts.values()]