mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-22 14:39:19 +00:00
feat: (minor) purchase register filters
This commit is contained in:
@@ -34,6 +34,33 @@ frappe.query_reports["Purchase Register"] = {
|
|||||||
"label": __("Mode of Payment"),
|
"label": __("Mode of Payment"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Mode of Payment"
|
"options": "Mode of Payment"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"cost_center",
|
||||||
|
"label": __("Cost Center"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Cost Center"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"warehouse",
|
||||||
|
"label": __("Warehouse"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Warehouse"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname":"item_group",
|
||||||
|
"label": __("Item Group"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Item Group"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
erpnext.dimension_filters.forEach((dimension) => {
|
||||||
|
frappe.query_reports["Purchase Register"].filters.splice(7, 0 ,{
|
||||||
|
"fieldname": dimension["fieldname"],
|
||||||
|
"label": __(dimension["label"]),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": dimension["document_type"]
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
from frappe import msgprint, _
|
from frappe import msgprint, _
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions, get_dimension_with_children
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
return _execute(filters)
|
return _execute(filters)
|
||||||
@@ -134,6 +135,34 @@ def get_conditions(filters):
|
|||||||
|
|
||||||
if filters.get("mode_of_payment"): conditions += " and ifnull(mode_of_payment, '') = %(mode_of_payment)s"
|
if filters.get("mode_of_payment"): conditions += " and ifnull(mode_of_payment, '') = %(mode_of_payment)s"
|
||||||
|
|
||||||
|
if filters.get("cost_center"):
|
||||||
|
conditions += """ and exists(select name from `tabPurchase Invoice Item`
|
||||||
|
where parent=`tabPurchase Invoice`.name
|
||||||
|
and ifnull(`tabPurchase Invoice Item`.cost_center, '') = %(cost_center)s)"""
|
||||||
|
|
||||||
|
if filters.get("warehouse"):
|
||||||
|
conditions += """ and exists(select name from `tabPurchase Invoice Item`
|
||||||
|
where parent=`tabPurchase Invoice`.name
|
||||||
|
and ifnull(`tabPurchase Invoice Item`.warehouse, '') = %(warehouse)s)"""
|
||||||
|
|
||||||
|
if filters.get("item_group"):
|
||||||
|
conditions += """ and exists(select name from `tabPurchase Invoice Item`
|
||||||
|
where parent=`tabPurchase Invoice`.name
|
||||||
|
and ifnull(`tabPurchase Invoice Item`.item_group, '') = %(item_group)s)"""
|
||||||
|
|
||||||
|
accounting_dimensions = get_accounting_dimensions(as_list=False)
|
||||||
|
|
||||||
|
if accounting_dimensions:
|
||||||
|
for dimension in accounting_dimensions:
|
||||||
|
if filters.get(dimension.fieldname):
|
||||||
|
if frappe.get_cached_value('DocType', dimension.document_type, 'is_tree'):
|
||||||
|
filters[dimension.fieldname] = get_dimension_with_children(dimension.document_type,
|
||||||
|
filters.get(dimension.fieldname))
|
||||||
|
|
||||||
|
conditions += """ and exists(select name from `tabPurchase Invoice Item`
|
||||||
|
where parent=`tabPurchase Invoice`.name
|
||||||
|
and ifnull(`tabPurchase Invoice Item`.{0}, '') in %({0})s)""".format(dimension.fieldname)
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
def get_invoices(filters, additional_query_columns):
|
def get_invoices(filters, additional_query_columns):
|
||||||
|
|||||||
Reference in New Issue
Block a user