Skip to content

Commit

Permalink
feat: add report LANDA Deliveries and Payments Summaries (LAN-715) (#238
Browse files Browse the repository at this point in the history
)

Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
  • Loading branch information
scdanieli and barredterra authored Aug 14, 2023
1 parent 6ef981d commit 242dac2
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 2 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -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(),
},
],
};
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion landa/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions landa/translations/de.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,

0 comments on commit 242dac2

Please sign in to comment.