From 97ddfcfc7ca272922203d5423a21e777c62477d1 Mon Sep 17 00:00:00 2001 From: Tunde Akinyanmi Date: Fri, 9 Dec 2022 10:14:18 +0100 Subject: [PATCH 1/3] fix: Maintain Same Rate Throughout Sales Cycle doesn't work Issue #29976 was partly fixed by #32923 but the problem still persists. The reason is because an incorrect fieldname was passed to the `validate_rate_with_reference_doc` method. This commit fixes it --- erpnext/selling/doctype/quotation/test_quotation.py | 13 +++++++++++++ erpnext/selling/doctype/sales_order/sales_order.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/doctype/quotation/test_quotation.py b/erpnext/selling/doctype/quotation/test_quotation.py index 6f0b381fc1..5cd6545187 100644 --- a/erpnext/selling/doctype/quotation/test_quotation.py +++ b/erpnext/selling/doctype/quotation/test_quotation.py @@ -30,6 +30,19 @@ class TestQuotation(FrappeTestCase): self.assertTrue(sales_order.get("payment_schedule")) + def test_maintain_rate_in_sales_cycle_is_enforced(self): + from erpnext.selling.doctype.quotation.quotation import make_sales_order + + quotation = frappe.copy_doc(test_records[0]) + quotation.transaction_date = nowdate() + quotation.valid_till = add_months(quotation.transaction_date, 1) + quotation.insert() + quotation.submit() + + sales_order = make_sales_order(quotation.name) + sales_order.items[0].rate = 1 + self.assertRaises(frappe.ValidationError, sales_order.save) + def test_make_sales_order_with_different_currency(self): from erpnext.selling.doctype.quotation.quotation import make_sales_order diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 78e2370878..0013c95032 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -194,7 +194,7 @@ class SalesOrder(SellingController): ) if cint(frappe.db.get_single_value("Selling Settings", "maintain_same_sales_rate")): - self.validate_rate_with_reference_doc([["Quotation", "prev_docname", "quotation_item"]]) + self.validate_rate_with_reference_doc([["Quotation", "prevdoc_docname", "quotation_item"]]) def update_enquiry_status(self, prevdoc, flag): enq = frappe.db.sql( From d193a14b8f8e39367bb26e6595283ef5aa545dcc Mon Sep 17 00:00:00 2001 From: Tunde Akinyanmi Date: Fri, 9 Dec 2022 12:39:03 +0100 Subject: [PATCH 2/3] test: ensure test case sets Selling Settings --- erpnext/selling/doctype/quotation/test_quotation.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/erpnext/selling/doctype/quotation/test_quotation.py b/erpnext/selling/doctype/quotation/test_quotation.py index 5cd6545187..b3c21c46ed 100644 --- a/erpnext/selling/doctype/quotation/test_quotation.py +++ b/erpnext/selling/doctype/quotation/test_quotation.py @@ -33,6 +33,11 @@ class TestQuotation(FrappeTestCase): def test_maintain_rate_in_sales_cycle_is_enforced(self): from erpnext.selling.doctype.quotation.quotation import make_sales_order + maintain_rate = frappe.db.get_value( + "Selling Settings", "Selling Settings", "maintain_same_sales_rate" + ) + frappe.db.set_value("Selling Settings", "Selling Settings", "maintain_same_sales_rate", 1) + quotation = frappe.copy_doc(test_records[0]) quotation.transaction_date = nowdate() quotation.valid_till = add_months(quotation.transaction_date, 1) @@ -43,6 +48,10 @@ class TestQuotation(FrappeTestCase): sales_order.items[0].rate = 1 self.assertRaises(frappe.ValidationError, sales_order.save) + frappe.db.set_value( + "Selling Settings", "Selling Settings", "maintain_same_sales_rate", maintain_rate + ) + def test_make_sales_order_with_different_currency(self): from erpnext.selling.doctype.quotation.quotation import make_sales_order From 71aa8c5e1c8f9ac71fc3a5a8246f8a15f896a57d Mon Sep 17 00:00:00 2001 From: Tunde Akinyanmi Date: Fri, 9 Dec 2022 14:33:54 +0100 Subject: [PATCH 3/3] test: refactor test case --- erpnext/selling/doctype/quotation/test_quotation.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/erpnext/selling/doctype/quotation/test_quotation.py b/erpnext/selling/doctype/quotation/test_quotation.py index b3c21c46ed..b151dd5e79 100644 --- a/erpnext/selling/doctype/quotation/test_quotation.py +++ b/erpnext/selling/doctype/quotation/test_quotation.py @@ -33,10 +33,8 @@ class TestQuotation(FrappeTestCase): def test_maintain_rate_in_sales_cycle_is_enforced(self): from erpnext.selling.doctype.quotation.quotation import make_sales_order - maintain_rate = frappe.db.get_value( - "Selling Settings", "Selling Settings", "maintain_same_sales_rate" - ) - frappe.db.set_value("Selling Settings", "Selling Settings", "maintain_same_sales_rate", 1) + maintain_rate = frappe.db.get_single_value("Selling Settings", "maintain_same_sales_rate") + frappe.db.set_single_value("Selling Settings", "maintain_same_sales_rate", 1) quotation = frappe.copy_doc(test_records[0]) quotation.transaction_date = nowdate() @@ -48,9 +46,7 @@ class TestQuotation(FrappeTestCase): sales_order.items[0].rate = 1 self.assertRaises(frappe.ValidationError, sales_order.save) - frappe.db.set_value( - "Selling Settings", "Selling Settings", "maintain_same_sales_rate", maintain_rate - ) + frappe.db.set_single_value("Selling Settings", "maintain_same_sales_rate", maintain_rate) def test_make_sales_order_with_different_currency(self): from erpnext.selling.doctype.quotation.quotation import make_sales_order