mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-12 17:51:20 +00:00
feat: additional filters in payment terms status report
This commit is contained in:
@@ -27,28 +27,64 @@ function get_filters() {
|
|||||||
"default": frappe.datetime.get_today()
|
"default": frappe.datetime.get_today()
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"sales_order",
|
"fieldname":"customer_group",
|
||||||
"label": __("Sales Order"),
|
"label": __("Customer Group"),
|
||||||
"fieldtype": "MultiSelectList",
|
"fieldtype": "Link",
|
||||||
"width": 100,
|
"width": 100,
|
||||||
"options": "Sales Order",
|
"options": "Customer Group",
|
||||||
"get_data": function(txt) {
|
"get_query": () => {
|
||||||
return frappe.db.get_link_options("Sales Order", txt, this.filters());
|
|
||||||
},
|
|
||||||
"filters": () => {
|
|
||||||
return {
|
return {
|
||||||
docstatus: 1,
|
filters: { 'is_group': 0 }
|
||||||
payment_terms_template: ['not in', ['']],
|
|
||||||
company: frappe.query_report.get_filter_value("company"),
|
|
||||||
transaction_date: ['between', [frappe.query_report.get_filter_value("period_start_date"), frappe.query_report.get_filter_value("period_end_date")]]
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
on_change: function(){
|
|
||||||
frappe.query_report.refresh();
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"customer",
|
||||||
|
"label": __("Customer"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"width": 100,
|
||||||
|
"options": "Customer",
|
||||||
|
"get_query": () => {
|
||||||
|
filters = {
|
||||||
|
'disabled': 0
|
||||||
|
}
|
||||||
|
if(frappe.query_report.get_filter_value("customer_group") != "") {
|
||||||
|
filters['customer_group'] = frappe.query_report.get_filter_value("customer_group");
|
||||||
|
}
|
||||||
|
return { 'filters': filters };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"item_group",
|
||||||
|
"label": __("Item Group"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"width": 100,
|
||||||
|
"options": "Item Group",
|
||||||
|
"get_query": () => {
|
||||||
|
return {
|
||||||
|
filters: { 'is_group': 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"item",
|
||||||
|
"label": __("Item"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"width": 100,
|
||||||
|
"options": "Item",
|
||||||
|
"get_query": () => {
|
||||||
|
filters = {
|
||||||
|
'disabled': 0
|
||||||
|
}
|
||||||
|
if(frappe.query_report.get_filter_value("item_group") != "") {
|
||||||
|
filters['item_group'] = frappe.query_report.get_filter_value("item_group");
|
||||||
|
}
|
||||||
|
return { 'filters': filters };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, qb, query_builder
|
from frappe import _, qb, query_builder
|
||||||
from frappe.query_builder import functions
|
from frappe.query_builder import Criterion, functions
|
||||||
|
|
||||||
|
|
||||||
def get_columns():
|
def get_columns():
|
||||||
@@ -14,6 +14,12 @@ def get_columns():
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Sales Order",
|
"options": "Sales Order",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": _("Customer"),
|
||||||
|
"fieldname": "customer",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Customer",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": _("Posting Date"),
|
"label": _("Posting Date"),
|
||||||
"fieldname": "submitted",
|
"fieldname": "submitted",
|
||||||
@@ -79,11 +85,29 @@ def get_conditions(filters):
|
|||||||
conditions.start_date = filters.period_start_date or frappe.utils.add_months(
|
conditions.start_date = filters.period_start_date or frappe.utils.add_months(
|
||||||
conditions.end_date, -1
|
conditions.end_date, -1
|
||||||
)
|
)
|
||||||
conditions.sales_order = filters.sales_order or []
|
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
|
|
||||||
|
def build_filter_criterions(filters):
|
||||||
|
filters = frappe._dict(filters) if filters else frappe._dict({})
|
||||||
|
qb_criterions = []
|
||||||
|
|
||||||
|
if filters.customer_group:
|
||||||
|
qb_criterions.append(qb.DocType("Customer").customer_group == filters.customer_group)
|
||||||
|
|
||||||
|
if filters.customer:
|
||||||
|
qb_criterions.append(qb.DocType("Customer").name == filters.customer)
|
||||||
|
|
||||||
|
if filters.item_group:
|
||||||
|
qb_criterions.append(qb.DocType("Item").item_group == filters.item_group)
|
||||||
|
|
||||||
|
if filters.item:
|
||||||
|
qb_criterions.append(qb.DocType("Item").name == filters.item)
|
||||||
|
|
||||||
|
return qb_criterions
|
||||||
|
|
||||||
|
|
||||||
def get_so_with_invoices(filters):
|
def get_so_with_invoices(filters):
|
||||||
"""
|
"""
|
||||||
Get Sales Order with payment terms template with their associated Invoices
|
Get Sales Order with payment terms template with their associated Invoices
|
||||||
@@ -92,16 +116,29 @@ def get_so_with_invoices(filters):
|
|||||||
|
|
||||||
so = qb.DocType("Sales Order")
|
so = qb.DocType("Sales Order")
|
||||||
ps = qb.DocType("Payment Schedule")
|
ps = qb.DocType("Payment Schedule")
|
||||||
|
cust = qb.DocType("Customer")
|
||||||
|
item = qb.DocType("Item")
|
||||||
|
soi = qb.DocType("Sales Order Item")
|
||||||
|
|
||||||
|
conditions = get_conditions(filters)
|
||||||
|
filter_criterions = build_filter_criterions(filters)
|
||||||
|
|
||||||
datediff = query_builder.CustomFunction("DATEDIFF", ["cur_date", "due_date"])
|
datediff = query_builder.CustomFunction("DATEDIFF", ["cur_date", "due_date"])
|
||||||
ifelse = query_builder.CustomFunction("IF", ["condition", "then", "else"])
|
ifelse = query_builder.CustomFunction("IF", ["condition", "then", "else"])
|
||||||
|
|
||||||
conditions = get_conditions(filters)
|
|
||||||
query_so = (
|
query_so = (
|
||||||
qb.from_(so)
|
qb.from_(cust)
|
||||||
|
.join(so)
|
||||||
|
.on(so.customer == cust.name)
|
||||||
|
.join(soi)
|
||||||
|
.on(soi.parent == so.name)
|
||||||
|
.join(item)
|
||||||
|
.on(item.item_code == soi.item_code)
|
||||||
.join(ps)
|
.join(ps)
|
||||||
.on(ps.parent == so.name)
|
.on(ps.parent == so.name)
|
||||||
.select(
|
.select(
|
||||||
so.name,
|
so.name,
|
||||||
|
so.customer,
|
||||||
so.transaction_date.as_("submitted"),
|
so.transaction_date.as_("submitted"),
|
||||||
ifelse(datediff(ps.due_date, functions.CurDate()) < 0, "Overdue", "Unpaid").as_("status"),
|
ifelse(datediff(ps.due_date, functions.CurDate()) < 0, "Overdue", "Unpaid").as_("status"),
|
||||||
ps.payment_term,
|
ps.payment_term,
|
||||||
@@ -117,12 +154,10 @@ def get_so_with_invoices(filters):
|
|||||||
& (so.company == conditions.company)
|
& (so.company == conditions.company)
|
||||||
& (so.transaction_date[conditions.start_date : conditions.end_date])
|
& (so.transaction_date[conditions.start_date : conditions.end_date])
|
||||||
)
|
)
|
||||||
|
.where(Criterion.all(filter_criterions))
|
||||||
.orderby(so.name, so.transaction_date, ps.due_date)
|
.orderby(so.name, so.transaction_date, ps.due_date)
|
||||||
)
|
)
|
||||||
|
|
||||||
if conditions.sales_order != []:
|
|
||||||
query_so = query_so.where(so.name.isin(conditions.sales_order))
|
|
||||||
|
|
||||||
sorders = query_so.run(as_dict=True)
|
sorders = query_so.run(as_dict=True)
|
||||||
|
|
||||||
invoices = []
|
invoices = []
|
||||||
|
|||||||
Reference in New Issue
Block a user