Skip to content

Commit

Permalink
refactor: filter only immediate upcoming payment term for each SO (#3…
Browse files Browse the repository at this point in the history
…3923)

* fix: ignore closed or 'on hold' orders

* refactor: filter immediate upcoming term

---------

Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
  • Loading branch information
ruthra-kumar and deepeshgarg007 authored Feb 13, 2023
1 parent e5a2b15 commit 192a339
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ function get_filters() {
return options
}
},
{
"fieldname":"only_immediate_upcoming_term",
"label": __("Show only the Immediate Upcoming Term"),
"fieldtype": "Check",
},
]
return filters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import frappe
from frappe import _, qb, query_builder
from frappe.query_builder import Criterion, functions
from frappe.utils.dateutils import getdate


def get_columns():
Expand Down Expand Up @@ -208,6 +209,7 @@ def get_so_with_invoices(filters):
)
.where(
(so.docstatus == 1)
& (so.status.isin(["To Deliver and Bill", "To Bill"]))
& (so.payment_terms_template != "NULL")
& (so.company == conditions.company)
& (so.transaction_date[conditions.start_date : conditions.end_date])
Expand Down Expand Up @@ -291,13 +293,27 @@ def filter_on_calculated_status(filters, sales_orders):
return sales_orders


def filter_for_immediate_upcoming_term(filters, sales_orders):
if filters.only_immediate_upcoming_term and sales_orders:
immediate_term_found = set()
filtered_data = []
for order in sales_orders:
if order.name not in immediate_term_found and order.due_date > getdate():
filtered_data.append(order)
immediate_term_found.add(order.name)
return filtered_data
return sales_orders


def execute(filters=None):
columns = get_columns()
sales_orders, so_invoices = get_so_with_invoices(filters)
sales_orders, so_invoices = set_payment_terms_statuses(sales_orders, so_invoices, filters)

sales_orders = filter_on_calculated_status(filters, sales_orders)

sales_orders = filter_for_immediate_upcoming_term(filters, sales_orders)

prepare_chart(sales_orders)

data = sales_orders
Expand Down

0 comments on commit 192a339

Please sign in to comment.