fix: Added dimensions in financial reports and general ledger
This commit is contained in:
parent
9a05ce10d9
commit
d83cf65be1
@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
|
// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.ui.form.on('Dimension', {
|
frappe.ui.form.on('Accounting Dimension', {
|
||||||
// refresh: function(frm) {
|
// refresh: function(frm) {
|
||||||
|
|
||||||
// }
|
// }
|
@ -4,6 +4,7 @@
|
|||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
|
"document_type",
|
||||||
"label",
|
"label",
|
||||||
"fieldname"
|
"fieldname"
|
||||||
],
|
],
|
||||||
@ -13,19 +14,25 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Label",
|
"label": "Label",
|
||||||
"reqd": 1,
|
|
||||||
"unique": 1
|
"unique": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "fieldname",
|
"fieldname": "fieldname",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Fieldname"
|
"label": "Fieldname"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "document_type",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Document Type",
|
||||||
|
"options": "DocType",
|
||||||
|
"reqd": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2019-05-04 18:59:14.969008",
|
"modified": "2019-05-09 15:30:55.339917",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Dimension",
|
"name": "Accounting Dimension",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
@ -8,22 +8,26 @@ from frappe.model.document import Document
|
|||||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
||||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
|
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
|
||||||
from frappe import scrub
|
from frappe import scrub
|
||||||
|
from frappe.utils import cstr
|
||||||
|
|
||||||
class Dimension(Document):
|
class AccountingDimension(Document):
|
||||||
|
|
||||||
def before_insert(self):
|
def before_insert(self):
|
||||||
self.set_fieldname()
|
self.set_fieldname_and_label()
|
||||||
self.make_dimension_in_accounting_doctypes()
|
self.make_accounting_dimension_in_accounting_doctypes()
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
self.delete_dimension()
|
self.delete_accounting_dimension()
|
||||||
|
|
||||||
|
def set_fieldname_and_label(self):
|
||||||
|
if not self.label:
|
||||||
|
self.label = cstr(self.document_type)
|
||||||
|
|
||||||
def set_fieldname(self):
|
|
||||||
if not self.fieldname:
|
if not self.fieldname:
|
||||||
self.fieldname = scrub(self.label)
|
self.fieldname = scrub(self.label)
|
||||||
|
|
||||||
def make_dimension_in_accounting_doctypes(self):
|
def make_accounting_dimension_in_accounting_doctypes(self):
|
||||||
last_created_dimension = get_last_created_dimension()
|
last_created_accounting_dimension = get_last_created_accounting_dimension()
|
||||||
|
|
||||||
doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "BOM", "Sales Order", "Purchase Order",
|
doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "BOM", "Sales Order", "Purchase Order",
|
||||||
"Stock Entry", "Budget", "Payroll Entry", "Delivery Note"]
|
"Stock Entry", "Budget", "Payroll Entry", "Delivery Note"]
|
||||||
@ -31,14 +35,15 @@ class Dimension(Document):
|
|||||||
df = {
|
df = {
|
||||||
"fieldname": self.fieldname,
|
"fieldname": self.fieldname,
|
||||||
"label": self.label,
|
"label": self.label,
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Link",
|
||||||
"insert_after": last_created_dimension if last_created_dimension else "project"
|
"options": self.document_type,
|
||||||
|
"insert_after": last_created_accounting_dimension if last_created_accounting_dimension else "project"
|
||||||
}
|
}
|
||||||
|
|
||||||
for doctype in doclist:
|
for doctype in doclist:
|
||||||
create_custom_field(doctype, df)
|
create_custom_field(doctype, df)
|
||||||
|
|
||||||
def delete_dimension(self):
|
def delete_accounting_dimension(self):
|
||||||
doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "BOM", "Sales Order", "Purchase Order",
|
doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "BOM", "Sales Order", "Purchase Order",
|
||||||
"Stock Entry", "Budget", "Payroll Entry", "Delivery Note"]
|
"Stock Entry", "Budget", "Payroll Entry", "Delivery Note"]
|
||||||
|
|
||||||
@ -58,8 +63,13 @@ class Dimension(Document):
|
|||||||
frappe.clear_cache(doctype=doc)
|
frappe.clear_cache(doctype=doc)
|
||||||
|
|
||||||
|
|
||||||
def get_last_created_dimension():
|
def get_last_created_accounting_dimension():
|
||||||
last_created_dimension = frappe.db.sql("select fieldname, max(creation) from `tabDimension`", as_dict=1)
|
last_created_accounting_dimension = frappe.db.sql("select fieldname, max(creation) from `tabAccounting Dimension`", as_dict=1)
|
||||||
|
|
||||||
if last_created_dimension[0]:
|
if last_created_accounting_dimension[0]:
|
||||||
return last_created_dimension[0].fieldname
|
return last_created_accounting_dimension[0].fieldname
|
||||||
|
|
||||||
|
def get_accounting_dimensions():
|
||||||
|
accounting_dimensions = frappe.get_all("Accounting Dimension", fields=["fieldname"])
|
||||||
|
|
||||||
|
return [d.fieldname for d in accounting_dimensions]
|
@ -6,5 +6,5 @@ from __future__ import unicode_literals
|
|||||||
# import frappe
|
# import frappe
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
class TestDimension(unittest.TestCase):
|
class TestAccountingDimension(unittest.TestCase):
|
||||||
pass
|
pass
|
@ -16,6 +16,7 @@ from frappe import _
|
|||||||
from frappe.utils import (flt, getdate, get_first_day, add_months, add_days, formatdate)
|
from frappe.utils import (flt, getdate, get_first_day, add_months, add_days, formatdate)
|
||||||
|
|
||||||
from six import itervalues
|
from six import itervalues
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
|
||||||
|
|
||||||
def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, accumulated_values=False,
|
def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, accumulated_values=False,
|
||||||
company=None, reset_period_on_fy_change=True):
|
company=None, reset_period_on_fy_change=True):
|
||||||
@ -348,20 +349,23 @@ def set_gl_entries_by_account(
|
|||||||
additional_conditions += " and account in ({})"\
|
additional_conditions += " and account in ({})"\
|
||||||
.format(", ".join([frappe.db.escape(d) for d in accounts]))
|
.format(", ".join([frappe.db.escape(d) for d in accounts]))
|
||||||
|
|
||||||
|
gl_filters = {
|
||||||
|
"company": company,
|
||||||
|
"from_date": from_date,
|
||||||
|
"to_date": to_date,
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value in filters.items():
|
||||||
|
if value:
|
||||||
|
gl_filters.update({
|
||||||
|
key: value
|
||||||
|
})
|
||||||
|
|
||||||
gl_entries = frappe.db.sql("""select posting_date, account, debit, credit, is_opening, fiscal_year, debit_in_account_currency, credit_in_account_currency, account_currency from `tabGL Entry`
|
gl_entries = frappe.db.sql("""select posting_date, account, debit, credit, is_opening, fiscal_year, debit_in_account_currency, credit_in_account_currency, account_currency from `tabGL Entry`
|
||||||
where company=%(company)s
|
where company=%(company)s
|
||||||
{additional_conditions}
|
{additional_conditions}
|
||||||
and posting_date <= %(to_date)s
|
and posting_date <= %(to_date)s
|
||||||
order by account, posting_date""".format(additional_conditions=additional_conditions),
|
order by account, posting_date""".format(additional_conditions=additional_conditions), gl_filters, as_dict=True)
|
||||||
{
|
|
||||||
"company": company,
|
|
||||||
"from_date": from_date,
|
|
||||||
"to_date": to_date,
|
|
||||||
"cost_center": filters.cost_center,
|
|
||||||
"project": filters.project,
|
|
||||||
"finance_book": filters.get("finance_book")
|
|
||||||
},
|
|
||||||
as_dict=True)
|
|
||||||
|
|
||||||
if filters and filters.get('presentation_currency'):
|
if filters and filters.get('presentation_currency'):
|
||||||
convert_to_presentation_currency(gl_entries, get_currency(filters))
|
convert_to_presentation_currency(gl_entries, get_currency(filters))
|
||||||
@ -375,6 +379,8 @@ def set_gl_entries_by_account(
|
|||||||
def get_additional_conditions(from_date, ignore_closing_entries, filters):
|
def get_additional_conditions(from_date, ignore_closing_entries, filters):
|
||||||
additional_conditions = []
|
additional_conditions = []
|
||||||
|
|
||||||
|
accounting_dimensions = get_accounting_dimensions()
|
||||||
|
|
||||||
if ignore_closing_entries:
|
if ignore_closing_entries:
|
||||||
additional_conditions.append("ifnull(voucher_type, '')!='Period Closing Voucher'")
|
additional_conditions.append("ifnull(voucher_type, '')!='Period Closing Voucher'")
|
||||||
|
|
||||||
@ -395,6 +401,11 @@ def get_additional_conditions(from_date, ignore_closing_entries, filters):
|
|||||||
if filters.get("finance_book"):
|
if filters.get("finance_book"):
|
||||||
additional_conditions.append("ifnull(finance_book, '') in (%(finance_book)s, '')")
|
additional_conditions.append("ifnull(finance_book, '') in (%(finance_book)s, '')")
|
||||||
|
|
||||||
|
if accounting_dimensions:
|
||||||
|
for dimension in accounting_dimensions:
|
||||||
|
if filters.get(dimension):
|
||||||
|
additional_conditions.append("{0} in (%({0})s)".format(dimension))
|
||||||
|
|
||||||
return " and {}".format(" and ".join(additional_conditions)) if additional_conditions else ""
|
return " and {}".format(" and ".join(additional_conditions)) if additional_conditions else ""
|
||||||
|
|
||||||
def get_cost_centers_with_children(cost_centers):
|
def get_cost_centers_with_children(cost_centers):
|
||||||
|
@ -214,3 +214,24 @@ frappe.query_reports["General Ledger"] = {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let dimension_filters = get_dimension_filters();
|
||||||
|
|
||||||
|
dimension_filters.then((dimensions) => {
|
||||||
|
dimensions.forEach((dimension) => {
|
||||||
|
frappe.query_reports["General Ledger"].filters.push({
|
||||||
|
"fieldname": dimension["fieldname"],
|
||||||
|
"label": __(dimension["label"]),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": dimension["document_type"]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
async function get_dimension_filters() {
|
||||||
|
let dimensions = await frappe.db.get_list('Accounting Dimension', {
|
||||||
|
fields: ['label', 'fieldname', 'document_type'],
|
||||||
|
});
|
||||||
|
|
||||||
|
return dimensions;
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@ from frappe import _, _dict
|
|||||||
from erpnext.accounts.utils import get_account_currency
|
from erpnext.accounts.utils import get_account_currency
|
||||||
from erpnext.accounts.report.financial_statements import get_cost_centers_with_children
|
from erpnext.accounts.report.financial_statements import get_cost_centers_with_children
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters:
|
if not filters:
|
||||||
@ -195,6 +196,13 @@ def get_conditions(filters):
|
|||||||
if match_conditions:
|
if match_conditions:
|
||||||
conditions.append(match_conditions)
|
conditions.append(match_conditions)
|
||||||
|
|
||||||
|
accounting_dimensions = get_accounting_dimensions()
|
||||||
|
|
||||||
|
if accounting_dimensions:
|
||||||
|
for dimension in accounting_dimensions:
|
||||||
|
if filters.get(dimension):
|
||||||
|
conditions.append("{0} in (%({0})s)".format(dimension))
|
||||||
|
|
||||||
return "and {}".format(" and ".join(conditions)) if conditions else ""
|
return "and {}".format(" and ".join(conditions)) if conditions else ""
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ from erpnext.accounts.party import get_party_account_currency, validate_party_fr
|
|||||||
from erpnext.accounts.doctype.pricing_rule.utils import validate_pricing_rules
|
from erpnext.accounts.doctype.pricing_rule.utils import validate_pricing_rules
|
||||||
from erpnext.exceptions import InvalidCurrency
|
from erpnext.exceptions import InvalidCurrency
|
||||||
from six import text_type
|
from six import text_type
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
|
||||||
|
|
||||||
force_item_fields = ("item_group", "brand", "stock_uom", "is_fixed_asset", "item_tax_rate", "pricing_rules")
|
force_item_fields = ("item_group", "brand", "stock_uom", "is_fixed_asset", "item_tax_rate", "pricing_rules")
|
||||||
|
|
||||||
@ -365,6 +366,14 @@ class AccountsController(TransactionBase):
|
|||||||
'party': None,
|
'party': None,
|
||||||
'project': self.get("project")
|
'project': self.get("project")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
accounting_dimensions = get_accounting_dimensions()
|
||||||
|
dimension_dict = frappe._dict()
|
||||||
|
|
||||||
|
for dimension in accounting_dimensions:
|
||||||
|
dimension_dict[dimension] = self.get(dimension)
|
||||||
|
|
||||||
|
gl_dict.update(dimension_dict)
|
||||||
gl_dict.update(args)
|
gl_dict.update(args)
|
||||||
|
|
||||||
if not account_currency:
|
if not account_currency:
|
||||||
|
@ -63,7 +63,7 @@ erpnext.financial_statements = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function get_filters(){
|
function get_filters(){
|
||||||
return [
|
let filters = [
|
||||||
{
|
{
|
||||||
"fieldname":"company",
|
"fieldname":"company",
|
||||||
"label": __("Company"),
|
"label": __("Company"),
|
||||||
@ -149,4 +149,27 @@ function get_filters(){
|
|||||||
"options": erpnext.get_presentation_currency_list()
|
"options": erpnext.get_presentation_currency_list()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
let dimension_filters = get_dimension_filters()
|
||||||
|
|
||||||
|
dimension_filters.then((dimensions) => {
|
||||||
|
dimensions.forEach((dimension) => {
|
||||||
|
filters.push({
|
||||||
|
"fieldname": dimension["fieldname"],
|
||||||
|
"label": __(dimension["label"]),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": dimension["document_type"]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function get_dimension_filters() {
|
||||||
|
let dimensions = await frappe.db.get_list('Accounting Dimension', {
|
||||||
|
fields: ['label', 'fieldname', 'document_type'],
|
||||||
|
});
|
||||||
|
|
||||||
|
return dimensions;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user