From 6b62e5784e9417e37480c496539f96d23f3c7eba Mon Sep 17 00:00:00 2001 From: Joonas Syysvirta Date: Thu, 10 Jul 2025 12:21:59 +0300 Subject: [PATCH] Fix accounting Excel/CSV reports Read the tax percentage that is used to get the Ceepos cost center code from the order line instead of the reservation. Also refactor the code slightly. Refs STAM-29 --- resources/api/reservation.py | 19 +++++++++++++------ resources/models/utils.py | 2 -- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/resources/api/reservation.py b/resources/api/reservation.py index c13a33f9f..051aa3ca0 100644 --- a/resources/api/reservation.py +++ b/resources/api/reservation.py @@ -33,6 +33,7 @@ from resources.models.utils import ( generate_reservation_csv, generate_reservation_xlsx, + get_ceepos_cost_center_code_value, get_object_or_none, ) from resources.pagination import ReservationPagination @@ -437,17 +438,23 @@ def add_report_data(self, request, instance, data): price = order.get_price() if price: order_line = order.order_lines.first() + unit = instance.resource.unit + + ceepos_cc_code = get_ceepos_cost_center_code_value( + unit.cost_center_code, + order_line.tax_percentage if order_line else None + ) data = { **data, "total_price": price, - "cost_center_code": instance.resource.unit.cost_center_code, - "sap_cost_center_code": instance.resource.unit.sap_cost_center_code, - "sap_sales_organization": instance.resource.unit.sap_sales_organization, + "cost_center_code": ceepos_cc_code, + "sap_cost_center_code": unit.sap_cost_center_code, + "sap_sales_organization": unit.sap_sales_organization, "invoice_generated_at": instance.invoice_generated_at, - "tax_percentage": order_line.tax_percentage if order_line else None, - "quantity": order_line.quantity if order_line else None, - "unit_price": order_line.unit_price if order_line else None, + "tax_percentage": getattr(order_line, "tax_percentage", None), + "quantity": getattr(order_line, "quantity", None), + "unit_price": getattr(order_line, "unit_price", None), } return data diff --git a/resources/models/utils.py b/resources/models/utils.py index 59a537aca..c14b5a217 100644 --- a/resources/models/utils.py +++ b/resources/models/utils.py @@ -121,8 +121,6 @@ def convert_value(reservation, name): value = reservation.get(name) or "" if value and name in RESERVATION_DATETIME_FIELDS: return localtime(value).replace(tzinfo=None) - if name == "cost_center_code": - return get_ceepos_cost_center_code_value(value, reservation["tax_percentage"]) return value