@@ -178,6 +178,39 @@ def test_landed_cost_voucher_stock_impact(self):
178178 self .assertEqual (last_sle .qty_after_transaction , last_sle_after_landed_cost .qty_after_transaction )
179179 self .assertEqual (last_sle_after_landed_cost .stock_value - last_sle .stock_value , 50.0 )
180180
181+ def test_lcv_validates_company (self ):
182+ from erpnext .stock .doctype .landed_cost_voucher .landed_cost_voucher import (
183+ IncorrectCompanyValidationError ,
184+ )
185+
186+ company_a = "_Test Company"
187+ company_b = "_Test Company with perpetual inventory"
188+
189+ pr = make_purchase_receipt (
190+ company = company_a ,
191+ warehouse = "Stores - _TC" ,
192+ qty = 1 ,
193+ rate = 100 ,
194+ )
195+
196+ lcv = make_landed_cost_voucher (
197+ company = company_b ,
198+ receipt_document_type = "Purchase Receipt" ,
199+ receipt_document = pr .name ,
200+ charges = 50 ,
201+ do_not_save = True ,
202+ )
203+
204+ self .assertRaises (IncorrectCompanyValidationError , lcv .validate_receipt_documents )
205+ lcv .company = company_a
206+
207+ self .assertRaises (IncorrectCompanyValidationError , lcv .validate_expense_accounts )
208+ lcv .taxes [0 ].expense_account = get_expense_account (company_a )
209+
210+ lcv .save ()
211+ distribute_landed_cost_on_items (lcv )
212+ lcv .submit ()
213+
181214 def test_landed_cost_voucher_for_zero_purchase_rate (self ):
182215 "Test impact of LCV on future stock balances."
183216 from erpnext .stock .doctype .item .test_item import make_item
@@ -1260,6 +1293,7 @@ def make_landed_cost_voucher(**args):
12601293 lcv = frappe .new_doc ("Landed Cost Voucher" )
12611294 lcv .company = args .company or "_Test Company"
12621295 lcv .distribute_charges_based_on = args .distribute_charges_based_on or "Amount"
1296+ expense_account = get_expense_account (args .company or "_Test Company" )
12631297
12641298 lcv .set (
12651299 "purchase_receipts" ,
@@ -1280,7 +1314,7 @@ def make_landed_cost_voucher(**args):
12801314 [
12811315 {
12821316 "description" : "Shipping Charges" ,
1283- "expense_account" : args .expense_account or "Expenses Included In Valuation - TCP1" ,
1317+ "expense_account" : args .expense_account or expense_account ,
12841318 "amount" : args .charges ,
12851319 }
12861320 ],
@@ -1300,6 +1334,7 @@ def create_landed_cost_voucher(receipt_document_type, receipt_document, company,
13001334 lcv = frappe .new_doc ("Landed Cost Voucher" )
13011335 lcv .company = company
13021336 lcv .distribute_charges_based_on = "Amount"
1337+ expense_account = get_expense_account (company )
13031338
13041339 lcv .set (
13051340 "purchase_receipts" ,
@@ -1319,7 +1354,7 @@ def create_landed_cost_voucher(receipt_document_type, receipt_document, company,
13191354 [
13201355 {
13211356 "description" : "Insurance Charges" ,
1322- "expense_account" : "Expenses Included In Valuation - TCP1" ,
1357+ "expense_account" : expense_account ,
13231358 "amount" : charges ,
13241359 }
13251360 ],
@@ -1334,6 +1369,11 @@ def create_landed_cost_voucher(receipt_document_type, receipt_document, company,
13341369 return lcv
13351370
13361371
1372+ def get_expense_account (company ):
1373+ company_abbr = frappe .get_cached_value ("Company" , company , "abbr" )
1374+ return f"Expenses Included In Valuation - { company_abbr } "
1375+
1376+
13371377def distribute_landed_cost_on_items (lcv ):
13381378 based_on = lcv .distribute_charges_based_on .lower ()
13391379 total = sum (flt (d .get (based_on )) for d in lcv .get ("items" ))
0 commit comments