feat: added cost center filter in AR/AP reports
This commit is contained in:
parent
349a1157ef
commit
ace95d5a67
@ -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) {
|
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 = {
|
frm.custom_make_buttons = {
|
||||||
'Delivery Note': 'Delivery',
|
'Delivery Note': 'Delivery',
|
||||||
'Sales Invoice': 'Sales Return',
|
'Sales Invoice': 'Sales Return',
|
||||||
|
|||||||
@ -50,6 +50,20 @@ frappe.query_reports["Accounts Payable"] = {
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Finance Book"
|
"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",
|
"fieldname":"supplier",
|
||||||
"label": __("Supplier"),
|
"label": __("Supplier"),
|
||||||
|
|||||||
@ -50,6 +50,20 @@ frappe.query_reports["Accounts Payable Summary"] = {
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Finance Book"
|
"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",
|
"fieldname":"supplier",
|
||||||
"label": __("Supplier"),
|
"label": __("Supplier"),
|
||||||
|
|||||||
@ -50,6 +50,20 @@ frappe.query_reports["Accounts Receivable"] = {
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Finance Book"
|
"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",
|
"fieldname":"customer",
|
||||||
"label": __("Customer"),
|
"label": __("Customer"),
|
||||||
|
|||||||
@ -537,6 +537,13 @@ class ReceivablePayableReport(object):
|
|||||||
where supplier_group=%s)""")
|
where supplier_group=%s)""")
|
||||||
values.append(self.filters.get("supplier_group"))
|
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",
|
accounts = [d.name for d in frappe.get_all("Account",
|
||||||
filters={"account_type": account_type, "company": self.filters.company})]
|
filters={"account_type": account_type, "company": self.filters.company})]
|
||||||
conditions.append("account in (%s)" % ','.join(['%s'] *len(accounts)))
|
conditions.append("account in (%s)" % ','.join(['%s'] *len(accounts)))
|
||||||
|
|||||||
@ -50,6 +50,20 @@ frappe.query_reports["Accounts Receivable Summary"] = {
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Finance Book"
|
"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",
|
"fieldname":"customer",
|
||||||
"label": __("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")
|
throw(_("Please contact to the user who have Sales Master Manager {0} role")
|
||||||
.format(" / " + credit_controller if credit_controller else ""))
|
.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
|
# 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("""
|
outstanding_based_on_gle = frappe.db.sql("""
|
||||||
select sum(debit) - sum(credit)
|
select sum(debit) - sum(credit)
|
||||||
from `tabGL Entry`
|
from `tabGL Entry` where party_type = 'Customer'
|
||||||
where party_type = 'Customer' and party = %s and company=%s""", (customer, company))
|
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
|
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"),
|
"label": __("Customer"),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": "Customer"
|
"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,7 +21,8 @@ def execute(filters=None):
|
|||||||
row = []
|
row = []
|
||||||
|
|
||||||
outstanding_amt = get_customer_outstanding(d.name, filters.get("company"),
|
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"))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user