fix: validate accounting dimension company in Journal Entry & Stock Entry (backport #46204) (#46369)

fix: validate accounting dimension company in Journal Entry & Stock Entry (#46204)

* fix: validate accounting dimension company in journal entry and stock entry

* test: update test cases to validate company-based accounting dimension

* fix(test): ensure 'Pick List' company matches 'Delivery Note' to prevent test failures

* chore: remove redundant lines of code

(cherry picked from commit 7b6ebad9e6)

Co-authored-by: Bhavansathru <122002510+Bhavan23@users.noreply.github.com>
This commit is contained in:
mergify[bot]
2025-03-06 18:12:06 +05:30
committed by GitHub
parent 5cc251a172
commit c816f9bd0a
9 changed files with 29 additions and 3 deletions

View File

@@ -141,6 +141,7 @@ class JournalEntry(AccountsController):
self.validate_empty_accounts_table()
self.validate_inter_company_accounts()
self.validate_depr_entry_voucher_type()
self.validate_company_in_accounting_dimension()
self.validate_advance_accounts()
if self.docstatus == 0:

View File

@@ -591,13 +591,14 @@ def make_journal_entry(
save=True,
submit=False,
project=None,
company=None,
):
if not cost_center:
cost_center = "_Test Cost Center - _TC"
jv = frappe.new_doc("Journal Entry")
jv.posting_date = posting_date or nowdate()
jv.company = "_Test Company"
jv.company = company or "_Test Company"
jv.user_remark = "test"
jv.multi_currency = 1
jv.set(

View File

@@ -27,6 +27,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
account1="Cash - TPC",
account2="Sales - TPC",
cost_center=cost_center,
company=company,
save=False,
)
jv1.company = company
@@ -39,6 +40,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
account1="Cost of Goods Sold - TPC",
account2="Cash - TPC",
cost_center=cost_center,
company=company,
save=False,
)
jv2.company = company
@@ -156,6 +158,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
amount=400,
cost_center=cost_center,
posting_date="2021-03-15",
company=company,
)
jv.company = company
jv.finance_book = create_finance_book().name
@@ -198,6 +201,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
account1="Cash - TPC",
account2="Sales - TPC",
cost_center=cost_center,
company=company,
save=False,
)
jv1.company = company
@@ -220,6 +224,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
account1="Cash - TPC",
account2="Sales - TPC",
cost_center=cost_center1,
company=company,
save=False,
)
jv1.company = company
@@ -232,6 +237,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
account1="Cash - TPC",
account2="Sales - TPC",
cost_center=cost_center2,
company=company,
save=False,
)
jv2.company = company
@@ -261,6 +267,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
account1="Cash - TPC",
account2="Sales - TPC",
cost_center=cost_center2,
company=company,
save=False,
)

View File

@@ -920,6 +920,7 @@ class TestPurchaseOrder(FrappeTestCase):
automatically_fetch_payment_terms(enable=0)
def test_internal_transfer_flow(self):
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
make_inter_company_purchase_invoice,
)
@@ -935,8 +936,16 @@ class TestPurchaseOrder(FrappeTestCase):
prepare_data_for_internal_transfer()
supplier = "_Test Internal Supplier 2"
create_cost_center(
cost_center_name="_Test Cost Center for perpetual inventory Account",
company="_Test Company with perpetual inventory",
)
mr = make_material_request(
qty=2, company="_Test Company with perpetual inventory", warehouse="Stores - TCP1"
qty=2,
company="_Test Company with perpetual inventory",
warehouse="Stores - TCP1",
cost_center="_Test Cost Center for perpetual inventory Account - TCP1",
)
po = create_purchase_order(

View File

@@ -419,7 +419,7 @@ class AccountsController(TransactionBase):
.where(doc_field.fieldname == "company")
).run(as_list=True)
dimension_list = sum(dimension_list, ["Project"])
dimension_list = sum(dimension_list, ["Project", "Cost Center"])
self.validate_company(dimension_list)
for child in self.get_all_children() or []:

View File

@@ -10,6 +10,7 @@ from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, cstr, flt, getdate, nowdate, nowtime, today
from erpnext.accounts.doctype.account.test_account import get_inventory_account
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
from erpnext.accounts.utils import get_balance_on
from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
from erpnext.selling.doctype.sales_order.test_sales_order import (
@@ -1400,6 +1401,7 @@ class TestDeliveryNote(FrappeTestCase):
warehouse = "Stores - TCP1"
target = "Finished Goods - TCP1"
customer = create_internal_customer(represents_company=company)
create_cost_center(cost_center_name="_Test Cost Center", company=company)
# average rate = 128.015
rates = [101.45, 150.46, 138.25, 121.9]
@@ -1414,6 +1416,7 @@ class TestDeliveryNote(FrappeTestCase):
qty=4,
warehouse=warehouse,
target_warehouse=target,
cost_center="_Test Cost Center - TCP1",
)
self.assertFalse(frappe.db.exists("GL Entry", {"voucher_no": dn.name, "voucher_type": dn.doctype}))

View File

@@ -1195,6 +1195,7 @@ def create_delivery_note(source_name, target_doc=None):
def create_dn_wo_so(pick_list):
delivery_note = frappe.new_doc("Delivery Note")
delivery_note.company = pick_list.company
item_table_mapper_without_so = {
"doctype": "Delivery Note Item",

View File

@@ -119,6 +119,7 @@ class TestSerialNo(FrappeTestCase):
serial_no=[serial_nos[0]],
company="_Test Company 1",
warehouse=wh,
cost_center="_Test Company 1 - _TC1",
)
sn_doc.reload()
@@ -154,6 +155,7 @@ class TestSerialNo(FrappeTestCase):
serial_no=[serial_nos[0]],
company="_Test Company 1",
warehouse=wh,
cost_center="_Test Company 1 - _TC1",
)
# Delivery from second company
@@ -163,6 +165,7 @@ class TestSerialNo(FrappeTestCase):
serial_no=[serial_nos[0]],
company="_Test Company 1",
warehouse=wh,
cost_center="_Test Company 1 - _TC1",
)
sn_doc.reload()

View File

@@ -209,6 +209,7 @@ class StockEntry(StockController):
self.validate_bom()
self.set_process_loss_qty()
self.validate_purchase_order()
self.validate_company_in_accounting_dimension()
if self.purpose in ("Manufacture", "Repack"):
self.mark_finished_and_scrap_items()