[UI Test] Sales Order with multi currency and tax (#10189)

* [UI Test] Sales Order with multi currency and tax

* [fix]Codacy fixed

* [fix] tests.txt
diff --git a/erpnext/crm/doctype/item/test_item.js b/erpnext/crm/doctype/item/test_item.js
index baaa21f..b48f93a 100644
--- a/erpnext/crm/doctype/item/test_item.js
+++ b/erpnext/crm/doctype/item/test_item.js
@@ -88,7 +88,33 @@
 				{default_warehouse: "Stores - RB"}
 			]
 		),
-
+		() => frappe.tests.make(
+			"Item", [
+				{item_code: "Test Product 4"},
+				{item_group: "Products"},
+				{is_stock_item: 1},
+				{has_batch_no: 1},
+				{create_new_batch: 1},
+				{uoms:
+					[
+						[
+							{uom:"Unit"},
+							{conversion_factor: 10},
+						]
+					]
+				},
+				{taxes:
+					[
+						[
+							{tax_type:"SGST - "+frappe.get_abbr(frappe.defaults.get_default("Company"))},
+							{tax_rate: 0},
+						]
+					]},
+				{has_serial_no: 1},
+				{standard_rate: 100},
+				{opening_stock: 100},
+			]
+		),
 		() => done()
 	]);
 });
diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.js b/erpnext/selling/doctype/sales_order/test_sales_order.js
index 87f0e96..3eceb89 100644
--- a/erpnext/selling/doctype/sales_order/test_sales_order.js
+++ b/erpnext/selling/doctype/sales_order/test_sales_order.js
@@ -1,59 +1,62 @@
-/* eslint-disable */
-// rename this file from _test_[name] to test_[name] to activate
-// and remove above this line
+QUnit.module('Sales Order');
 
-QUnit.test("test: Sales Order", function (assert) {
-	assert.expect(2);
+QUnit.test("test sales order", function(assert) {
+	assert.expect(8);
 	let done = assert.async();
-	let delivery_date = frappe.datetime.add_days(frappe.defaults.get_default("year_end_date"), 1);
-
 	frappe.run_serially([
-		// insert a new Sales Order
 		() => {
 			return frappe.tests.make('Sales Order', [
-				{customer: "Test Customer 1"},
-				{delivery_date: delivery_date},
-				{order_type: 'Sales'},
+				{customer: 'Test Customer 1'},
 				{items: [
 					[
-						{"item_code": "Test Product 1"},
-						{"qty": 5},
-						{'rate': 100},
-					]]
-				}
-			])
+						{'delivery_date': frappe.datetime.add_days(frappe.defaults.get_default("year_end_date"), 1)},
+						{'qty': 5},
+						{'item_code': 'Test Product 4'},
+						{'uom': 'unit'},
+						{'margin_type': 'Percentage'},
+						{'discount_percentage': 10},
+					]
+				]},
+				{customer_address: 'Test1-Billing'},
+				{shipping_address_name: 'Test1-Shipping'},
+				{contact_person: 'Contact 1-Test Customer 1'},
+				{taxes_and_charges: 'TEST In State GST'},
+				{tc_name: 'Test Term 1'},
+				{terms: 'This is Test'}
+			]);
 		},
 		() => {
-			assert.ok(cur_frm.doc.items[0].delivery_date == delivery_date);
-		},
-		() => frappe.timeout(1),
-		// make SO without delivery date in parent, 
-		// parent delivery date should be set based on final delivery date entered in item
-		() => {
-			return frappe.tests.make('Sales Order', [
-				{customer: "Test Customer 1"},
-				{order_type: 'Sales'},
-				{items: [
-					[
-						{"item_code": "Test Product 1"},
-						{"qty": 5},
-						{'rate': 100},
-						{'delivery_date': delivery_date}
-					],
-					[
-						{"item_code": "Test Product 2"},
-						{"qty": 5},
-						{'rate': 100},
-						{'delivery_date': frappe.datetime.add_days(delivery_date, 5)}
-					]]
-				}
-			])
+			return frappe.tests.set_form_values(cur_frm, [
+				{selling_price_list:'Test-Selling-USD'},
+				{currency: 'USD'},
+				{apply_discount_on:'Grand Total'},
+				{additional_discount_percentage:10}
+			]);
 		},
 		() => cur_frm.save(),
+		() => {
+			// get_item_details
+			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 4', "Item name correct");
+			// get tax details
+			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST', "Tax details correct");
+			// get tax account head details
+			assert.ok(cur_frm.doc.taxes[0].account_head=='CGST - '+frappe.get_abbr(frappe.defaults.get_default('Company')), " Account Head abbr correct");
+			// calculate totals
+			assert.ok(cur_frm.doc.items[0].price_list_rate==1000, "Item 1 price_list_rate");
+			assert.ok(cur_frm.doc.total== 4500, "total correct ");
+			assert.ok(cur_frm.doc.rounded_total== 4414.5, "rounded total correct ");
+
+		},
+		() => cur_frm.print_doc(),
 		() => frappe.timeout(1),
 		() => {
-			assert.ok(cur_frm.doc.delivery_date == frappe.datetime.add_days(delivery_date, 5));
+			assert.ok($('.btn-print-print').is(':visible'), "Print Format Available");
+			assert.ok($(".section-break+ .section-break .column-break:nth-child(1) .data-field:nth-child(1) .value").text().includes("Billing Street 1"), "Print Preview Works As Expected");
 		},
+		() => cur_frm.print_doc(),
+		() => 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/tests/ui/tests.txt b/erpnext/tests/ui/tests.txt
index a3ab3c4..2abadec 100644
--- a/erpnext/tests/ui/tests.txt
+++ b/erpnext/tests/ui/tests.txt
@@ -8,6 +8,7 @@
 erpnext/selling/doctype/quotation/test_quotation.js
 erpnext/setup/doctype/company/tests/test_company_production.js
 erpnext/crm/doctype/item/test_item.js
+erpnext/selling/doctype/sales_order/test_sales_order.js
 erpnext/manufacturing/doctype/workstation/test_workstation.js
 erpnext/manufacturing/doctype/operation/test_operation.js
 erpnext/manufacturing/doctype/bom/test_bom.js
@@ -40,5 +41,4 @@
 erpnext/schools/doctype/assessment_criteria_group/test_assessment_criteria_group.js
 erpnext/schools/doctype/assessment_criteria/test_assessment_criteria.js
 erpnext/schools/doctype/course/test_course.js
-erpnext/schools/doctype/program/test_program.js
-erpnext/selling/doctype/sales_order/test_sales_order.js
\ No newline at end of file
+erpnext/schools/doctype/program/test_program.js
\ No newline at end of file