@@ -1017,6 +1017,102 @@ def test_stock_transfer_from_purchase_receipt(self):
10171017
10181018 pr .cancel ()
10191019
1020+ def test_lcv_for_internal_transfer (self ):
1021+ from erpnext .stock .doctype .delivery_note .delivery_note import make_inter_company_purchase_receipt
1022+ from erpnext .stock .doctype .delivery_note .test_delivery_note import create_delivery_note
1023+ from erpnext .stock .doctype .landed_cost_voucher .test_landed_cost_voucher import (
1024+ make_landed_cost_voucher ,
1025+ )
1026+
1027+ prepare_data_for_internal_transfer ()
1028+
1029+ customer = "_Test Internal Customer 2"
1030+ company = "_Test Company with perpetual inventory"
1031+
1032+ item_code = make_item (
1033+ "Test Item For LCV in Internal Transfer" ,
1034+ {"has_batch_no" : 1 , "create_new_batch" : 1 , "batch_naming_series" : "TEST-SBATCH.###" },
1035+ ).name
1036+
1037+ pr1 = make_purchase_receipt (
1038+ item_code = item_code ,
1039+ qty = 10 ,
1040+ rate = 100 ,
1041+ warehouse = "Stores - TCP1" ,
1042+ company = "_Test Company with perpetual inventory" ,
1043+ )
1044+
1045+ dn1 = create_delivery_note (
1046+ item_code = pr1 .items [0 ].item_code ,
1047+ company = company ,
1048+ customer = customer ,
1049+ cost_center = "Main - TCP1" ,
1050+ expense_account = "Cost of Goods Sold - TCP1" ,
1051+ qty = 10 ,
1052+ rate = 500 ,
1053+ warehouse = "Stores - TCP1" ,
1054+ target_warehouse = "Work In Progress - TCP1" ,
1055+ )
1056+
1057+ pr = make_inter_company_purchase_receipt (dn1 .name )
1058+ pr .items [0 ].from_warehouse = "Work In Progress - TCP1"
1059+ pr .items [0 ].warehouse = "Stores - TCP1"
1060+ pr .submit ()
1061+
1062+ sle_entries = frappe .get_all (
1063+ "Stock Ledger Entry" ,
1064+ filters = {"voucher_type" : "Purchase Receipt" , "voucher_no" : pr .name },
1065+ fields = ["serial_and_batch_bundle" , "actual_qty" ],
1066+ )
1067+ self .assertEqual (len (sle_entries ), 2 )
1068+
1069+ inward_sabb = frappe .get_all (
1070+ "Serial and Batch Bundle" ,
1071+ filters = {
1072+ "voucher_type" : "Purchase Receipt" ,
1073+ "voucher_no" : pr .name ,
1074+ "total_qty" : (">" , 0 ),
1075+ "docstatus" : 1 ,
1076+ },
1077+ pluck = "name" ,
1078+ )
1079+ self .assertEqual (len (inward_sabb ), 1 )
1080+
1081+ original_cost = frappe .db .get_value ("Serial and Batch Bundle" , inward_sabb [0 ], "total_amount" )
1082+
1083+ make_landed_cost_voucher (
1084+ company = pr .company ,
1085+ receipt_document_type = "Purchase Receipt" ,
1086+ receipt_document = pr .name ,
1087+ charges = 100 ,
1088+ distribute_charges_based_on = "Qty" ,
1089+ expense_account = "Expenses Included In Valuation - TCP1" ,
1090+ )
1091+
1092+ sle_entries = frappe .get_all (
1093+ "Stock Ledger Entry" ,
1094+ filters = {"voucher_type" : "Purchase Receipt" , "voucher_no" : pr .name , "is_cancelled" : 0 },
1095+ fields = ["serial_and_batch_bundle" , "actual_qty" ],
1096+ )
1097+ self .assertEqual (len (sle_entries ), 2 )
1098+
1099+ new_inward_sabb = frappe .get_all (
1100+ "Serial and Batch Bundle" ,
1101+ filters = {
1102+ "voucher_type" : "Purchase Receipt" ,
1103+ "voucher_no" : pr .name ,
1104+ "total_qty" : (">" , 0 ),
1105+ "docstatus" : 1 ,
1106+ },
1107+ pluck = "name" ,
1108+ )
1109+ self .assertEqual (len (new_inward_sabb ), 1 )
1110+
1111+ new_cost = frappe .db .get_value ("Serial and Batch Bundle" , new_inward_sabb [0 ], "total_amount" )
1112+ self .assertEqual (new_cost , original_cost + 100 )
1113+
1114+ self .assertTrue (new_inward_sabb [0 ] == inward_sabb [0 ])
1115+
10201116 def test_stock_transfer_from_purchase_receipt_with_valuation (self ):
10211117 from erpnext .stock .doctype .delivery_note .delivery_note import make_inter_company_purchase_receipt
10221118 from erpnext .stock .doctype .delivery_note .test_delivery_note import create_delivery_note
0 commit comments