fix: Add company filters for account
(cherry picked from commit ecca9cb023)
# Conflicts:
# erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
This commit is contained in:
@@ -15,6 +15,17 @@ frappe.ui.form.on('Accounting Dimension', {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
frm.set_query("offsetting_account", "dimension_defaults", function(doc, cdt, cdn) {
|
||||||
|
let d = locals[cdt][cdn];
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
company: d.company,
|
||||||
|
root_type: ["in", ["Asset", "Liability"]],
|
||||||
|
is_group: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (!frm.is_new()) {
|
if (!frm.is_new()) {
|
||||||
frm.add_custom_button(__('Show {0}', [frm.doc.document_type]), function () {
|
frm.add_custom_button(__('Show {0}', [frm.doc.document_type]), function () {
|
||||||
frappe.set_route("List", frm.doc.document_type);
|
frappe.set_route("List", frm.doc.document_type);
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ class AccountingDimension(Document):
|
|||||||
if not self.is_new():
|
if not self.is_new():
|
||||||
self.validate_document_type_change()
|
self.validate_document_type_change()
|
||||||
|
|
||||||
|
self.validate_dimension_defaults()
|
||||||
|
|
||||||
def validate_document_type_change(self):
|
def validate_document_type_change(self):
|
||||||
doctype_before_save = frappe.db.get_value("Accounting Dimension", self.name, "document_type")
|
doctype_before_save = frappe.db.get_value("Accounting Dimension", self.name, "document_type")
|
||||||
if doctype_before_save != self.document_type:
|
if doctype_before_save != self.document_type:
|
||||||
@@ -46,6 +48,14 @@ class AccountingDimension(Document):
|
|||||||
message += _("Please create a new Accounting Dimension if required.")
|
message += _("Please create a new Accounting Dimension if required.")
|
||||||
frappe.throw(message)
|
frappe.throw(message)
|
||||||
|
|
||||||
|
def validate_dimension_defaults(self):
|
||||||
|
companies = []
|
||||||
|
for default in self.get("dimension_defaults"):
|
||||||
|
if default.company not in companies:
|
||||||
|
companies.append(default.company)
|
||||||
|
else:
|
||||||
|
frappe.throw(_("Company {0} is added more than once").format(frappe.bold(default.company)))
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
if frappe.flags.in_test:
|
if frappe.flags.in_test:
|
||||||
make_dimension_in_accounting_doctypes(doc=self)
|
make_dimension_in_accounting_doctypes(doc=self)
|
||||||
|
|||||||
@@ -1769,10 +1769,10 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
pi.submit()
|
pi.submit()
|
||||||
|
|
||||||
expected_gle = [
|
expected_gle = [
|
||||||
["_Test Account Cost for Goods Sold - _TC", 1000, 0.0, nowdate(), {"branch": branch2.branch}],
|
["_Test Account Cost for Goods Sold - _TC", 1000, 0.0, nowdate(), branch2.branch],
|
||||||
["Creditors - _TC", 0.0, 1000, nowdate(), {"branch": branch1.branch}],
|
["Creditors - _TC", 0.0, 1000, nowdate(), branch1.branch],
|
||||||
["Offsetting - _TC", 1000, 0.0, nowdate(), {"branch": branch1.branch}],
|
["Offsetting - _TC", 1000, 0.0, nowdate(), branch1.branch],
|
||||||
["Offsetting - _TC", 0.0, 1000, nowdate(), {"branch": branch2.branch}],
|
["Offsetting - _TC", 0.0, 1000, nowdate(), branch2.branch],
|
||||||
]
|
]
|
||||||
|
|
||||||
check_gl_entries(
|
check_gl_entries(
|
||||||
@@ -1781,7 +1781,7 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
expected_gle,
|
expected_gle,
|
||||||
nowdate(),
|
nowdate(),
|
||||||
voucher_type="Purchase Invoice",
|
voucher_type="Purchase Invoice",
|
||||||
check_acc_dimensions=True,
|
additional_columns=["branch"],
|
||||||
)
|
)
|
||||||
clear_dimension_defaults("Branch")
|
clear_dimension_defaults("Branch")
|
||||||
disable_dimension()
|
disable_dimension()
|
||||||
@@ -1804,7 +1804,7 @@ def check_gl_entries(
|
|||||||
expected_gle,
|
expected_gle,
|
||||||
posting_date,
|
posting_date,
|
||||||
voucher_type="Purchase Invoice",
|
voucher_type="Purchase Invoice",
|
||||||
check_acc_dimensions=False,
|
additional_columns=None,
|
||||||
):
|
):
|
||||||
gl = frappe.qb.DocType("GL Entry")
|
gl = frappe.qb.DocType("GL Entry")
|
||||||
query = (
|
query = (
|
||||||
@@ -1869,10 +1869,18 @@ def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
|
|||||||
as_dict=1,
|
as_dict=1,
|
||||||
)
|
)
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
|
<<<<<<< HEAD
|
||||||
=======
|
=======
|
||||||
if check_acc_dimensions:
|
if check_acc_dimensions:
|
||||||
for col in list(expected_gle[0][4].keys()):
|
for col in list(expected_gle[0][4].keys()):
|
||||||
query = query.select(col)
|
query = query.select(col)
|
||||||
|
=======
|
||||||
|
|
||||||
|
if additional_columns:
|
||||||
|
for col in additional_columns:
|
||||||
|
query = query.select(gl[col])
|
||||||
|
|
||||||
|
>>>>>>> ecca9cb023 (fix: Add company filters for account)
|
||||||
gl_entries = query.run(as_dict=True)
|
gl_entries = query.run(as_dict=True)
|
||||||
>>>>>>> 77deac4fb9 (test: PI offsetting entry for accounting dimension)
|
>>>>>>> 77deac4fb9 (test: PI offsetting entry for accounting dimension)
|
||||||
|
|
||||||
@@ -1881,9 +1889,12 @@ def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
|
|||||||
doc.assertEqual(expected_gle[i][1], gle.debit)
|
doc.assertEqual(expected_gle[i][1], gle.debit)
|
||||||
doc.assertEqual(expected_gle[i][2], gle.credit)
|
doc.assertEqual(expected_gle[i][2], gle.credit)
|
||||||
doc.assertEqual(getdate(expected_gle[i][3]), gle.posting_date)
|
doc.assertEqual(getdate(expected_gle[i][3]), gle.posting_date)
|
||||||
if check_acc_dimensions:
|
|
||||||
for acc_dimension in expected_gle[i][4]:
|
if additional_columns:
|
||||||
doc.assertEqual(expected_gle[i][4][acc_dimension], gle[acc_dimension])
|
j = 4
|
||||||
|
for col in additional_columns:
|
||||||
|
doc.assertEqual(expected_gle[i][j], gle[col])
|
||||||
|
j += 1
|
||||||
|
|
||||||
|
|
||||||
def create_tax_witholding_category(category_name, company, account):
|
def create_tax_witholding_category(category_name, company, account):
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ def make_gl_entries(
|
|||||||
from_repost=False,
|
from_repost=False,
|
||||||
):
|
):
|
||||||
if gl_map:
|
if gl_map:
|
||||||
make_acc_dimensions_offsetting_entry(gl_map)
|
|
||||||
if not cancel:
|
if not cancel:
|
||||||
|
make_acc_dimensions_offsetting_entry(gl_map)
|
||||||
validate_accounting_period(gl_map)
|
validate_accounting_period(gl_map)
|
||||||
validate_disabled_accounts(gl_map)
|
validate_disabled_accounts(gl_map)
|
||||||
gl_map = process_gl_map(gl_map, merge_entries)
|
gl_map = process_gl_map(gl_map, merge_entries)
|
||||||
@@ -61,6 +61,7 @@ def make_acc_dimensions_offsetting_entry(gl_map):
|
|||||||
return
|
return
|
||||||
|
|
||||||
offsetting_entries = []
|
offsetting_entries = []
|
||||||
|
|
||||||
for gle in gl_map:
|
for gle in gl_map:
|
||||||
for dimension in accounting_dimensions_to_offset:
|
for dimension in accounting_dimensions_to_offset:
|
||||||
offsetting_entry = gle.copy()
|
offsetting_entry = gle.copy()
|
||||||
@@ -79,12 +80,14 @@ def make_acc_dimensions_offsetting_entry(gl_map):
|
|||||||
)
|
)
|
||||||
offsetting_entry["against_voucher_type"] = None
|
offsetting_entry["against_voucher_type"] = None
|
||||||
offsetting_entries.append(offsetting_entry)
|
offsetting_entries.append(offsetting_entry)
|
||||||
|
|
||||||
gl_map += offsetting_entries
|
gl_map += offsetting_entries
|
||||||
|
|
||||||
|
|
||||||
def get_accounting_dimensions_for_offsetting_entry(gl_map, company):
|
def get_accounting_dimensions_for_offsetting_entry(gl_map, company):
|
||||||
acc_dimension = frappe.qb.DocType("Accounting Dimension")
|
acc_dimension = frappe.qb.DocType("Accounting Dimension")
|
||||||
dimension_detail = frappe.qb.DocType("Accounting Dimension Detail")
|
dimension_detail = frappe.qb.DocType("Accounting Dimension Detail")
|
||||||
|
|
||||||
acc_dimensions = (
|
acc_dimensions = (
|
||||||
frappe.qb.from_(acc_dimension)
|
frappe.qb.from_(acc_dimension)
|
||||||
.inner_join(dimension_detail)
|
.inner_join(dimension_detail)
|
||||||
@@ -96,11 +99,13 @@ def get_accounting_dimensions_for_offsetting_entry(gl_map, company):
|
|||||||
& (dimension_detail.automatically_post_balancing_accounting_entry == 1)
|
& (dimension_detail.automatically_post_balancing_accounting_entry == 1)
|
||||||
)
|
)
|
||||||
).run(as_dict=True)
|
).run(as_dict=True)
|
||||||
|
|
||||||
accounting_dimensions_to_offset = []
|
accounting_dimensions_to_offset = []
|
||||||
for acc_dimension in acc_dimensions:
|
for acc_dimension in acc_dimensions:
|
||||||
values = set([entry.get(acc_dimension.fieldname) for entry in gl_map])
|
values = set([entry.get(acc_dimension.fieldname) for entry in gl_map])
|
||||||
if len(values) > 1:
|
if len(values) > 1:
|
||||||
accounting_dimensions_to_offset.append(acc_dimension)
|
accounting_dimensions_to_offset.append(acc_dimension)
|
||||||
|
|
||||||
return accounting_dimensions_to_offset
|
return accounting_dimensions_to_offset
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ def create_accounting_dimension(**args):
|
|||||||
accounting_dimension = frappe.new_doc("Accounting Dimension")
|
accounting_dimension = frappe.new_doc("Accounting Dimension")
|
||||||
accounting_dimension.document_type = document_type
|
accounting_dimension.document_type = document_type
|
||||||
accounting_dimension.insert()
|
accounting_dimension.insert()
|
||||||
accounting_dimension.save()
|
|
||||||
|
accounting_dimension.set("dimension_defaults", [])
|
||||||
accounting_dimension.append(
|
accounting_dimension.append(
|
||||||
"dimension_defaults",
|
"dimension_defaults",
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user