[UI Test] Buying module - Multiple tests for Purchase orders (#10414)

* Extended timeout to avoid rare failures

* Get purchase orders with discount on grand total

* Get purchase orders with discount on individual items

* Get purchase orders and calculate taxes

* Added paths
diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js
index 4226880..940f36f 100644
--- a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js
@@ -45,7 +45,7 @@
 		},
 
 		() => cur_frm.print_doc(),
-		() => frappe.timeout(1),
+		() => frappe.timeout(2),
 		() => {
 			assert.ok($('.btn-print-print').is(':visible'), "Print Format Available");
 			assert.ok($('div > div:nth-child(5) > div > div > table > tbody > tr > td:nth-child(4) > div').text().includes('Test Product 4'), "Print Preview Works");
diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_discount_on_grand_total.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_discount_on_grand_total.js
new file mode 100644
index 0000000..54fa777
--- /dev/null
+++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_discount_on_grand_total.js
@@ -0,0 +1,48 @@
+QUnit.module('Buying');
+
+QUnit.test("test: purchase order with discount on grand total", function(assert) {
+	assert.expect(4);
+	let done = assert.async();
+
+	frappe.run_serially([
+		() => {
+			return frappe.tests.make('Purchase Order', [
+				{supplier: 'Test Supplier'},
+				{company: 'Wind Power LLC'},
+				{is_subcontracted: 'No'},
+				{buying_price_list: 'Test-Buying-EUR'},
+				{currency: 'EUR'},
+				{items: [
+					[
+						{"item_code": 'Test Product 4'},
+						{"qty": 5},
+						{"uom": 'Unit'},
+						{"rate": 500 },
+						{"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)},
+						{"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
+						{"warehouse": 'Stores - WP'}
+					]
+				]},
+				{apply_discount_on: 'Grand Total'},
+				{additional_discount_percentage: 10}
+			]);
+		},
+
+		() => frappe.timeout(1),
+
+		() => {
+			assert.ok(cur_frm.doc.supplier_name == 'Test Supplier', "Supplier name correct");
+			assert.ok(cur_frm.doc.items[0].rate == 500, "Rate correct");
+			// Calculate total
+			assert.ok(cur_frm.doc.total == 2500, "Total correct");
+			// Calculate grand total after discount
+			assert.ok(cur_frm.doc.grand_total == 2250, "Grand total correct");
+		},
+
+		() => frappe.tests.click_button('Submit'),
+		() => frappe.tests.click_button('Yes'),
+		() => frappe.timeout(0.3),
+
+		() => done()
+	]);
+});
\ No newline at end of file
diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_item_wise_discount.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_item_wise_discount.js
new file mode 100644
index 0000000..4ea8b97
--- /dev/null
+++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_item_wise_discount.js
@@ -0,0 +1,45 @@
+QUnit.module('Buying');
+
+QUnit.test("test: purchase order with item wise discount", function(assert) {
+	assert.expect(4);
+	let done = assert.async();
+
+	frappe.run_serially([
+		() => {
+			return frappe.tests.make('Purchase Order', [
+				{supplier: 'Test Supplier'},
+				{company: 'Wind Power LLC'},
+				{is_subcontracted: 'No'},
+				{buying_price_list: 'Test-Buying-EUR'},
+				{currency: 'EUR'},
+				{items: [
+					[
+						{"item_code": 'Test Product 4'},
+						{"qty": 5},
+						{"uom": 'Unit'},
+						{"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)},
+						{"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
+						{"warehouse": 'Stores - WP'},
+						{"discount_percentage": 20}
+					]
+				]}
+			]);
+		},
+
+		() => frappe.timeout(1),
+
+		() => {
+			assert.ok(cur_frm.doc.supplier_name == 'Test Supplier', "Supplier name correct");
+			assert.ok(cur_frm.doc.items[0].discount_percentage == 20, "Discount correct");
+			// Calculate totals after discount
+			assert.ok(cur_frm.doc.total == 2000, "Total correct");
+			assert.ok(cur_frm.doc.grand_total == 2000, "Grand total correct");
+		},
+
+		() => frappe.tests.click_button('Submit'),
+		() => frappe.tests.click_button('Yes'),
+		() => frappe.timeout(0.3),
+
+		() => done()
+	]);
+});
\ No newline at end of file
diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js
new file mode 100644
index 0000000..b5f59ad
--- /dev/null
+++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js
@@ -0,0 +1,44 @@
+QUnit.module('Buying');
+
+QUnit.test("test: purchase order with taxes and charges", function(assert) {
+	assert.expect(3);
+	let done = assert.async();
+
+	frappe.run_serially([
+		() => {
+			return frappe.tests.make('Purchase Order', [
+				{supplier: 'Test Supplier'},
+				{company: 'Wind Power LLC'},
+				{is_subcontracted: 'No'},
+				{buying_price_list: 'Test-Buying-USD'},
+				{currency: 'USD'},
+				{items: [
+					[
+						{"item_code": 'Test Product 4'},
+						{"qty": 5},
+						{"uom": 'Unit'},
+						{"rate": 500 },
+						{"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)},
+						{"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)},
+						{"warehouse": 'Stores - WP'}
+					]
+				]},
+
+				{taxes_and_charges: 'TEST In State GST'}
+			]);
+		},
+
+		() => {
+			// Check taxes and calculate grand total
+			assert.ok(cur_frm.doc.taxes[1].account_head=='SGST - '+frappe.get_abbr(frappe.defaults.get_default('Company')), "Account Head abbr correct");
+			assert.ok(cur_frm.doc.total_taxes_and_charges == 225, "Taxes and charges correct");
+			assert.ok(cur_frm.doc.grand_total == 2725, "Grand total correct");
+		},
+
+		() => frappe.timeout(0.3),
+		() => frappe.tests.click_button('Submit'),
+		() => frappe.tests.click_button('Yes'),
+		() => frappe.timeout(0.3),
+		() => done()
+	]);
+});
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation.js
index 81e512b..8404cb5 100644
--- a/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation.js
+++ b/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation.js
@@ -46,7 +46,7 @@
 		},
 
 		() => cur_frm.print_doc(),
-		() => frappe.timeout(1),
+		() => frappe.timeout(2),
 		() => {
 			assert.ok($('.btn-print-print').is(':visible'), "Print Format Available");
 			assert.ok($("table > tbody > tr > td:nth-child(3) > div").text().includes("Test Product 4"), "Print Preview Works As Expected");
diff --git a/erpnext/tests/ui/tests.txt b/erpnext/tests/ui/tests.txt
index c5d450a..86b6a3a 100644
--- a/erpnext/tests/ui/tests.txt
+++ b/erpnext/tests/ui/tests.txt
@@ -87,4 +87,7 @@
 erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation_for_item_wise_discount.js
 erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js
 erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_multi_uom.js
-erpnext/buying/doctype/purchase_order/tests/test_purchase_order_get_items.js
\ No newline at end of file
+erpnext/buying/doctype/purchase_order/tests/test_purchase_order_get_items.js
+erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_discount_on_grand_total.js
+erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_item_wise_discount.js
+erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js
\ No newline at end of file