From 242dac2f32a1c1fe33a970fc7fe1cb473d4d9729 Mon Sep 17 00:00:00 2001 From: Samuel Danieli <23150094+scdanieli@users.noreply.github.com> Date: Mon, 14 Aug 2023 21:42:05 +0200 Subject: [PATCH] feat: add report LANDA Deliveries and Payments Summaries (LAN-715) (#238) Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- .../__init__.py | 0 ...landa_deliveries_and_payments_summaries.js | 32 +++++ ...nda_deliveries_and_payments_summaries.json | 45 +++++++ ...landa_deliveries_and_payments_summaries.py | 110 ++++++++++++++++++ .../order_management/order_management.json | 11 +- landa/patches.txt | 2 +- landa/translations/de.csv | 1 + 7 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 landa/landa_sales/report/landa_deliveries_and_payments_summaries/__init__.py create mode 100644 landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.js create mode 100644 landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.json create mode 100644 landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.py diff --git a/landa/landa_sales/report/landa_deliveries_and_payments_summaries/__init__.py b/landa/landa_sales/report/landa_deliveries_and_payments_summaries/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.js b/landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.js new file mode 100644 index 00000000..172d4f62 --- /dev/null +++ b/landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.js @@ -0,0 +1,32 @@ +// Copyright (c) 2023, ALYF GmbH and contributors +// For license information, please see license.txt +/* eslint-disable */ + +frappe.query_reports["LANDA Deliveries and Payments Summaries"] = { + filters: [ + { + fieldname: "organization", + fieldtype: "Link", + label: "Organization", + mandatory: 0, + options: "Organization", + wildcard_filter: 0, + default: frappe.boot.landa.organization, + get_query: function () { + return { + filters: { + parent_organization: frappe.boot.landa.regional_organization, + }, + }; + }, + }, + { + fieldname: "year_of_settlement", + fieldtype: "Data", + label: "Year of Settlement", + mandatory: 0, + wildcard_filter: 0, + default: new Date().getFullYear(), + }, + ], +}; diff --git a/landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.json b/landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.json new file mode 100644 index 00000000..3384460a --- /dev/null +++ b/landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.json @@ -0,0 +1,45 @@ +{ + "add_total_row": 1, + "columns": [], + "creation": "2023-08-13 07:57:14.110476", + "disable_prepared_report": 1, + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "filters": [], + "idx": 0, + "is_standard": "Yes", + "letter_head": "Extended Information in Footer", + "modified": "2023-08-14 21:36:45.525674", + "modified_by": "Administrator", + "module": "LANDA Sales", + "name": "LANDA Deliveries and Payments Summaries", + "owner": "Administrator", + "prepared_report": 1, + "ref_doctype": "Delivery Note", + "report_name": "LANDA Deliveries and Payments Summaries", + "report_type": "Script Report", + "roles": [ + { + "role": "Accounts User" + }, + { + "role": "Accounts Manager" + }, + { + "role": "Auditor" + }, + { + "role": "Sales User" + }, + { + "role": "Sales Manager" + }, + { + "role": "LANDA Regional Organization Management" + }, + { + "role": "LANDA Local Organization Management" + } + ] +} \ No newline at end of file diff --git a/landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.py b/landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.py new file mode 100644 index 00000000..26560ee0 --- /dev/null +++ b/landa/landa_sales/report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.py @@ -0,0 +1,110 @@ +# Copyright (c) 2023, ALYF GmbH and contributors +# For license information, please see license.txt + +from datetime import datetime + +import frappe +from frappe import _ + + +class LandaDeliveriesAndPaymentsSummaries: + def __init__(self, filters): + self.filters = filters + + def run(self): + return self.get_columns(), self.get_data() + + def get_base_filters(self, organization, year_of_settlement): + filters = self.filters.copy() + filters["docstatus"] = 1 + filters["organization"] = organization + filters["year_of_settlement"] = year_of_settlement + + return filters + + def fetch_and_sum(self, doctype, pluck_field, extra_filters): + return sum(frappe.get_list(doctype, pluck=pluck_field, filters=extra_filters)) + + def get_data(self): + data = [] + + years_of_settlement = ( + [self.filters["year_of_settlement"]] + if self.filters.get("year_of_settlement") + else list(range(2021, datetime.now().year + 1)) + ) + + organizations = ( + [self.filters["organization"]] + if self.filters.get("organization") + else frappe.get_list( + "Organization", pluck="name", filters=[["parent_organization", "in", ["AVS", "AVL", "AVE"]]] + ) + ) + + for year_of_settlement in years_of_settlement: + for organization in organizations: + base_filters = self.get_base_filters(organization, year_of_settlement) + + delivery_filters = base_filters.copy() + delivery_filters["is_return"] = 0 + delivery_totals = self.fetch_and_sum("Delivery Note", "base_grand_total", delivery_filters) + + return_filters = base_filters.copy() + return_filters["is_return"] = 1 + return_totals = self.fetch_and_sum("Delivery Note", "base_grand_total", return_filters) + + payments_received_filters = base_filters.copy() + payments_received_filters["payment_type"] = "Receive" + payments_received_filters["party_type"] = "Customer" + payments_received_amounts = -self.fetch_and_sum( + "Payment Entry", "base_paid_amount", payments_received_filters + ) + + payments_sent_filters = base_filters.copy() + payments_sent_filters["payment_type"] = "Pay" + payments_sent_filters["party_type"] = "Customer" + payments_sent_amounts = self.fetch_and_sum( + "Payment Entry", "base_paid_amount", payments_sent_filters + ) + + data.append( + { + "organization": organization, + "year_of_settlement": year_of_settlement, + "outstanding_amount": delivery_totals + + return_totals + + payments_received_amounts + + payments_sent_amounts, + } + ) + + return sorted(data, key=lambda row: row["organization"]) + + def get_columns(self): + return [ + { + "fieldname": "organization", + "fieldtype": "Link", + "options": "Organization", + "label": _("Organization"), + "width": 200, + }, + { + "fieldname": "year_of_settlement", + "fieldtype": "Data", + "label": _("Year of Settlement"), + "disable_total": True, + "width": 200, + }, + { + "fieldname": "outstanding_amount", + "fieldtype": "Currency", + "label": _("Outstanding Amount"), + "width": 200, + }, + ] + + +def execute(filters=None): + return LandaDeliveriesAndPaymentsSummaries(filters).run() diff --git a/landa/landa_sales/workspace/order_management/order_management.json b/landa/landa_sales/workspace/order_management/order_management.json index 2b73d877..10f40623 100644 --- a/landa/landa_sales/workspace/order_management/order_management.json +++ b/landa/landa_sales/workspace/order_management/order_management.json @@ -156,6 +156,15 @@ "onboard": 0, "type": "Link" }, + { + "hidden": 0, + "is_query_report": 1, + "label": "LANDA Deliveries and Payments Summaries", + "link_to": "LANDA Deliveries and Payments Summaries", + "link_type": "Report", + "onboard": 0, + "type": "Link" + }, { "hidden": 0, "is_query_report": 1, @@ -192,7 +201,7 @@ "type": "Link" } ], - "modified": "2023-06-03 09:39:24.071517", + "modified": "2023-08-13 09:30:54.733641", "modified_by": "Administrator", "module": "LANDA Sales", "name": "Order Management", diff --git a/landa/patches.txt b/landa/patches.txt index 991aaee7..1009756b 100644 --- a/landa/patches.txt +++ b/landa/patches.txt @@ -22,6 +22,6 @@ execute:from landa.install import update_accounts_settings; update_accounts_sett landa.patches.set_billing_and_shipping_defaults landa.patches.delete_old_scheduled_job_logs landa.patches.update_system_settings -landa.patches.delete_customized_workspaces # 2023-06-06 +landa.patches.delete_customized_workspaces # 2023-08-14 landa.patches.build_water_body_cache landa.patches.set_hide_custom_in_user_workspaces diff --git a/landa/translations/de.csv b/landa/translations/de.csv index 6b6daae7..0e20fb5d 100644 --- a/landa/translations/de.csv +++ b/landa/translations/de.csv @@ -25,3 +25,4 @@ Water Body Export,Export Gewässerverzeichnis, No permission to set Member Function Category {0},"Sie haben nicht die nötigen Rechte, um eine Mitgliedsfunktion der Kategorie {0} zu vergeben", The {0} Function Category can only be assigned once per member in the same organization., Die Mitgliedsfunktion {0} kann nur einmal pro Mitglied in der gleichen Organisation vergeben werden., Only One per Organization, Nur eine pro Organisation, +LANDA Deliveries and Payments Summaries,Kostenübersicht Zusammenfassung, \ No newline at end of file