From 35870b3c5ce952d01eb68c89b1ccad867075894f Mon Sep 17 00:00:00 2001 From: vinod-8848digital Date: Thu, 23 Jan 2025 00:34:34 +0530 Subject: [PATCH 1/3] test: TC_B_115 test case shipping rule fixed restricted to country create purchase order and select shipping rule then error should raise --- .../purchase_order/test_purchase_order.py | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index f03189d11611..b4d482a78fa9 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -5213,6 +5213,62 @@ def test_shipping_rule_net_weight_pr_pi_pe_with_gst_TC_B_111(self): self.assertEqual(gl_entries_pe[1].get("account"), "_Test Creditors - _TC") self.assertEqual(gl_entries_pe[1].get("debit"), 1430) + def test_shipping_rule_fixed_restricted_country_po_with_gst_TC_B_115(self): + company = "_Test Company" + warehouse = "Stores - _TC" + supplier = "_Test Supplier 1" + item_code = "test_item_with_fixed_shipping_rule" + gst_hsn_code = "888890" + + # Ensure Item exists + if not frappe.db.exists("Item", item_code): + frappe.get_doc({ + "doctype": "Item", + "item_code": item_code, + "item_name": item_code, + "gst_hsn_code": gst_hsn_code, + "is_stock_item": 1 + }).insert() + + # Create Shipping Rule with Fixed Amount + shipping_rule = frappe.get_doc({ + "doctype": "Shipping Rule", + "company": company, + "label": "test_shipping_rule_restricted_country", + "calculate_based_on": "Fixed", + "shipping_rule_type": "Buying", + "account": "Creditors - _TC", + "cost_center": "Main - _TC", + "shipping_amount": 500, + "countries":[ + { + "country": "Australia" + } + ] + }).insert() + + # Create Purchase Order + po = frappe.get_doc({ + "doctype": "Purchase Order", + "supplier": supplier, + "company": company, + "schedule_date": today(), + "set_warehouse": warehouse, + "items": [ + { + "item_code": item_code, + "qty": 10, + "rate": 100, + "warehouse": warehouse, + } + ], + "taxes_and_charges": "Input GST In-state - _TC", + "shipping_rule": shipping_rule.name + }) + with self.assertRaises(frappe.exceptions.ValidationError) as cm: + po.insert() + self.assertEqual(str(cm.exception), "Shipping rule not applicable for country India in Shipping Address") + def create_po_for_sc_testing(): from erpnext.controllers.tests.test_subcontracting_controller import ( make_bom_for_subcontracted_items, From c9213265178e2b682002325e29e1370841e87409 Mon Sep 17 00:00:00 2001 From: vinod-8848digital Date: Thu, 23 Jan 2025 00:37:24 +0530 Subject: [PATCH 2/3] test: TC_B_116 test case for shipping rule with net total and restricted to country then in the purchase order error should raise --- .../purchase_order/test_purchase_order.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index b4d482a78fa9..47b1e25157ba 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -5269,6 +5269,63 @@ def test_shipping_rule_fixed_restricted_country_po_with_gst_TC_B_115(self): po.insert() self.assertEqual(str(cm.exception), "Shipping rule not applicable for country India in Shipping Address") + def test_shipping_rule_net_total_restricted_country_po_with_gst_TC_B_116(self): + company = "_Test Company" + warehouse = "Stores - _TC" + supplier = "_Test Supplier 1" + item_code = "test_item_with_shipping_rule" + gst_hsn_code = "888890" + + if not frappe.db.exists("Item", item_code): + frappe.get_doc({ + "doctype": "Item", + "item_code": item_code, + "item_name": item_code, + "gst_hsn_code": gst_hsn_code, + "is_stock_item": 1 + }).insert() + + shipping_rule = frappe.get_doc({ + "doctype": "Shipping Rule", + "company": company, + "label": "test_shipping_rule_restricted_country", + "calculate_based_on": "Net Total", + "shipping_rule_type": "Buying", + "account": "Creditors - _TC", + "cost_center": "Main - _TC", + "conditions": [{ + "from_value": 500, + "to_value": 2000, + "shipping_amount": 500 + }], + "countries":[ + { + "country": "Australia" + } + ] + }).insert() + + po = frappe.get_doc({ + "doctype": "Purchase Order", + "supplier": supplier, + "company": company, + "schedule_date": today(), + "set_warehouse": warehouse, + "items": [ + { + "item_code": item_code, + "qty": 10, + "rate": 100, + "warehouse": warehouse, + } + ], + "taxes_and_charges": "Input GST In-state - _TC", + "shipping_rule": shipping_rule.name + }) + with self.assertRaises(frappe.exceptions.ValidationError) as cm: + po.insert() + self.assertEqual(str(cm.exception), "Shipping rule not applicable for country India in Shipping Address") + def create_po_for_sc_testing(): from erpnext.controllers.tests.test_subcontracting_controller import ( make_bom_for_subcontracted_items, From 63b557f0714096628c32fcb2b69d60b20cdf6c6b Mon Sep 17 00:00:00 2001 From: vinod-8848digital Date: Thu, 23 Jan 2025 00:39:43 +0530 Subject: [PATCH 3/3] test: TC_B_117 test case for shipping rule with net weight then create purchase order error should raise --- .../purchase_order/test_purchase_order.py | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index 47b1e25157ba..6eb0fecda438 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -5326,6 +5326,68 @@ def test_shipping_rule_net_total_restricted_country_po_with_gst_TC_B_116(self): po.insert() self.assertEqual(str(cm.exception), "Shipping rule not applicable for country India in Shipping Address") + def test_shipping_rule_net_weight_restricted_country_po_with_gst_TC_B_117(self): + company = "_Test Company" + warehouse = "Stores - _TC" + supplier = "_Test Supplier 1" + item_code = "test_item_with_net_weight_shipping_rule" + gst_hsn_code = "888890" + + # Ensure Item exists with weight specification + if not frappe.db.exists("Item", item_code): + frappe.get_doc({ + "doctype": "Item", + "item_code": item_code, + "item_name": item_code, + "gst_hsn_code": gst_hsn_code, + "is_stock_item": 1, + "weight_per_unit": 2.5, # Weight per unit + "weight_uom": "Kg" + }).insert() + + # Create Shipping Rule with calculation based on Net Weight + shipping_rule = frappe.get_doc({ + "doctype": "Shipping Rule", + "company": company, + "label": "test_shipping_rule_restricted_country", + "calculate_based_on": "Net Weight", + "shipping_rule_type": "Buying", + "account": "Creditors - _TC", + "cost_center": "Main - _TC", + "conditions": [{ + "from_value": 10, # Net weight range + "to_value": 50, + "shipping_amount": 250 + }], + "countries":[ + { + "country": "Australia" + } + ] + }).insert() + + # Create Purchase Order + po = frappe.get_doc({ + "doctype": "Purchase Order", + "supplier": supplier, + "company": company, + "schedule_date": today(), + "set_warehouse": warehouse, + "items": [ + { + "item_code": item_code, + "qty": 10, # Total weight = 10 * 2.5 = 25 Kg + "rate": 100, + "warehouse": warehouse, + } + ], + "taxes_and_charges": "Input GST In-state - _TC", + "shipping_rule": shipping_rule.name + }) + with self.assertRaises(frappe.exceptions.ValidationError) as cm: + po.insert() + self.assertEqual(str(cm.exception), "Shipping rule not applicable for country India in Shipping Address") + def create_po_for_sc_testing(): from erpnext.controllers.tests.test_subcontracting_controller import ( make_bom_for_subcontracted_items,