fix: Flaky test for Report Subcontracted Raw materials to be transferred

This commit is contained in:
marination 2021-06-14 14:51:33 +05:30
parent ad58182395
commit 3b070d1b05

View File

@ -30,42 +30,54 @@ class TestSubcontractedItemToBeTransferred(unittest.TestCase):
po.reload() po.reload()
po_data = [row for row in data if row.get('purchase_order') == po.name] po_data = [row for row in data if row.get('purchase_order') == po.name]
# Alphabetically sort to be certain of order
po_data = sorted(po_data, key = lambda i: i['rm_item_code'])
self.assertEqual(len(po_data), 2) self.assertEqual(len(po_data), 2)
self.assertIn(po_data[0]['rm_item_code'], ['_Test Item', '_Test Item Home Desktop 100']) self.assertEqual(po_data[0]['purchase_order'], po.name)
self.assertIn(po_data[0]['p_qty'], [9, 18])
self.assertIn(po_data[0]['transferred_qty'], [1, 2])
self.assertEqual(data[1]['purchase_order'], po.name) self.assertEqual(po_data[0]['rm_item_code'], '_Test Item')
self.assertIn(data[1]['rm_item_code'], ['_Test Item', '_Test Item Home Desktop 100']) self.assertEqual(po_data[0]['p_qty'], 8)
self.assertIn(data[1]['p_qty'], [9, 18]) self.assertEqual(po_data[0]['transferred_qty'], 2)
self.assertIn(data[1]['transferred_qty'], [1, 2])
self.assertEqual(po_data[1]['rm_item_code'], '_Test Item Home Desktop 100')
self.assertEqual(po_data[1]['p_qty'], 19)
self.assertEqual(po_data[1]['transferred_qty'], 1)
se.cancel() se.cancel()
po.cancel() po.cancel()
def transfer_subcontracted_raw_materials(po): def transfer_subcontracted_raw_materials(po):
# Order of supplied items fetched in PO is flaky
transfer_qty_map = {
'_Test Item': 2,
'_Test Item Home Desktop 100': 1
}
item_1 = po.supplied_items[0].rm_item_code
item_2 = po.supplied_items[1].rm_item_code
rm_item = [ rm_item = [
{ {
'name': po.supplied_items[0].name, 'name': po.supplied_items[0].name,
'item_code': '_Test Item Home Desktop 100', 'item_code': item_1,
'rm_item_code': '_Test Item Home Desktop 100', 'rm_item_code': item_1,
'item_name': '_Test Item Home Desktop 100', 'item_name': item_1,
'qty': 2, 'qty': transfer_qty_map[item_1],
'warehouse': '_Test Warehouse - _TC', 'warehouse': '_Test Warehouse - _TC',
'rate': 100, 'rate': 100,
'amount': 200, 'amount': 100 * transfer_qty_map[item_1],
'stock_uom': 'Nos' 'stock_uom': 'Nos'
}, },
{ {
'name': po.supplied_items[1].name, 'name': po.supplied_items[1].name,
'item_code': '_Test Item', 'item_code': item_2,
'rm_item_code': '_Test Item', 'rm_item_code': item_2,
'item_name': '_Test Item', 'item_name': item_2,
'qty': 1, 'qty': transfer_qty_map[item_2],
'warehouse': '_Test Warehouse - _TC', 'warehouse': '_Test Warehouse - _TC',
'rate': 100, 'rate': 100,
'amount': 100, 'amount': 100 * transfer_qty_map[item_2],
'stock_uom': 'Nos' 'stock_uom': 'Nos'
} }
] ]