Merge pull request #16940 from rohitwaghchaure/added_cost_center_filters_in_ar_ap
feat: added cost center filter in AR/AP reports
This commit is contained in:
commit
ac9f38bfc2
@ -510,6 +510,15 @@ frappe.ui.form.on("Purchase Invoice", {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frm.set_query("cost_center", function() {
|
||||
return {
|
||||
filters: {
|
||||
company: frm.doc.company,
|
||||
is_group: 0
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
onload: function(frm) {
|
||||
|
@ -564,6 +564,15 @@ frappe.ui.form.on('Sales Invoice', {
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("cost_center", function() {
|
||||
return {
|
||||
filters: {
|
||||
company: frm.doc.company,
|
||||
is_group: 0
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.custom_make_buttons = {
|
||||
'Delivery Note': 'Delivery',
|
||||
'Sales Invoice': 'Sales Return',
|
||||
|
@ -50,6 +50,20 @@ frappe.query_reports["Accounts Payable"] = {
|
||||
"fieldtype": "Link",
|
||||
"options": "Finance Book"
|
||||
},
|
||||
{
|
||||
"fieldname":"cost_center",
|
||||
"label": __("Cost Center"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Cost Center",
|
||||
get_query: () => {
|
||||
var company = frappe.query_report.get_filter_value('company');
|
||||
return {
|
||||
filters: {
|
||||
'company': company
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldname":"supplier",
|
||||
"label": __("Supplier"),
|
||||
|
@ -50,6 +50,20 @@ frappe.query_reports["Accounts Payable Summary"] = {
|
||||
"fieldtype": "Link",
|
||||
"options": "Finance Book"
|
||||
},
|
||||
{
|
||||
"fieldname":"cost_center",
|
||||
"label": __("Cost Center"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Cost Center",
|
||||
get_query: () => {
|
||||
var company = frappe.query_report.get_filter_value('company');
|
||||
return {
|
||||
filters: {
|
||||
'company': company
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldname":"supplier",
|
||||
"label": __("Supplier"),
|
||||
|
@ -50,6 +50,20 @@ frappe.query_reports["Accounts Receivable"] = {
|
||||
"fieldtype": "Link",
|
||||
"options": "Finance Book"
|
||||
},
|
||||
{
|
||||
"fieldname":"cost_center",
|
||||
"label": __("Cost Center"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Cost Center",
|
||||
get_query: () => {
|
||||
var company = frappe.query_report.get_filter_value('company');
|
||||
return {
|
||||
filters: {
|
||||
'company': company
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldname":"customer",
|
||||
"label": __("Customer"),
|
||||
|
@ -537,6 +537,13 @@ class ReceivablePayableReport(object):
|
||||
where supplier_group=%s)""")
|
||||
values.append(self.filters.get("supplier_group"))
|
||||
|
||||
if self.filters.get("cost_center"):
|
||||
lft, rgt = frappe.get_cached_value("Cost Center",
|
||||
self.filters.get("cost_center"), ['lft', 'rgt'])
|
||||
|
||||
conditions.append("""cost_center in (select name from `tabCost Center` where
|
||||
lft >= {0} and rgt <= {1})""".format(lft, rgt))
|
||||
|
||||
accounts = [d.name for d in frappe.get_all("Account",
|
||||
filters={"account_type": account_type, "company": self.filters.company})]
|
||||
conditions.append("account in (%s)" % ','.join(['%s'] *len(accounts)))
|
||||
|
@ -50,6 +50,20 @@ frappe.query_reports["Accounts Receivable Summary"] = {
|
||||
"fieldtype": "Link",
|
||||
"options": "Finance Book"
|
||||
},
|
||||
{
|
||||
"fieldname":"cost_center",
|
||||
"label": __("Cost Center"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Cost Center",
|
||||
get_query: () => {
|
||||
var company = frappe.query_report.get_filter_value('company');
|
||||
return {
|
||||
filters: {
|
||||
'company': company
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldname":"customer",
|
||||
"label": __("Customer"),
|
||||
|
@ -260,12 +260,21 @@ def check_credit_limit(customer, company, ignore_outstanding_sales_order=False,
|
||||
throw(_("Please contact to the user who have Sales Master Manager {0} role")
|
||||
.format(" / " + credit_controller if credit_controller else ""))
|
||||
|
||||
def get_customer_outstanding(customer, company, ignore_outstanding_sales_order=False):
|
||||
def get_customer_outstanding(customer, company, ignore_outstanding_sales_order=False, cost_center=None):
|
||||
# Outstanding based on GL Entries
|
||||
|
||||
cond = ""
|
||||
if cost_center:
|
||||
lft, rgt = frappe.get_cached_value("Cost Center",
|
||||
cost_center, ['lft', 'rgt'])
|
||||
|
||||
cond = """ and cost_center in (select name from `tabCost Center` where
|
||||
lft >= {0} and rgt <= {1})""".format(lft, rgt)
|
||||
|
||||
outstanding_based_on_gle = frappe.db.sql("""
|
||||
select sum(debit) - sum(credit)
|
||||
from `tabGL Entry`
|
||||
where party_type = 'Customer' and party = %s and company=%s""", (customer, company))
|
||||
from `tabGL Entry` where party_type = 'Customer'
|
||||
and party = %s and company=%s {0}""".format(cond), (customer, company), debug=1)
|
||||
|
||||
outstanding_based_on_gle = flt(outstanding_based_on_gle[0][0]) if outstanding_based_on_gle else 0
|
||||
|
||||
|
@ -16,6 +16,20 @@ frappe.query_reports["Customer Credit Balance"] = {
|
||||
"label": __("Customer"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Customer"
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldname":"cost_center",
|
||||
"label": __("Cost Center"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Cost Center",
|
||||
get_query: () => {
|
||||
var company = frappe.query_report.get_filter_value('company');
|
||||
return {
|
||||
filters: {
|
||||
'company': company
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -21,9 +21,10 @@ def execute(filters=None):
|
||||
row = []
|
||||
|
||||
outstanding_amt = get_customer_outstanding(d.name, filters.get("company"),
|
||||
ignore_outstanding_sales_order=d.bypass_credit_limit_check_at_sales_order)
|
||||
ignore_outstanding_sales_order=d.bypass_credit_limit_check_at_sales_order,
|
||||
cost_center=filters.get("cost_center"))
|
||||
|
||||
credit_limit = get_credit_limit(d.name, filters.get("company"))
|
||||
credit_limit = get_credit_limit(d.name, filters.get("company"))
|
||||
|
||||
bal = flt(credit_limit) - flt(outstanding_amt)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user