99from frappe .test_runner import make_test_records
1010from erpnext .stock .doctype .stock_reconciliation .test_stock_reconciliation import create_stock_reconciliation
1111from erpnext .manufacturing .doctype .bom_update_tool .bom_update_tool import update_cost
12+ from six import string_types
1213
1314test_records = frappe .get_test_records ('BOM' )
1415
@@ -63,16 +64,8 @@ def test_update_bom_cost_in_all_boms(self):
6364 and item_code='_Test Item 2' and docstatus=1 and parenttype='BOM'""" )
6465 rm_rate = rm_rate [0 ][0 ] if rm_rate else 0
6566
66- # update valuation rate of item '_Test Item 2'
67- warehouse_list = frappe .db .sql_list ("""select warehouse from `tabBin`
68- where item_code='_Test Item 2' and actual_qty > 0""" )
69-
70- if not warehouse_list :
71- warehouse_list .append ("_Test Warehouse - _TC" )
72-
73- for warehouse in warehouse_list :
74- create_stock_reconciliation (item_code = "_Test Item 2" , warehouse = warehouse ,
75- qty = 200 , rate = rm_rate + 10 )
67+ # Reset item valuation rate
68+ reset_item_valuation_rate (item_code = '_Test Item 2' , qty = 200 , rate = rm_rate + 10 )
7669
7770 # update cost of all BOMs based on latest valuation rate
7871 update_cost ()
@@ -96,7 +89,7 @@ def test_bom_cost(self):
9689 self .assertEqual (bom .base_raw_material_cost , 480000 )
9790 self .assertEqual (bom .base_total_cost , 486000 )
9891
99- def test_bom_cost_multi_uom_multi_currency (self ):
92+ def test_bom_cost_multi_uom_multi_currency_based_on_price_list (self ):
10093 frappe .db .set_value ("Price List" , "_Test Price List" , "price_not_uom_dependant" , 1 )
10194 for item_code , rate in (("_Test Item" , 3600 ), ("_Test Item Home Desktop Manufactured" , 3000 )):
10295 frappe .db .sql ("delete from `tabItem Price` where price_list='_Test Price List' and item_code=%s" ,
@@ -131,5 +124,35 @@ def test_bom_cost_multi_uom_multi_currency(self):
131124 self .assertEqual (bom .base_raw_material_cost , 27000 )
132125 self .assertEqual (bom .base_total_cost , 33000 )
133126
127+ def test_bom_cost_multi_uom_based_on_valuation_rate (self ):
128+ bom = frappe .copy_doc (test_records [2 ])
129+ bom .set_rate_of_sub_assembly_item_based_on_bom = 0
130+ bom .rm_cost_as_per = "Valuation Rate"
131+ bom .items [0 ].uom = "_Test UOM 1"
132+ bom .items [0 ].conversion_factor = 6
133+ bom .insert ()
134+
135+ reset_item_valuation_rate (item_code = '_Test Item' , qty = 200 , rate = 200 )
136+
137+ bom .update_cost ()
138+
139+ self .assertEqual (bom .items [0 ].rate , 20 )
140+
134141def get_default_bom (item_code = "_Test FG Item 2" ):
135142 return frappe .db .get_value ("BOM" , {"item" : item_code , "is_active" : 1 , "is_default" : 1 })
143+
144+ def reset_item_valuation_rate (item_code , warehouse_list = None , qty = None , rate = None ):
145+ if warehouse_list and isinstance (warehouse_list , string_types ):
146+ warehouse_list = [warehouse_list ]
147+
148+ if not warehouse_list :
149+ warehouse_list = frappe .db .sql_list ("""
150+ select warehouse from `tabBin`
151+ where item_code=%s and actual_qty > 0
152+ """ , item_code )
153+
154+ if not warehouse_list :
155+ warehouse_list .append ("_Test Warehouse - _TC" )
156+
157+ for warehouse in warehouse_list :
158+ create_stock_reconciliation (item_code = item_code , warehouse = warehouse , qty = qty , rate = rate )
0 commit comments