-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add report LANDA Deliveries and Payments Summaries (LAN-715) (#238
- Loading branch information
1 parent
6ef981d
commit 242dac2
Showing
7 changed files
with
199 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
32 changes: 32 additions & 0 deletions
32
...report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}, | ||
], | ||
}; |
45 changes: 45 additions & 0 deletions
45
...port/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
110 changes: 110 additions & 0 deletions
110
...report/landa_deliveries_and_payments_summaries/landa_deliveries_and_payments_summaries.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters