From 9b0d4ab4daa8ff3aac0c57a7e26ea4e80aca035a Mon Sep 17 00:00:00 2001 From: Sudharsanan11 Date: Mon, 23 Feb 2026 01:59:25 +0530 Subject: [PATCH] test(stock): add test to validate company for receipts and expense accounts (cherry picked from commit d58171987c4a63de234acfd2c1f2cd53c767ad03) --- .../landed_cost_voucher.py | 6 ++++ .../test_landed_cost_voucher.py | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py index 4dfcb212392..9a478ace4d3 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py @@ -14,6 +14,10 @@ from erpnext.controllers.taxes_and_totals import init_landed_taxes_and_totals from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos +class IncorrectCompanyValidationError(frappe.ValidationError): + pass + + class LandedCostVoucher(Document): # begin: auto-generated types # This code is auto-generated. Do not modify anything in this block. @@ -121,6 +125,7 @@ class LandedCostVoucher(Document): frappe.bold(self.company), ), title=_("Incorrect Company"), + exc=IncorrectCompanyValidationError, ) if d.receipt_document_type == "Purchase Invoice": @@ -169,6 +174,7 @@ class LandedCostVoucher(Document): frappe.bold(self.company), ), title=_("Incorrect Account"), + exc=IncorrectCompanyValidationError, ) def set_total_taxes_and_charges(self): diff --git a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py index a9b36f8661f..a81f92dd369 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py @@ -174,6 +174,39 @@ class TestLandedCostVoucher(FrappeTestCase): self.assertEqual(last_sle.qty_after_transaction, last_sle_after_landed_cost.qty_after_transaction) self.assertEqual(last_sle_after_landed_cost.stock_value - last_sle.stock_value, 50.0) + def test_lcv_validates_company(self): + from erpnext.stock.doctype.landed_cost_voucher.landed_cost_voucher import ( + IncorrectCompanyValidationError, + ) + + company_a = "_Test Company" + company_b = "_Test Company with perpetual inventory" + + pr = make_purchase_receipt( + company=company_a, + warehouse="Stores - _TC", + qty=1, + rate=100, + ) + + lcv = make_landed_cost_voucher( + company=company_b, + receipt_document_type="Purchase Receipt", + receipt_document=pr.name, + charges=50, + do_not_save=True, + ) + + self.assertRaises(IncorrectCompanyValidationError, lcv.validate_receipt_documents) + lcv.company = company_a + + self.assertRaises(IncorrectCompanyValidationError, lcv.validate_expense_accounts) + lcv.taxes[0].expense_account = get_expense_account(company_a) + + lcv.save() + distribute_landed_cost_on_items(lcv) + lcv.submit() + def test_landed_cost_voucher_for_zero_purchase_rate(self): "Test impact of LCV on future stock balances." from erpnext.stock.doctype.item.test_item import make_item