mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 08:54:45 +00:00
Merge pull request #23912 from deepeshgarg007/accounting_dimension_filters
feat: Configurable accounting dimension filters and validations
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.ui.form.on('Accounting Dimension', {
|
frappe.ui.form.on('Accounting Dimension', {
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
frm.set_query('document_type', () => {
|
frm.set_query('document_type', () => {
|
||||||
let invalid_doctypes = frappe.model.core_doctypes_list;
|
let invalid_doctypes = frappe.model.core_doctypes_list;
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ def get_dimension_with_children(doctype, dimension):
|
|||||||
return all_dimensions
|
return all_dimensions
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_dimension_filters():
|
def get_dimensions(with_cost_center_and_project=False):
|
||||||
dimension_filters = frappe.db.sql("""
|
dimension_filters = frappe.db.sql("""
|
||||||
SELECT label, fieldname, document_type
|
SELECT label, fieldname, document_type
|
||||||
FROM `tabAccounting Dimension`
|
FROM `tabAccounting Dimension`
|
||||||
@@ -214,6 +214,18 @@ def get_dimension_filters():
|
|||||||
FROM `tabAccounting Dimension Detail` c, `tabAccounting Dimension` p
|
FROM `tabAccounting Dimension Detail` c, `tabAccounting Dimension` p
|
||||||
WHERE c.parent = p.name""", as_dict=1)
|
WHERE c.parent = p.name""", as_dict=1)
|
||||||
|
|
||||||
|
if with_cost_center_and_project:
|
||||||
|
dimension_filters.extend([
|
||||||
|
{
|
||||||
|
'fieldname': 'cost_center',
|
||||||
|
'document_type': 'Cost Center'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'fieldname': 'project',
|
||||||
|
'document_type': 'Project'
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
default_dimensions_map = {}
|
default_dimensions_map = {}
|
||||||
for dimension in default_dimensions:
|
for dimension in default_dimensions:
|
||||||
default_dimensions_map.setdefault(dimension.company, {})
|
default_dimensions_map.setdefault(dimension.company, {})
|
||||||
|
|||||||
@@ -11,37 +11,7 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import d
|
|||||||
|
|
||||||
class TestAccountingDimension(unittest.TestCase):
|
class TestAccountingDimension(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
frappe.set_user("Administrator")
|
create_dimension()
|
||||||
|
|
||||||
if not frappe.db.exists("Accounting Dimension", {"document_type": "Department"}):
|
|
||||||
dimension = frappe.get_doc({
|
|
||||||
"doctype": "Accounting Dimension",
|
|
||||||
"document_type": "Department",
|
|
||||||
}).insert()
|
|
||||||
else:
|
|
||||||
dimension1 = frappe.get_doc("Accounting Dimension", "Department")
|
|
||||||
dimension1.disabled = 0
|
|
||||||
dimension1.save()
|
|
||||||
|
|
||||||
if not frappe.db.exists("Accounting Dimension", {"document_type": "Location"}):
|
|
||||||
dimension1 = frappe.get_doc({
|
|
||||||
"doctype": "Accounting Dimension",
|
|
||||||
"document_type": "Location",
|
|
||||||
})
|
|
||||||
|
|
||||||
dimension1.append("dimension_defaults", {
|
|
||||||
"company": "_Test Company",
|
|
||||||
"reference_document": "Location",
|
|
||||||
"default_dimension": "Block 1",
|
|
||||||
"mandatory_for_bs": 1
|
|
||||||
})
|
|
||||||
|
|
||||||
dimension1.insert()
|
|
||||||
dimension1.save()
|
|
||||||
else:
|
|
||||||
dimension1 = frappe.get_doc("Accounting Dimension", "Location")
|
|
||||||
dimension1.disabled = 0
|
|
||||||
dimension1.save()
|
|
||||||
|
|
||||||
def test_dimension_against_sales_invoice(self):
|
def test_dimension_against_sales_invoice(self):
|
||||||
si = create_sales_invoice(do_not_save=1)
|
si = create_sales_invoice(do_not_save=1)
|
||||||
@@ -101,6 +71,38 @@ class TestAccountingDimension(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
disable_dimension()
|
disable_dimension()
|
||||||
|
|
||||||
|
def create_dimension():
|
||||||
|
frappe.set_user("Administrator")
|
||||||
|
|
||||||
|
if not frappe.db.exists("Accounting Dimension", {"document_type": "Department"}):
|
||||||
|
frappe.get_doc({
|
||||||
|
"doctype": "Accounting Dimension",
|
||||||
|
"document_type": "Department",
|
||||||
|
}).insert()
|
||||||
|
else:
|
||||||
|
dimension = frappe.get_doc("Accounting Dimension", "Department")
|
||||||
|
dimension.disabled = 0
|
||||||
|
dimension.save()
|
||||||
|
|
||||||
|
if not frappe.db.exists("Accounting Dimension", {"document_type": "Location"}):
|
||||||
|
dimension1 = frappe.get_doc({
|
||||||
|
"doctype": "Accounting Dimension",
|
||||||
|
"document_type": "Location",
|
||||||
|
})
|
||||||
|
|
||||||
|
dimension1.append("dimension_defaults", {
|
||||||
|
"company": "_Test Company",
|
||||||
|
"reference_document": "Location",
|
||||||
|
"default_dimension": "Block 1",
|
||||||
|
"mandatory_for_bs": 1
|
||||||
|
})
|
||||||
|
|
||||||
|
dimension1.insert()
|
||||||
|
dimension1.save()
|
||||||
|
else:
|
||||||
|
dimension1 = frappe.get_doc("Accounting Dimension", "Location")
|
||||||
|
dimension1.disabled = 0
|
||||||
|
dimension1.save()
|
||||||
|
|
||||||
def disable_dimension():
|
def disable_dimension():
|
||||||
dimension1 = frappe.get_doc("Accounting Dimension", "Department")
|
dimension1 = frappe.get_doc("Accounting Dimension", "Department")
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
|
// For license information, please see license.txt
|
||||||
|
|
||||||
|
frappe.ui.form.on('Accounting Dimension Filter', {
|
||||||
|
refresh: function(frm, cdt, cdn) {
|
||||||
|
if (frm.doc.accounting_dimension) {
|
||||||
|
frm.set_df_property('dimensions', 'label', frm.doc.accounting_dimension, cdn, 'dimension_value');
|
||||||
|
}
|
||||||
|
|
||||||
|
let help_content =
|
||||||
|
`<table class="table table-bordered" style="background-color: #f9f9f9;">
|
||||||
|
<tr><td>
|
||||||
|
<p>
|
||||||
|
<i class="fa fa-hand-right"></i>
|
||||||
|
{{__('Note: On checking Is Mandatory the accounting dimension will become mandatory against that specific account for all accounting transactions')}}
|
||||||
|
</p>
|
||||||
|
</td></tr>
|
||||||
|
</table>`;
|
||||||
|
|
||||||
|
frm.set_df_property('dimension_filter_help', 'options', help_content);
|
||||||
|
},
|
||||||
|
onload: function(frm) {
|
||||||
|
frm.set_query('applicable_on_account', 'accounts', function() {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
'company': frm.doc.company
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
frappe.db.get_list('Accounting Dimension',
|
||||||
|
{fields: ['document_type']}).then((res) => {
|
||||||
|
let options = ['Cost Center', 'Project'];
|
||||||
|
|
||||||
|
res.forEach((dimension) => {
|
||||||
|
options.push(dimension.document_type);
|
||||||
|
});
|
||||||
|
|
||||||
|
frm.set_df_property('accounting_dimension', 'options', options);
|
||||||
|
});
|
||||||
|
|
||||||
|
frm.trigger('setup_filters');
|
||||||
|
},
|
||||||
|
|
||||||
|
setup_filters: function(frm) {
|
||||||
|
let filters = {};
|
||||||
|
|
||||||
|
if (frm.doc.accounting_dimension) {
|
||||||
|
frappe.model.with_doctype(frm.doc.accounting_dimension, function() {
|
||||||
|
if (frappe.model.is_tree(frm.doc.accounting_dimension)) {
|
||||||
|
filters['is_group'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frappe.meta.has_field(frm.doc.accounting_dimension, 'company')) {
|
||||||
|
filters['company'] = frm.doc.company;
|
||||||
|
}
|
||||||
|
|
||||||
|
frm.set_query('dimension_value', 'dimensions', function() {
|
||||||
|
return {
|
||||||
|
filters: filters
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
accounting_dimension: function(frm) {
|
||||||
|
frm.clear_table("dimensions");
|
||||||
|
let row = frm.add_child("dimensions");
|
||||||
|
row.accounting_dimension = frm.doc.accounting_dimension;
|
||||||
|
frm.refresh_field("dimensions");
|
||||||
|
frm.trigger('setup_filters');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
frappe.ui.form.on('Allowed Dimension', {
|
||||||
|
dimensions_add: function(frm, cdt, cdn) {
|
||||||
|
let row = locals[cdt][cdn];
|
||||||
|
row.accounting_dimension = frm.doc.accounting_dimension;
|
||||||
|
frm.refresh_field("dimensions");
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
{
|
||||||
|
"actions": [],
|
||||||
|
"autoname": "format:{accounting_dimension}-{#####}",
|
||||||
|
"creation": "2020-11-08 18:28:11.906146",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"accounting_dimension",
|
||||||
|
"disabled",
|
||||||
|
"column_break_2",
|
||||||
|
"company",
|
||||||
|
"allow_or_restrict",
|
||||||
|
"section_break_4",
|
||||||
|
"accounts",
|
||||||
|
"column_break_6",
|
||||||
|
"dimensions",
|
||||||
|
"section_break_10",
|
||||||
|
"dimension_filter_help"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "accounting_dimension",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Accounting Dimension",
|
||||||
|
"reqd": 1,
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_2",
|
||||||
|
"fieldtype": "Column Break",
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "section_break_4",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"hide_border": 1,
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_6",
|
||||||
|
"fieldtype": "Column Break",
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "allow_or_restrict",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"label": "Allow Or Restrict Dimension",
|
||||||
|
"options": "Allow\nRestrict",
|
||||||
|
"reqd": 1,
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "accounts",
|
||||||
|
"fieldtype": "Table",
|
||||||
|
"label": "Applicable On Account",
|
||||||
|
"options": "Applicable On Account",
|
||||||
|
"reqd": 1,
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "eval:doc.accounting_dimension",
|
||||||
|
"fieldname": "dimensions",
|
||||||
|
"fieldtype": "Table",
|
||||||
|
"label": "Applicable Dimension",
|
||||||
|
"options": "Allowed Dimension",
|
||||||
|
"reqd": 1,
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "disabled",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Disabled",
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "company",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Company",
|
||||||
|
"options": "Company",
|
||||||
|
"reqd": 1,
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "dimension_filter_help",
|
||||||
|
"fieldtype": "HTML",
|
||||||
|
"label": "Dimension Filter Help",
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "section_break_10",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"index_web_pages_for_search": 1,
|
||||||
|
"links": [],
|
||||||
|
"modified": "2020-12-16 15:27:23.659285",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "Accounts",
|
||||||
|
"name": "Accounting Dimension Filter",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"create": 1,
|
||||||
|
"delete": 1,
|
||||||
|
"email": 1,
|
||||||
|
"export": 1,
|
||||||
|
"print": 1,
|
||||||
|
"read": 1,
|
||||||
|
"report": 1,
|
||||||
|
"role": "System Manager",
|
||||||
|
"share": 1,
|
||||||
|
"write": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"quick_entry": 1,
|
||||||
|
"sort_field": "modified",
|
||||||
|
"sort_order": "DESC",
|
||||||
|
"track_changes": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright, (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import frappe
|
||||||
|
from frappe import _, scrub
|
||||||
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
class AccountingDimensionFilter(Document):
|
||||||
|
def validate(self):
|
||||||
|
self.validate_applicable_accounts()
|
||||||
|
|
||||||
|
def validate_applicable_accounts(self):
|
||||||
|
accounts = frappe.db.sql(
|
||||||
|
"""
|
||||||
|
SELECT a.applicable_on_account as account
|
||||||
|
FROM `tabApplicable On Account` a, `tabAccounting Dimension Filter` d
|
||||||
|
WHERE d.name = a.parent
|
||||||
|
and d.name != %s
|
||||||
|
and d.accounting_dimension = %s
|
||||||
|
""", (self.name, self.accounting_dimension), as_dict=1)
|
||||||
|
|
||||||
|
account_list = [d.account for d in accounts]
|
||||||
|
|
||||||
|
for account in self.get('accounts'):
|
||||||
|
if account.applicable_on_account in account_list:
|
||||||
|
frappe.throw(_("Row {0}: {1} account already applied for Accounting Dimension {2}").format(
|
||||||
|
account.idx, frappe.bold(account.applicable_on_account), frappe.bold(self.accounting_dimension)))
|
||||||
|
|
||||||
|
def get_dimension_filter_map():
|
||||||
|
filters = frappe.db.sql("""
|
||||||
|
SELECT
|
||||||
|
a.applicable_on_account, d.dimension_value, p.accounting_dimension,
|
||||||
|
p.allow_or_restrict, a.is_mandatory
|
||||||
|
FROM
|
||||||
|
`tabApplicable On Account` a, `tabAllowed Dimension` d,
|
||||||
|
`tabAccounting Dimension Filter` p
|
||||||
|
WHERE
|
||||||
|
p.name = a.parent
|
||||||
|
AND p.disabled = 0
|
||||||
|
AND p.name = d.parent
|
||||||
|
""", as_dict=1)
|
||||||
|
|
||||||
|
dimension_filter_map = {}
|
||||||
|
|
||||||
|
for f in filters:
|
||||||
|
f.fieldname = scrub(f.accounting_dimension)
|
||||||
|
|
||||||
|
build_map(dimension_filter_map, f.fieldname, f.applicable_on_account, f.dimension_value,
|
||||||
|
f.allow_or_restrict, f.is_mandatory)
|
||||||
|
|
||||||
|
return dimension_filter_map
|
||||||
|
|
||||||
|
def build_map(map_object, dimension, account, filter_value, allow_or_restrict, is_mandatory):
|
||||||
|
map_object.setdefault((dimension, account), {
|
||||||
|
'allowed_dimensions': [],
|
||||||
|
'is_mandatory': is_mandatory,
|
||||||
|
'allow_or_restrict': allow_or_restrict
|
||||||
|
})
|
||||||
|
map_object[(dimension, account)]['allowed_dimensions'].append(filter_value)
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
|
# See license.txt
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
import unittest
|
||||||
|
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import create_dimension, disable_dimension
|
||||||
|
from erpnext.exceptions import InvalidAccountDimensionError, MandatoryAccountDimensionError
|
||||||
|
|
||||||
|
class TestAccountingDimensionFilter(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
create_dimension()
|
||||||
|
create_accounting_dimension_filter()
|
||||||
|
self.invoice_list = []
|
||||||
|
|
||||||
|
def test_allowed_dimension_validation(self):
|
||||||
|
si = create_sales_invoice(do_not_save=1)
|
||||||
|
si.items[0].cost_center = 'Main - _TC'
|
||||||
|
si.department = 'Accounts - _TC'
|
||||||
|
si.location = 'Block 1'
|
||||||
|
si.save()
|
||||||
|
|
||||||
|
self.assertRaises(InvalidAccountDimensionError, si.submit)
|
||||||
|
self.invoice_list.append(si)
|
||||||
|
|
||||||
|
def test_mandatory_dimension_validation(self):
|
||||||
|
si = create_sales_invoice(do_not_save=1)
|
||||||
|
si.department = ''
|
||||||
|
si.location = 'Block 1'
|
||||||
|
|
||||||
|
# Test with no department for Sales Account
|
||||||
|
si.items[0].department = ''
|
||||||
|
si.items[0].cost_center = '_Test Cost Center 2 - _TC'
|
||||||
|
si.save()
|
||||||
|
|
||||||
|
self.assertRaises(MandatoryAccountDimensionError, si.submit)
|
||||||
|
self.invoice_list.append(si)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
disable_dimension_filter()
|
||||||
|
disable_dimension()
|
||||||
|
|
||||||
|
for si in self.invoice_list:
|
||||||
|
si.load_from_db()
|
||||||
|
if si.docstatus == 1:
|
||||||
|
si.cancel()
|
||||||
|
|
||||||
|
def create_accounting_dimension_filter():
|
||||||
|
if not frappe.db.get_value('Accounting Dimension Filter',
|
||||||
|
{'accounting_dimension': 'Cost Center'}):
|
||||||
|
frappe.get_doc({
|
||||||
|
'doctype': 'Accounting Dimension Filter',
|
||||||
|
'accounting_dimension': 'Cost Center',
|
||||||
|
'allow_or_restrict': 'Allow',
|
||||||
|
'company': '_Test Company',
|
||||||
|
'accounts': [{
|
||||||
|
'applicable_on_account': 'Sales - _TC',
|
||||||
|
}],
|
||||||
|
'dimensions': [{
|
||||||
|
'accounting_dimension': 'Cost Center',
|
||||||
|
'dimension_value': '_Test Cost Center 2 - _TC'
|
||||||
|
}]
|
||||||
|
}).insert()
|
||||||
|
else:
|
||||||
|
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Cost Center'})
|
||||||
|
doc.disabled = 0
|
||||||
|
doc.save()
|
||||||
|
|
||||||
|
if not frappe.db.get_value('Accounting Dimension Filter',
|
||||||
|
{'accounting_dimension': 'Department'}):
|
||||||
|
frappe.get_doc({
|
||||||
|
'doctype': 'Accounting Dimension Filter',
|
||||||
|
'accounting_dimension': 'Department',
|
||||||
|
'allow_or_restrict': 'Allow',
|
||||||
|
'company': '_Test Company',
|
||||||
|
'accounts': [{
|
||||||
|
'applicable_on_account': 'Sales - _TC',
|
||||||
|
'is_mandatory': 1
|
||||||
|
}],
|
||||||
|
'dimensions': [{
|
||||||
|
'accounting_dimension': 'Department',
|
||||||
|
'dimension_value': 'Accounts - _TC'
|
||||||
|
}]
|
||||||
|
}).insert()
|
||||||
|
else:
|
||||||
|
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Department'})
|
||||||
|
doc.disabled = 0
|
||||||
|
doc.save()
|
||||||
|
|
||||||
|
def disable_dimension_filter():
|
||||||
|
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Cost Center'})
|
||||||
|
doc.disabled = 1
|
||||||
|
doc.save()
|
||||||
|
|
||||||
|
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Department'})
|
||||||
|
doc.disabled = 1
|
||||||
|
doc.save()
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"actions": [],
|
||||||
|
"creation": "2020-11-08 18:22:36.001131",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"accounting_dimension",
|
||||||
|
"dimension_value"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "accounting_dimension",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Accounting Dimension",
|
||||||
|
"options": "DocType",
|
||||||
|
"read_only": 1,
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "dimension_value",
|
||||||
|
"fieldtype": "Dynamic Link",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"options": "accounting_dimension",
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"index_web_pages_for_search": 1,
|
||||||
|
"istable": 1,
|
||||||
|
"links": [],
|
||||||
|
"modified": "2020-11-23 09:56:19.744200",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "Accounts",
|
||||||
|
"name": "Allowed Dimension",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"permissions": [],
|
||||||
|
"quick_entry": 1,
|
||||||
|
"sort_field": "modified",
|
||||||
|
"sort_order": "DESC",
|
||||||
|
"track_changes": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
# import frappe
|
||||||
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
class AllowedDimension(Document):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"actions": [],
|
||||||
|
"creation": "2020-11-08 18:20:00.944449",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"applicable_on_account",
|
||||||
|
"is_mandatory"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "applicable_on_account",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Accounts",
|
||||||
|
"options": "Account",
|
||||||
|
"reqd": 1,
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"columns": 2,
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "is_mandatory",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Is Mandatory",
|
||||||
|
"show_days": 1,
|
||||||
|
"show_seconds": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"index_web_pages_for_search": 1,
|
||||||
|
"istable": 1,
|
||||||
|
"links": [],
|
||||||
|
"modified": "2020-11-22 19:55:13.324136",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "Accounts",
|
||||||
|
"name": "Applicable On Account",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"permissions": [],
|
||||||
|
"quick_entry": 1,
|
||||||
|
"sort_field": "modified",
|
||||||
|
"sort_order": "DESC",
|
||||||
|
"track_changes": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
# import frappe
|
||||||
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
class ApplicableOnAccount(Document):
|
||||||
|
pass
|
||||||
@@ -1,24 +1,9 @@
|
|||||||
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
frappe.ui.form.on('Budget', {
|
frappe.ui.form.on('Budget', {
|
||||||
onload: function(frm) {
|
onload: function(frm) {
|
||||||
frm.set_query("cost_center", function() {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
company: frm.doc.company
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
frm.set_query("project", function() {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
company: frm.doc.company
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
frm.set_query("account", "accounts", function() {
|
frm.set_query("account", "accounts", function() {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
@@ -26,16 +11,18 @@ frappe.ui.form.on('Budget', {
|
|||||||
report_type: "Profit and Loss",
|
report_type: "Profit and Loss",
|
||||||
is_group: 0
|
is_group: 0
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
|
|
||||||
frm.set_query("monthly_distribution", function() {
|
frm.set_query("monthly_distribution", function() {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
fiscal_year: frm.doc.fiscal_year
|
fiscal_year: frm.doc.fiscal_year
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ from frappe.model.meta import get_field_precision
|
|||||||
from erpnext.accounts.party import validate_party_gle_currency, validate_party_frozen_disabled
|
from erpnext.accounts.party import validate_party_gle_currency, validate_party_frozen_disabled
|
||||||
from erpnext.accounts.utils import get_account_currency
|
from erpnext.accounts.utils import get_account_currency
|
||||||
from erpnext.accounts.utils import get_fiscal_year
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
from erpnext.exceptions import InvalidAccountCurrency
|
from erpnext.exceptions import InvalidAccountCurrency, InvalidAccountDimensionError, MandatoryAccountDimensionError
|
||||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_checks_for_pl_and_bs_accounts
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_checks_for_pl_and_bs_accounts
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension_filter.accounting_dimension_filter import get_dimension_filter_map
|
||||||
|
from six import iteritems
|
||||||
|
|
||||||
exclude_from_linked_with = True
|
exclude_from_linked_with = True
|
||||||
class GLEntry(Document):
|
class GLEntry(Document):
|
||||||
@@ -39,6 +41,7 @@ class GLEntry(Document):
|
|||||||
if not from_repost:
|
if not from_repost:
|
||||||
self.validate_account_details(adv_adj)
|
self.validate_account_details(adv_adj)
|
||||||
self.validate_dimensions_for_pl_and_bs()
|
self.validate_dimensions_for_pl_and_bs()
|
||||||
|
self.validate_allowed_dimensions()
|
||||||
|
|
||||||
validate_frozen_account(self.account, adv_adj)
|
validate_frozen_account(self.account, adv_adj)
|
||||||
validate_balance_type(self.account, adv_adj)
|
validate_balance_type(self.account, adv_adj)
|
||||||
@@ -76,11 +79,9 @@ class GLEntry(Document):
|
|||||||
.format(self.voucher_type, self.voucher_no, self.account))
|
.format(self.voucher_type, self.voucher_no, self.account))
|
||||||
|
|
||||||
def validate_dimensions_for_pl_and_bs(self):
|
def validate_dimensions_for_pl_and_bs(self):
|
||||||
|
|
||||||
account_type = frappe.db.get_value("Account", self.account, "report_type")
|
account_type = frappe.db.get_value("Account", self.account, "report_type")
|
||||||
|
|
||||||
for dimension in get_checks_for_pl_and_bs_accounts():
|
for dimension in get_checks_for_pl_and_bs_accounts():
|
||||||
|
|
||||||
if account_type == "Profit and Loss" \
|
if account_type == "Profit and Loss" \
|
||||||
and self.company == dimension.company and dimension.mandatory_for_pl and not dimension.disabled:
|
and self.company == dimension.company and dimension.mandatory_for_pl and not dimension.disabled:
|
||||||
if not self.get(dimension.fieldname):
|
if not self.get(dimension.fieldname):
|
||||||
@@ -93,6 +94,25 @@ class GLEntry(Document):
|
|||||||
frappe.throw(_("Accounting Dimension <b>{0}</b> is required for 'Balance Sheet' account {1}.")
|
frappe.throw(_("Accounting Dimension <b>{0}</b> is required for 'Balance Sheet' account {1}.")
|
||||||
.format(dimension.label, self.account))
|
.format(dimension.label, self.account))
|
||||||
|
|
||||||
|
def validate_allowed_dimensions(self):
|
||||||
|
dimension_filter_map = get_dimension_filter_map()
|
||||||
|
for key, value in iteritems(dimension_filter_map):
|
||||||
|
dimension = key[0]
|
||||||
|
account = key[1]
|
||||||
|
|
||||||
|
if self.account == account:
|
||||||
|
if value['is_mandatory'] and not self.get(dimension):
|
||||||
|
frappe.throw(_("{0} is mandatory for account {1}").format(
|
||||||
|
frappe.bold(frappe.unscrub(dimension)), frappe.bold(self.account)), MandatoryAccountDimensionError)
|
||||||
|
|
||||||
|
if value['allow_or_restrict'] == 'Allow':
|
||||||
|
if self.get(dimension) and self.get(dimension) not in value['allowed_dimensions']:
|
||||||
|
frappe.throw(_("Invalid value {0} for {1} against account {2}").format(
|
||||||
|
frappe.bold(self.get(dimension)), frappe.bold(frappe.unscrub(dimension)), frappe.bold(self.account)), InvalidAccountDimensionError)
|
||||||
|
else:
|
||||||
|
if self.get(dimension) and self.get(dimension) in value['allowed_dimensions']:
|
||||||
|
frappe.throw(_("Invalid value {0} for {1} against account {2}").format(
|
||||||
|
frappe.bold(self.get(dimension)), frappe.bold(frappe.unscrub(dimension)), frappe.bold(self.account)), InvalidAccountDimensionError)
|
||||||
|
|
||||||
def check_pl_account(self):
|
def check_pl_account(self):
|
||||||
if self.is_opening=='Yes' and \
|
if self.is_opening=='Yes' and \
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ frappe.ui.form.on("Journal Entry", {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
voucher_type: function(frm){
|
voucher_type: function(frm){
|
||||||
@@ -197,6 +199,7 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
|
|||||||
this.load_defaults();
|
this.load_defaults();
|
||||||
this.setup_queries();
|
this.setup_queries();
|
||||||
this.setup_balance_formatter();
|
this.setup_balance_formatter();
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
onload_post_render: function() {
|
onload_post_render: function() {
|
||||||
@@ -222,15 +225,6 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
|
|||||||
return erpnext.journal_entry.account_query(me.frm);
|
return erpnext.journal_entry.account_query(me.frm);
|
||||||
});
|
});
|
||||||
|
|
||||||
me.frm.set_query("cost_center", "accounts", function(doc, cdt, cdn) {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
company: me.frm.doc.company,
|
|
||||||
is_group: 0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
me.frm.set_query("party_type", "accounts", function(doc, cdt, cdn) {
|
me.frm.set_query("party_type", "accounts", function(doc, cdt, cdn) {
|
||||||
const row = locals[cdt][cdn];
|
const row = locals[cdt][cdn];
|
||||||
|
|
||||||
@@ -406,6 +400,8 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur_frm.cscript.update_totals(doc);
|
cur_frm.cscript.update_totals(doc);
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, 'accounts');
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
frappe.ui.form.on('Loyalty Program', {
|
frappe.ui.form.on('Loyalty Program', {
|
||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
var help_content =
|
var help_content =
|
||||||
@@ -46,20 +48,17 @@ frappe.ui.form.on('Loyalty Program', {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("cost_center", function() {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
company: frm.doc.company
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
frm.set_value("company", frappe.defaults.get_user_default("Company"));
|
frm.set_value("company", frappe.defaults.get_user_default("Company"));
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
if (frm.doc.loyalty_program_type === "Single Tier Program" && frm.doc.collection_rules.length > 1) {
|
if (frm.doc.loyalty_program_type === "Single Tier Program" && frm.doc.collection_rules.length > 1) {
|
||||||
frappe.throw(__("Please select the Multiple Tier Program type for more than one collection rules."));
|
frappe.throw(__("Please select the Multiple Tier Program type for more than one collection rules."));
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
company: function(frm) {
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ frappe.ui.form.on('Opening Invoice Creation Tool', {
|
|||||||
frm.dashboard.show_progress(data.title, (data.count / data.total) * 100, data.message);
|
frm.dashboard.show_progress(data.title, (data.count / data.total) * 100, data.message);
|
||||||
frm.page.set_indicator(__('In Progress'), 'orange');
|
frm.page.set_indicator(__('In Progress'), 'orange');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
@@ -100,6 +102,7 @@ frappe.ui.form.on('Opening Invoice Creation Tool', {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
invoice_type: function(frm) {
|
invoice_type: function(frm) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
{% include "erpnext/public/js/controllers/accounts.js" %}
|
{% include "erpnext/public/js/controllers/accounts.js" %}
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
frappe.ui.form.on('Payment Entry', {
|
frappe.ui.form.on('Payment Entry', {
|
||||||
onload: function(frm) {
|
onload: function(frm) {
|
||||||
@@ -8,6 +9,8 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
if (!frm.doc.paid_from) frm.set_value("paid_from_account_currency", null);
|
if (!frm.doc.paid_from) frm.set_value("paid_from_account_currency", null);
|
||||||
if (!frm.doc.paid_to) frm.set_value("paid_to_account_currency", null);
|
if (!frm.doc.paid_to) frm.set_value("paid_to_account_currency", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
@@ -88,15 +91,6 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("cost_center", "deductions", function() {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
"is_group": 0,
|
|
||||||
"company": frm.doc.company
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
frm.set_query("reference_doctype", "references", function() {
|
frm.set_query("reference_doctype", "references", function() {
|
||||||
if (frm.doc.party_type=="Customer") {
|
if (frm.doc.party_type=="Customer") {
|
||||||
var doctypes = ["Sales Order", "Sales Invoice", "Journal Entry", "Dunning"];
|
var doctypes = ["Sales Order", "Sales Invoice", "Journal Entry", "Dunning"];
|
||||||
@@ -167,6 +161,7 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
company: function(frm) {
|
company: function(frm) {
|
||||||
frm.events.hide_unhide_fields(frm);
|
frm.events.hide_unhide_fields(frm);
|
||||||
frm.events.set_dynamic_labels(frm);
|
frm.events.set_dynamic_labels(frm);
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
contact_person: function(frm) {
|
contact_person: function(frm) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from frappe import _
|
|||||||
from erpnext.accounts.utils import get_account_currency
|
from erpnext.accounts.utils import get_account_currency
|
||||||
from erpnext.controllers.accounts_controller import AccountsController
|
from erpnext.controllers.accounts_controller import AccountsController
|
||||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (get_accounting_dimensions,
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (get_accounting_dimensions,
|
||||||
get_dimension_filters)
|
get_dimensions)
|
||||||
|
|
||||||
class PeriodClosingVoucher(AccountsController):
|
class PeriodClosingVoucher(AccountsController):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
@@ -58,7 +58,7 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
for dimension in accounting_dimensions:
|
for dimension in accounting_dimensions:
|
||||||
dimension_fields.append('t1.{0}'.format(dimension))
|
dimension_fields.append('t1.{0}'.format(dimension))
|
||||||
|
|
||||||
dimension_filters, default_dimensions = get_dimension_filters()
|
dimension_filters, default_dimensions = get_dimensions()
|
||||||
|
|
||||||
pl_accounts = self.get_pl_balances(dimension_fields)
|
pl_accounts = self.get_pl_balances(dimension_fields)
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ frappe.ui.form.on('POS Profile', {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
@@ -67,6 +69,7 @@ frappe.ui.form.on('POS Profile', {
|
|||||||
|
|
||||||
company: function(frm) {
|
company: function(frm) {
|
||||||
frm.trigger("toggle_display_account_head");
|
frm.trigger("toggle_display_account_head");
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
toggle_display_account_head: function(frm) {
|
toggle_display_account_head: function(frm) {
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
company: function() {
|
||||||
|
erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype);
|
||||||
|
},
|
||||||
|
|
||||||
onload: function() {
|
onload: function() {
|
||||||
this._super();
|
this._super();
|
||||||
|
|
||||||
@@ -41,6 +46,8 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
|||||||
if (this.frm.doc.supplier && this.frm.doc.__islocal) {
|
if (this.frm.doc.supplier && this.frm.doc.__islocal) {
|
||||||
this.frm.trigger('supplier');
|
this.frm.trigger('supplier');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(doc) {
|
refresh: function(doc) {
|
||||||
@@ -511,15 +518,6 @@ 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) {
|
||||||
|
|||||||
@@ -5,14 +5,17 @@
|
|||||||
cur_frm.pformat.print_heading = 'Invoice';
|
cur_frm.pformat.print_heading = 'Invoice';
|
||||||
|
|
||||||
{% include 'erpnext/selling/sales_common.js' %};
|
{% include 'erpnext/selling/sales_common.js' %};
|
||||||
|
|
||||||
|
|
||||||
frappe.provide("erpnext.accounts");
|
frappe.provide("erpnext.accounts");
|
||||||
|
|
||||||
|
|
||||||
erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({
|
erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({
|
||||||
setup: function(doc) {
|
setup: function(doc) {
|
||||||
this.setup_posting_date_time_check();
|
this.setup_posting_date_time_check();
|
||||||
this._super(doc);
|
this._super(doc);
|
||||||
},
|
},
|
||||||
|
company: function() {
|
||||||
|
erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype);
|
||||||
|
},
|
||||||
onload: function() {
|
onload: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
this._super();
|
this._super();
|
||||||
@@ -33,6 +36,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
|||||||
me.frm.refresh_fields();
|
me.frm.refresh_fields();
|
||||||
}
|
}
|
||||||
erpnext.queries.setup_warehouse_query(this.frm);
|
erpnext.queries.setup_warehouse_query(this.frm);
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(doc, dt, dn) {
|
refresh: function(doc, dt, dn) {
|
||||||
@@ -571,15 +575,6 @@ frappe.ui.form.on('Sales Invoice', {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("cost_center", function() {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
company: frm.doc.company,
|
|
||||||
is_group: 0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
frm.set_query("unrealized_profit_loss_account", function() {
|
frm.set_query("unrealized_profit_loss_account", function() {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
frappe.ui.form.on('Shipping Rule', {
|
frappe.provide('erpnext.accounts.dimensions');
|
||||||
refresh: function(frm) {
|
|
||||||
frm.set_query("cost_center", function() {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
company: frm.doc.company
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
frappe.ui.form.on('Shipping Rule', {
|
||||||
|
onload: function(frm) {
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
|
},
|
||||||
|
|
||||||
|
company: function(frm) {
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
|
},
|
||||||
|
|
||||||
|
refresh: function(frm) {
|
||||||
frm.set_query("account", function() {
|
frm.set_query("account", function() {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.provide("erpnext.asset");
|
frappe.provide("erpnext.asset");
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
frappe.ui.form.on('Asset', {
|
frappe.ui.form.on('Asset', {
|
||||||
onload: function(frm) {
|
onload: function(frm) {
|
||||||
@@ -32,13 +33,11 @@ frappe.ui.form.on('Asset', {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("cost_center", function() {
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
return {
|
},
|
||||||
"filters": {
|
|
||||||
"company": frm.doc.company,
|
company: function(frm) {
|
||||||
}
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
};
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
frappe.ui.form.on('Asset Value Adjustment', {
|
frappe.ui.form.on('Asset Value Adjustment', {
|
||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
frm.add_fetch('company', 'cost_center', 'cost_center');
|
frm.add_fetch('company', 'cost_center', 'cost_center');
|
||||||
@@ -13,11 +15,19 @@ frappe.ui.form.on('Asset Value Adjustment', {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onload: function(frm) {
|
onload: function(frm) {
|
||||||
if(frm.is_new() && frm.doc.asset) {
|
if(frm.is_new() && frm.doc.asset) {
|
||||||
frm.trigger("set_current_asset_value");
|
frm.trigger("set_current_asset_value");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
company: function(frm) {
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
|
},
|
||||||
|
|
||||||
asset: function(frm) {
|
asset: function(frm) {
|
||||||
frm.trigger("set_current_asset_value");
|
frm.trigger("set_current_asset_value");
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
frappe.provide("erpnext.buying");
|
frappe.provide("erpnext.buying");
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
{% include 'erpnext/public/js/controllers/buying.js' %};
|
{% include 'erpnext/public/js/controllers/buying.js' %};
|
||||||
|
|
||||||
frappe.ui.form.on("Purchase Order", {
|
frappe.ui.form.on("Purchase Order", {
|
||||||
@@ -30,6 +30,10 @@ frappe.ui.form.on("Purchase Order", {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
company: function(frm) {
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
|
},
|
||||||
|
|
||||||
onload: function(frm) {
|
onload: function(frm) {
|
||||||
set_schedule_date(frm);
|
set_schedule_date(frm);
|
||||||
if (!frm.doc.transaction_date){
|
if (!frm.doc.transaction_date){
|
||||||
@@ -39,6 +43,8 @@ frappe.ui.form.on("Purchase Order", {
|
|||||||
erpnext.queries.setup_queries(frm, "Warehouse", function() {
|
erpnext.queries.setup_queries(frm, "Warehouse", function() {
|
||||||
return erpnext.queries.warehouse(frm.doc);
|
return erpnext.queries.warehouse(frm.doc);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -493,6 +493,41 @@ def get_income_account(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
'company': filters.get("company", "")
|
'company': filters.get("company", "")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
@frappe.validate_and_sanitize_search_inputs
|
||||||
|
def get_filtered_dimensions(doctype, txt, searchfield, start, page_len, filters):
|
||||||
|
from erpnext.accounts.doctype.accounting_dimension_filter.accounting_dimension_filter import get_dimension_filter_map
|
||||||
|
dimension_filters = get_dimension_filter_map()
|
||||||
|
dimension_filters = dimension_filters.get((filters.get('dimension'),filters.get('account')))
|
||||||
|
query_filters = []
|
||||||
|
|
||||||
|
meta = frappe.get_meta(doctype)
|
||||||
|
if meta.is_tree:
|
||||||
|
query_filters.append(['is_group', '=', 0])
|
||||||
|
|
||||||
|
if meta.has_field('company'):
|
||||||
|
query_filters.append(['company', '=', filters.get('company')])
|
||||||
|
|
||||||
|
if txt:
|
||||||
|
query_filters.append([searchfield, 'LIKE', "%%%s%%" % txt])
|
||||||
|
|
||||||
|
if dimension_filters:
|
||||||
|
if dimension_filters['allow_or_restrict'] == 'Allow':
|
||||||
|
query_selector = 'in'
|
||||||
|
else:
|
||||||
|
query_selector = 'not in'
|
||||||
|
|
||||||
|
if len(dimension_filters['allowed_dimensions']) == 1:
|
||||||
|
dimensions = tuple(dimension_filters['allowed_dimensions'] * 2)
|
||||||
|
else:
|
||||||
|
dimensions = tuple(dimension_filters['allowed_dimensions'])
|
||||||
|
|
||||||
|
query_filters.append(['name', query_selector, dimensions])
|
||||||
|
|
||||||
|
output = frappe.get_all(doctype, filters=query_filters)
|
||||||
|
result = [d.name for d in output]
|
||||||
|
|
||||||
|
return [(d,) for d in set(result)]
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@frappe.validate_and_sanitize_search_inputs
|
@frappe.validate_and_sanitize_search_inputs
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
|
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
frappe.ui.form.on('Fee Schedule', {
|
frappe.ui.form.on('Fee Schedule', {
|
||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
frm.add_fetch('fee_structure', 'receivable_account', 'receivable_account');
|
frm.add_fetch('fee_structure', 'receivable_account', 'receivable_account');
|
||||||
@@ -8,6 +9,10 @@ frappe.ui.form.on('Fee Schedule', {
|
|||||||
frm.add_fetch('fee_structure', 'cost_center', 'cost_center');
|
frm.add_fetch('fee_structure', 'cost_center', 'cost_center');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
company: function(frm) {
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
|
},
|
||||||
|
|
||||||
onload: function(frm) {
|
onload: function(frm) {
|
||||||
frm.set_query('receivable_account', function(doc) {
|
frm.set_query('receivable_account', function(doc) {
|
||||||
return {
|
return {
|
||||||
@@ -50,6 +55,8 @@ frappe.ui.form.on('Fee Schedule', {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
|
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
frappe.ui.form.on('Fee Structure', {
|
frappe.ui.form.on('Fee Structure', {
|
||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
frm.add_fetch('company', 'default_receivable_account', 'receivable_account');
|
frm.add_fetch('company', 'default_receivable_account', 'receivable_account');
|
||||||
@@ -8,6 +10,10 @@ frappe.ui.form.on('Fee Structure', {
|
|||||||
frm.add_fetch('company', 'cost_center', 'cost_center');
|
frm.add_fetch('company', 'cost_center', 'cost_center');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
company: function(frm) {
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
|
},
|
||||||
|
|
||||||
onload: function(frm) {
|
onload: function(frm) {
|
||||||
frm.set_query('academic_term', function() {
|
frm.set_query('academic_term', function() {
|
||||||
return {
|
return {
|
||||||
@@ -35,6 +41,8 @@ frappe.ui.form.on('Fee Structure', {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
|
// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
frappe.ui.form.on("Fees", {
|
frappe.ui.form.on("Fees", {
|
||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
@@ -9,15 +10,19 @@ frappe.ui.form.on("Fees", {
|
|||||||
frm.add_fetch("fee_structure", "cost_center", "cost_center");
|
frm.add_fetch("fee_structure", "cost_center", "cost_center");
|
||||||
},
|
},
|
||||||
|
|
||||||
onload: function(frm){
|
company: function(frm) {
|
||||||
frm.set_query("academic_term",function(){
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
|
},
|
||||||
|
|
||||||
|
onload: function(frm) {
|
||||||
|
frm.set_query("academic_term", function() {
|
||||||
return{
|
return{
|
||||||
"filters":{
|
"filters": {
|
||||||
"academic_year": (frm.doc.academic_year)
|
"academic_year": (frm.doc.academic_year)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
frm.set_query("fee_structure",function(){
|
frm.set_query("fee_structure", function() {
|
||||||
return{
|
return{
|
||||||
"filters":{
|
"filters":{
|
||||||
"academic_year": (frm.doc.academic_year)
|
"academic_year": (frm.doc.academic_year)
|
||||||
@@ -45,6 +50,8 @@ frappe.ui.form.on("Fees", {
|
|||||||
if (!frm.doc.posting_date) {
|
if (!frm.doc.posting_date) {
|
||||||
frm.doc.posting_date = frappe.datetime.get_today();
|
frm.doc.posting_date = frappe.datetime.get_today();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
|
|||||||
@@ -6,3 +6,5 @@ class PartyFrozen(frappe.ValidationError): pass
|
|||||||
class InvalidAccountCurrency(frappe.ValidationError): pass
|
class InvalidAccountCurrency(frappe.ValidationError): pass
|
||||||
class InvalidCurrency(frappe.ValidationError): pass
|
class InvalidCurrency(frappe.ValidationError): pass
|
||||||
class PartyDisabled(frappe.ValidationError):pass
|
class PartyDisabled(frappe.ValidationError):pass
|
||||||
|
class InvalidAccountDimensionError(frappe.ValidationError): pass
|
||||||
|
class MandatoryAccountDimensionError(frappe.ValidationError): pass
|
||||||
|
|||||||
@@ -2,11 +2,21 @@
|
|||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
frappe.provide("erpnext.hr");
|
frappe.provide("erpnext.hr");
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
erpnext.hr.ExpenseClaimController = frappe.ui.form.Controller.extend({
|
frappe.ui.form.on('Expense Claim', {
|
||||||
expense_type: function(doc, cdt, cdn) {
|
onload: function(frm) {
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
|
},
|
||||||
|
company: function(frm) {
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
frappe.ui.form.on('Expense Claim Detail', {
|
||||||
|
expense_type: function(frm, cdt, cdn) {
|
||||||
var d = locals[cdt][cdn];
|
var d = locals[cdt][cdn];
|
||||||
if(!doc.company) {
|
if (!frm.doc.company) {
|
||||||
d.expense_type = "";
|
d.expense_type = "";
|
||||||
frappe.msgprint(__("Please set the Company"));
|
frappe.msgprint(__("Please set the Company"));
|
||||||
this.frm.refresh_fields();
|
this.frm.refresh_fields();
|
||||||
@@ -20,7 +30,7 @@ erpnext.hr.ExpenseClaimController = frappe.ui.form.Controller.extend({
|
|||||||
method: "erpnext.hr.doctype.expense_claim.expense_claim.get_expense_claim_account_and_cost_center",
|
method: "erpnext.hr.doctype.expense_claim.expense_claim.get_expense_claim_account_and_cost_center",
|
||||||
args: {
|
args: {
|
||||||
"expense_claim_type": d.expense_type,
|
"expense_claim_type": d.expense_type,
|
||||||
"company": doc.company
|
"company": frm.doc.company
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if (r.message) {
|
if (r.message) {
|
||||||
@@ -32,8 +42,6 @@ erpnext.hr.ExpenseClaimController = frappe.ui.form.Controller.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$.extend(cur_frm.cscript, new erpnext.hr.ExpenseClaimController({frm: cur_frm}));
|
|
||||||
|
|
||||||
cur_frm.add_fetch('employee', 'company', 'company');
|
cur_frm.add_fetch('employee', 'company', 'company');
|
||||||
cur_frm.add_fetch('employee','employee_name','employee_name');
|
cur_frm.add_fetch('employee','employee_name','employee_name');
|
||||||
cur_frm.add_fetch('expense_type','description','description');
|
cur_frm.add_fetch('expense_type','description','description');
|
||||||
@@ -167,15 +175,6 @@ frappe.ui.form.on("Expense Claim", {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("cost_center", "expenses", function() {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
"company": frm.doc.company,
|
|
||||||
"is_group": 0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
frm.set_query("payable_account", function() {
|
frm.set_query("payable_account", function() {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
var in_progress = false;
|
var in_progress = false;
|
||||||
|
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
frappe.ui.form.on('Payroll Entry', {
|
frappe.ui.form.on('Payroll Entry', {
|
||||||
onload: function (frm) {
|
onload: function (frm) {
|
||||||
if (!frm.doc.posting_date) {
|
if (!frm.doc.posting_date) {
|
||||||
@@ -10,6 +12,7 @@ frappe.ui.form.on('Payroll Entry', {
|
|||||||
}
|
}
|
||||||
frm.toggle_reqd(['payroll_frequency'], !frm.doc.salary_slip_based_on_timesheet);
|
frm.toggle_reqd(['payroll_frequency'], !frm.doc.salary_slip_based_on_timesheet);
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
frm.events.department_filters(frm);
|
frm.events.department_filters(frm);
|
||||||
frm.events.payroll_payable_account_filters(frm);
|
frm.events.payroll_payable_account_filters(frm);
|
||||||
},
|
},
|
||||||
@@ -129,21 +132,6 @@ frappe.ui.form.on('Payroll Entry', {
|
|||||||
"company": frm.doc.company
|
"company": frm.doc.company
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}),
|
|
||||||
frm.set_query("cost_center", function () {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
"is_group": 0,
|
|
||||||
company: frm.doc.company
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
frm.set_query("project", function () {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
company: frm.doc.company
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -183,6 +171,7 @@ frappe.ui.form.on('Payroll Entry', {
|
|||||||
|
|
||||||
company: function (frm) {
|
company: function (frm) {
|
||||||
frm.events.clear_employee_table(frm);
|
frm.events.clear_employee_table(frm);
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
currency: function (frm) {
|
currency: function (frm) {
|
||||||
|
|||||||
@@ -31,15 +31,6 @@ frappe.ui.form.on(cur_frm.doctype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query("cost_center", "taxes", function(doc) {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
'company': doc.company,
|
|
||||||
"is_group": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
validate: function(frm) {
|
validate: function(frm) {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
frappe.provide('erpnext.accounts.dimensions');
|
||||||
|
|
||||||
erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||||
setup: function() {
|
setup: function() {
|
||||||
this._super();
|
this._super();
|
||||||
@@ -106,6 +108,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
if(!item.warehouse && frm.doc.set_warehouse) {
|
if(!item.warehouse && frm.doc.set_warehouse) {
|
||||||
item.warehouse = frm.doc.set_warehouse;
|
item.warehouse = frm.doc.set_warehouse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.copy_dimension_from_first_row(frm, cdt, cdn, 'items');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -159,16 +163,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (this.frm.fields_dict["items"].grid.get_field("cost_center")) {
|
|
||||||
this.frm.set_query("cost_center", "items", function(doc) {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
"company": doc.company,
|
|
||||||
"is_group": 0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.frm.fields_dict["items"].grid.get_field("expense_account")) {
|
if (this.frm.fields_dict["items"].grid.get_field("expense_account")) {
|
||||||
this.frm.set_query("expense_account", "items", function(doc) {
|
this.frm.set_query("expense_account", "items", function(doc) {
|
||||||
|
|||||||
@@ -115,7 +115,26 @@ $.extend(erpnext.queries, {
|
|||||||
["Warehouse", "is_group", "=",0]
|
["Warehouse", "is_group", "=",0]
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
get_filtered_dimensions: function(doc, child_fields, dimension, company) {
|
||||||
|
let account = '';
|
||||||
|
|
||||||
|
child_fields.forEach((field) => {
|
||||||
|
if (!account) {
|
||||||
|
account = doc[field];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
query: "erpnext.controllers.queries.get_filtered_dimensions",
|
||||||
|
filters: {
|
||||||
|
'dimension': dimension,
|
||||||
|
'account': account,
|
||||||
|
'company': company
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -194,15 +194,21 @@ $.extend(erpnext.utils, {
|
|||||||
add_dimensions: function(report_name, index) {
|
add_dimensions: function(report_name, index) {
|
||||||
let filters = frappe.query_reports[report_name].filters;
|
let filters = frappe.query_reports[report_name].filters;
|
||||||
|
|
||||||
erpnext.dimension_filters.forEach((dimension) => {
|
frappe.call({
|
||||||
let found = filters.some(el => el.fieldname === dimension['fieldname']);
|
method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimensions",
|
||||||
|
callback: function(r) {
|
||||||
|
let accounting_dimensions = r.message[0];
|
||||||
|
accounting_dimensions.forEach((dimension) => {
|
||||||
|
let found = filters.some(el => el.fieldname === dimension['fieldname']);
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
filters.splice(index, 0 ,{
|
filters.splice(index, 0, {
|
||||||
"fieldname": dimension["fieldname"],
|
"fieldname": dimension["fieldname"],
|
||||||
"label": __(dimension["label"]),
|
"label": __(dimension["label"]),
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": dimension["document_type"]
|
"options": dimension["document_type"]
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,54 +1,83 @@
|
|||||||
frappe.provide('frappe.ui.form');
|
frappe.provide('erpnext.accounts');
|
||||||
|
|
||||||
let default_dimensions = {};
|
erpnext.accounts.dimensions = {
|
||||||
|
setup_dimension_filters(frm, doctype) {
|
||||||
|
this.accounting_dimensions = [];
|
||||||
|
this.default_dimensions = {};
|
||||||
|
this.fetch_custom_dimensions(frm, doctype);
|
||||||
|
},
|
||||||
|
|
||||||
let doctypes_with_dimensions = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset",
|
fetch_custom_dimensions(frm, doctype) {
|
||||||
"Expense Claim", "Stock Entry", "Budget", "Payroll Entry", "Delivery Note", "Shipping Rule", "Loyalty Program",
|
let me = this;
|
||||||
"Fee Schedule", "Fee Structure", "Stock Reconciliation", "Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool",
|
frappe.call({
|
||||||
"Subscription", "Purchase Order", "Journal Entry", "Material Request", "Purchase Receipt", "Landed Cost Item", "Asset"];
|
method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimensions",
|
||||||
|
args: {
|
||||||
|
'with_cost_center_and_project': true
|
||||||
|
},
|
||||||
|
callback: function(r) {
|
||||||
|
me.accounting_dimensions = r.message[0];
|
||||||
|
me.default_dimensions = r.message[1];
|
||||||
|
me.setup_filters(frm, doctype);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
let child_docs = ["Sales Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Journal Entry Account",
|
setup_filters(frm, doctype) {
|
||||||
"Material Request Item", "Delivery Note Item", "Purchase Receipt Item", "Stock Entry Detail", "Payment Entry Deduction",
|
if (this.accounting_dimensions) {
|
||||||
"Landed Cost Item", "Asset Value Adjustment", "Opening Invoice Creation Tool Item", "Subscription Plan"];
|
this.accounting_dimensions.forEach((dimension) => {
|
||||||
|
|
||||||
frappe.call({
|
|
||||||
method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimension_filters",
|
|
||||||
callback: function(r) {
|
|
||||||
erpnext.dimension_filters = r.message[0];
|
|
||||||
default_dimensions = r.message[1];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
doctypes_with_dimensions.forEach((doctype) => {
|
|
||||||
frappe.ui.form.on(doctype, {
|
|
||||||
onload: function(frm) {
|
|
||||||
erpnext.dimension_filters.forEach((dimension) => {
|
|
||||||
frappe.model.with_doctype(dimension['document_type'], () => {
|
frappe.model.with_doctype(dimension['document_type'], () => {
|
||||||
if(frappe.meta.has_field(dimension['document_type'], 'is_group')) {
|
let parent_fields = [];
|
||||||
frm.set_query(dimension['fieldname'], {
|
frappe.meta.get_docfields(doctype).forEach((df) => {
|
||||||
"is_group": 0
|
if (df.fieldtype === 'Link' && df.options === 'Account') {
|
||||||
});
|
parent_fields.push(df.fieldname);
|
||||||
}
|
} else if (df.fieldtype === 'Table') {
|
||||||
|
this.setup_child_filters(frm, df.options, df.fieldname, dimension['fieldname']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frappe.meta.has_field(doctype, dimension['fieldname'])) {
|
||||||
|
this.setup_account_filters(frm, dimension['fieldname'], parent_fields);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
},
|
||||||
|
|
||||||
company: function(frm) {
|
setup_child_filters(frm, doctype, parentfield, dimension) {
|
||||||
if(frm.doc.company && (Object.keys(default_dimensions || {}).length > 0)
|
let fields = [];
|
||||||
&& default_dimensions[frm.doc.company]) {
|
|
||||||
frm.trigger('update_dimension');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
update_dimension: function(frm) {
|
if (frappe.meta.has_field(doctype, dimension)) {
|
||||||
erpnext.dimension_filters.forEach((dimension) => {
|
frappe.model.with_doctype(doctype, () => {
|
||||||
if(frm.is_new()) {
|
frappe.meta.get_docfields(doctype).forEach((df) => {
|
||||||
if(frm.doc.company && Object.keys(default_dimensions || {}).length > 0
|
if (df.fieldtype === 'Link' && df.options === 'Account') {
|
||||||
&& default_dimensions[frm.doc.company]) {
|
fields.push(df.fieldname);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let default_dimension = default_dimensions[frm.doc.company][dimension['fieldname']];
|
frm.set_query(dimension, parentfield, function(doc, cdt, cdn) {
|
||||||
|
let row = locals[cdt][cdn];
|
||||||
|
return erpnext.queries.get_filtered_dimensions(row, fields, dimension, doc.company);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
if(default_dimension) {
|
setup_account_filters(frm, dimension, fields) {
|
||||||
|
frm.set_query(dimension, function(doc) {
|
||||||
|
return erpnext.queries.get_filtered_dimensions(doc, fields, dimension, doc.company);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
update_dimension(frm, doctype) {
|
||||||
|
if (this.accounting_dimensions) {
|
||||||
|
this.accounting_dimensions.forEach((dimension) => {
|
||||||
|
if (frm.is_new()) {
|
||||||
|
if (frm.doc.company && Object.keys(this.default_dimensions || {}).length > 0
|
||||||
|
&& this.default_dimensions[frm.doc.company]) {
|
||||||
|
|
||||||
|
let default_dimension = this.default_dimensions[frm.doc.company][dimension['fieldname']];
|
||||||
|
|
||||||
|
if (default_dimension) {
|
||||||
if (frappe.meta.has_field(doctype, dimension['fieldname'])) {
|
if (frappe.meta.has_field(doctype, dimension['fieldname'])) {
|
||||||
frm.set_value(dimension['fieldname'], default_dimension);
|
frm.set_value(dimension['fieldname'], default_dimension);
|
||||||
}
|
}
|
||||||
@@ -61,23 +90,14 @@ doctypes_with_dimensions.forEach((doctype) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
});
|
|
||||||
|
|
||||||
child_docs.forEach((doctype) => {
|
copy_dimension_from_first_row(frm, cdt, cdn, fieldname) {
|
||||||
frappe.ui.form.on(doctype, {
|
if (frappe.meta.has_field(frm.doctype, fieldname) && this.accounting_dimensions) {
|
||||||
items_add: function(frm, cdt, cdn) {
|
this.accounting_dimensions.forEach((dimension) => {
|
||||||
erpnext.dimension_filters.forEach((dimension) => {
|
let row = frappe.get_doc(cdt, cdn);
|
||||||
var row = frappe.get_doc(cdt, cdn);
|
frm.script_manager.copy_from_first_row(fieldname, row, [dimension['fieldname']]);
|
||||||
frm.script_manager.copy_from_first_row("items", row, [dimension['fieldname']]);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
accounts_add: function(frm, cdt, cdn) {
|
|
||||||
erpnext.dimension_filters.forEach((dimension) => {
|
|
||||||
var row = frappe.get_doc(cdt, cdn);
|
|
||||||
frm.script_manager.copy_from_first_row("accounts", row, [dimension['fieldname']]);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
};
|
||||||
@@ -7,6 +7,7 @@ cur_frm.add_fetch('customer', 'tax_id', 'tax_id');
|
|||||||
|
|
||||||
frappe.provide("erpnext.stock");
|
frappe.provide("erpnext.stock");
|
||||||
frappe.provide("erpnext.stock.delivery_note");
|
frappe.provide("erpnext.stock.delivery_note");
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
frappe.ui.form.on("Delivery Note", {
|
frappe.ui.form.on("Delivery Note", {
|
||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
@@ -76,7 +77,7 @@ frappe.ui.form.on("Delivery Note", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
print_without_amount: function(frm) {
|
print_without_amount: function(frm) {
|
||||||
@@ -318,6 +319,7 @@ frappe.ui.form.on('Delivery Note', {
|
|||||||
|
|
||||||
company: function(frm) {
|
company: function(frm) {
|
||||||
frm.trigger("unhide_account_head");
|
frm.trigger("unhide_account_head");
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
unhide_account_head: function(frm) {
|
unhide_account_head: function(frm) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
{% include 'erpnext/public/js/controllers/buying.js' %};
|
{% include 'erpnext/public/js/controllers/buying.js' %};
|
||||||
|
|
||||||
frappe.ui.form.on('Material Request', {
|
frappe.ui.form.on('Material Request', {
|
||||||
@@ -66,6 +67,12 @@ frappe.ui.form.on('Material Request', {
|
|||||||
filters: {'company': doc.company}
|
filters: {'company': doc.company}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
|
},
|
||||||
|
|
||||||
|
company: function(frm) {
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
onload_post_render: function(frm) {
|
onload_post_render: function(frm) {
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ frappe.ui.form.on("Purchase Receipt", {
|
|||||||
erpnext.queries.setup_queries(frm, "Warehouse", function() {
|
erpnext.queries.setup_queries(frm, "Warehouse", function() {
|
||||||
return erpnext.queries.warehouse(frm.doc);
|
return erpnext.queries.warehouse(frm.doc);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
@@ -75,6 +77,7 @@ frappe.ui.form.on("Purchase Receipt", {
|
|||||||
|
|
||||||
company: function(frm) {
|
company: function(frm) {
|
||||||
frm.trigger("toggle_display_account_head");
|
frm.trigger("toggle_display_account_head");
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
toggle_display_account_head: function(frm) {
|
toggle_display_account_head: function(frm) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt
|
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
frappe.provide("erpnext.stock");
|
frappe.provide("erpnext.stock");
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
frappe.ui.form.on('Stock Entry', {
|
frappe.ui.form.on('Stock Entry', {
|
||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
@@ -97,6 +98,7 @@ frappe.ui.form.on('Stock Entry', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
frm.add_fetch("bom_no", "inspection_required", "inspection_required");
|
frm.add_fetch("bom_no", "inspection_required", "inspection_required");
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
setup_quality_inspection: function(frm) {
|
setup_quality_inspection: function(frm) {
|
||||||
@@ -312,6 +314,8 @@ frappe.ui.form.on('Stock Entry', {
|
|||||||
frm.set_value("letter_head", company_doc.default_letter_head);
|
frm.set_value("letter_head", company_doc.default_letter_head);
|
||||||
}
|
}
|
||||||
frm.trigger("toggle_display_account_head");
|
frm.trigger("toggle_display_account_head");
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
frappe.provide("erpnext.stock");
|
frappe.provide("erpnext.stock");
|
||||||
|
frappe.provide("erpnext.accounts.dimensions");
|
||||||
|
|
||||||
frappe.ui.form.on("Stock Reconciliation", {
|
frappe.ui.form.on("Stock Reconciliation", {
|
||||||
onload: function(frm) {
|
onload: function(frm) {
|
||||||
@@ -26,6 +27,12 @@ frappe.ui.form.on("Stock Reconciliation", {
|
|||||||
if (!frm.doc.expense_account) {
|
if (!frm.doc.expense_account) {
|
||||||
frm.trigger("set_expense_account");
|
frm.trigger("set_expense_account");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||||
|
},
|
||||||
|
|
||||||
|
company: function(frm) {
|
||||||
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
|
|||||||
Reference in New Issue
Block a user