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:
rohitwaghchaure 2019-03-18 14:22:15 +05:30 committed by GitHub
commit ac9f38bfc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 111 additions and 6 deletions

View File

@ -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) {

View File

@ -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',

View File

@ -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"),

View File

@ -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"),

View File

@ -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"),

View File

@ -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)))

View File

@ -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"),

View File

@ -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

View File

@ -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
}
}
}
},
]
}

View File

@ -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)