mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-16 13:32:13 +00:00
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:
@@ -141,6 +141,7 @@ class JournalEntry(AccountsController):
|
|||||||
self.validate_empty_accounts_table()
|
self.validate_empty_accounts_table()
|
||||||
self.validate_inter_company_accounts()
|
self.validate_inter_company_accounts()
|
||||||
self.validate_depr_entry_voucher_type()
|
self.validate_depr_entry_voucher_type()
|
||||||
|
self.validate_company_in_accounting_dimension()
|
||||||
self.validate_advance_accounts()
|
self.validate_advance_accounts()
|
||||||
|
|
||||||
if self.docstatus == 0:
|
if self.docstatus == 0:
|
||||||
|
|||||||
@@ -591,13 +591,14 @@ def make_journal_entry(
|
|||||||
save=True,
|
save=True,
|
||||||
submit=False,
|
submit=False,
|
||||||
project=None,
|
project=None,
|
||||||
|
company=None,
|
||||||
):
|
):
|
||||||
if not cost_center:
|
if not cost_center:
|
||||||
cost_center = "_Test Cost Center - _TC"
|
cost_center = "_Test Cost Center - _TC"
|
||||||
|
|
||||||
jv = frappe.new_doc("Journal Entry")
|
jv = frappe.new_doc("Journal Entry")
|
||||||
jv.posting_date = posting_date or nowdate()
|
jv.posting_date = posting_date or nowdate()
|
||||||
jv.company = "_Test Company"
|
jv.company = company or "_Test Company"
|
||||||
jv.user_remark = "test"
|
jv.user_remark = "test"
|
||||||
jv.multi_currency = 1
|
jv.multi_currency = 1
|
||||||
jv.set(
|
jv.set(
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
account1="Cash - TPC",
|
account1="Cash - TPC",
|
||||||
account2="Sales - TPC",
|
account2="Sales - TPC",
|
||||||
cost_center=cost_center,
|
cost_center=cost_center,
|
||||||
|
company=company,
|
||||||
save=False,
|
save=False,
|
||||||
)
|
)
|
||||||
jv1.company = company
|
jv1.company = company
|
||||||
@@ -39,6 +40,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
account1="Cost of Goods Sold - TPC",
|
account1="Cost of Goods Sold - TPC",
|
||||||
account2="Cash - TPC",
|
account2="Cash - TPC",
|
||||||
cost_center=cost_center,
|
cost_center=cost_center,
|
||||||
|
company=company,
|
||||||
save=False,
|
save=False,
|
||||||
)
|
)
|
||||||
jv2.company = company
|
jv2.company = company
|
||||||
@@ -156,6 +158,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
amount=400,
|
amount=400,
|
||||||
cost_center=cost_center,
|
cost_center=cost_center,
|
||||||
posting_date="2021-03-15",
|
posting_date="2021-03-15",
|
||||||
|
company=company,
|
||||||
)
|
)
|
||||||
jv.company = company
|
jv.company = company
|
||||||
jv.finance_book = create_finance_book().name
|
jv.finance_book = create_finance_book().name
|
||||||
@@ -198,6 +201,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
account1="Cash - TPC",
|
account1="Cash - TPC",
|
||||||
account2="Sales - TPC",
|
account2="Sales - TPC",
|
||||||
cost_center=cost_center,
|
cost_center=cost_center,
|
||||||
|
company=company,
|
||||||
save=False,
|
save=False,
|
||||||
)
|
)
|
||||||
jv1.company = company
|
jv1.company = company
|
||||||
@@ -220,6 +224,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
account1="Cash - TPC",
|
account1="Cash - TPC",
|
||||||
account2="Sales - TPC",
|
account2="Sales - TPC",
|
||||||
cost_center=cost_center1,
|
cost_center=cost_center1,
|
||||||
|
company=company,
|
||||||
save=False,
|
save=False,
|
||||||
)
|
)
|
||||||
jv1.company = company
|
jv1.company = company
|
||||||
@@ -232,6 +237,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
account1="Cash - TPC",
|
account1="Cash - TPC",
|
||||||
account2="Sales - TPC",
|
account2="Sales - TPC",
|
||||||
cost_center=cost_center2,
|
cost_center=cost_center2,
|
||||||
|
company=company,
|
||||||
save=False,
|
save=False,
|
||||||
)
|
)
|
||||||
jv2.company = company
|
jv2.company = company
|
||||||
@@ -261,6 +267,7 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
account1="Cash - TPC",
|
account1="Cash - TPC",
|
||||||
account2="Sales - TPC",
|
account2="Sales - TPC",
|
||||||
cost_center=cost_center2,
|
cost_center=cost_center2,
|
||||||
|
company=company,
|
||||||
save=False,
|
save=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -920,6 +920,7 @@ class TestPurchaseOrder(FrappeTestCase):
|
|||||||
automatically_fetch_payment_terms(enable=0)
|
automatically_fetch_payment_terms(enable=0)
|
||||||
|
|
||||||
def test_internal_transfer_flow(self):
|
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 (
|
from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
|
||||||
make_inter_company_purchase_invoice,
|
make_inter_company_purchase_invoice,
|
||||||
)
|
)
|
||||||
@@ -935,8 +936,16 @@ class TestPurchaseOrder(FrappeTestCase):
|
|||||||
prepare_data_for_internal_transfer()
|
prepare_data_for_internal_transfer()
|
||||||
supplier = "_Test Internal Supplier 2"
|
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(
|
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(
|
po = create_purchase_order(
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ class AccountsController(TransactionBase):
|
|||||||
.where(doc_field.fieldname == "company")
|
.where(doc_field.fieldname == "company")
|
||||||
).run(as_list=True)
|
).run(as_list=True)
|
||||||
|
|
||||||
dimension_list = sum(dimension_list, ["Project"])
|
dimension_list = sum(dimension_list, ["Project", "Cost Center"])
|
||||||
self.validate_company(dimension_list)
|
self.validate_company(dimension_list)
|
||||||
|
|
||||||
for child in self.get_all_children() or []:
|
for child in self.get_all_children() or []:
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from frappe.tests.utils import FrappeTestCase
|
|||||||
from frappe.utils import add_days, cstr, flt, getdate, nowdate, nowtime, today
|
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.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.accounts.utils import get_balance_on
|
||||||
from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
|
from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
|
||||||
from erpnext.selling.doctype.sales_order.test_sales_order import (
|
from erpnext.selling.doctype.sales_order.test_sales_order import (
|
||||||
@@ -1400,6 +1401,7 @@ class TestDeliveryNote(FrappeTestCase):
|
|||||||
warehouse = "Stores - TCP1"
|
warehouse = "Stores - TCP1"
|
||||||
target = "Finished Goods - TCP1"
|
target = "Finished Goods - TCP1"
|
||||||
customer = create_internal_customer(represents_company=company)
|
customer = create_internal_customer(represents_company=company)
|
||||||
|
create_cost_center(cost_center_name="_Test Cost Center", company=company)
|
||||||
|
|
||||||
# average rate = 128.015
|
# average rate = 128.015
|
||||||
rates = [101.45, 150.46, 138.25, 121.9]
|
rates = [101.45, 150.46, 138.25, 121.9]
|
||||||
@@ -1414,6 +1416,7 @@ class TestDeliveryNote(FrappeTestCase):
|
|||||||
qty=4,
|
qty=4,
|
||||||
warehouse=warehouse,
|
warehouse=warehouse,
|
||||||
target_warehouse=target,
|
target_warehouse=target,
|
||||||
|
cost_center="_Test Cost Center - TCP1",
|
||||||
)
|
)
|
||||||
self.assertFalse(frappe.db.exists("GL Entry", {"voucher_no": dn.name, "voucher_type": dn.doctype}))
|
self.assertFalse(frappe.db.exists("GL Entry", {"voucher_no": dn.name, "voucher_type": dn.doctype}))
|
||||||
|
|
||||||
|
|||||||
@@ -1195,6 +1195,7 @@ def create_delivery_note(source_name, target_doc=None):
|
|||||||
|
|
||||||
def create_dn_wo_so(pick_list):
|
def create_dn_wo_so(pick_list):
|
||||||
delivery_note = frappe.new_doc("Delivery Note")
|
delivery_note = frappe.new_doc("Delivery Note")
|
||||||
|
delivery_note.company = pick_list.company
|
||||||
|
|
||||||
item_table_mapper_without_so = {
|
item_table_mapper_without_so = {
|
||||||
"doctype": "Delivery Note Item",
|
"doctype": "Delivery Note Item",
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ class TestSerialNo(FrappeTestCase):
|
|||||||
serial_no=[serial_nos[0]],
|
serial_no=[serial_nos[0]],
|
||||||
company="_Test Company 1",
|
company="_Test Company 1",
|
||||||
warehouse=wh,
|
warehouse=wh,
|
||||||
|
cost_center="_Test Company 1 - _TC1",
|
||||||
)
|
)
|
||||||
sn_doc.reload()
|
sn_doc.reload()
|
||||||
|
|
||||||
@@ -154,6 +155,7 @@ class TestSerialNo(FrappeTestCase):
|
|||||||
serial_no=[serial_nos[0]],
|
serial_no=[serial_nos[0]],
|
||||||
company="_Test Company 1",
|
company="_Test Company 1",
|
||||||
warehouse=wh,
|
warehouse=wh,
|
||||||
|
cost_center="_Test Company 1 - _TC1",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Delivery from second company
|
# Delivery from second company
|
||||||
@@ -163,6 +165,7 @@ class TestSerialNo(FrappeTestCase):
|
|||||||
serial_no=[serial_nos[0]],
|
serial_no=[serial_nos[0]],
|
||||||
company="_Test Company 1",
|
company="_Test Company 1",
|
||||||
warehouse=wh,
|
warehouse=wh,
|
||||||
|
cost_center="_Test Company 1 - _TC1",
|
||||||
)
|
)
|
||||||
sn_doc.reload()
|
sn_doc.reload()
|
||||||
|
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ class StockEntry(StockController):
|
|||||||
self.validate_bom()
|
self.validate_bom()
|
||||||
self.set_process_loss_qty()
|
self.set_process_loss_qty()
|
||||||
self.validate_purchase_order()
|
self.validate_purchase_order()
|
||||||
|
self.validate_company_in_accounting_dimension()
|
||||||
|
|
||||||
if self.purpose in ("Manufacture", "Repack"):
|
if self.purpose in ("Manufacture", "Repack"):
|
||||||
self.mark_finished_and_scrap_items()
|
self.mark_finished_and_scrap_items()
|
||||||
|
|||||||
Reference in New Issue
Block a user