From 5398cf8f227e740dc035eca4d1f44f21109dea1d Mon Sep 17 00:00:00 2001 From: Tunde Akinyanmi Date: Fri, 9 Dec 2022 10:14:18 +0100 Subject: [PATCH 1/5] 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 (cherry picked from commit 97ddfcfc7ca272922203d5423a21e777c62477d1) --- 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 6f0b381fc16..5cd65451870 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 78e2370878f..0013c95032f 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 1b94200ab73ae1ba446b04d7ee903d652680c792 Mon Sep 17 00:00:00 2001 From: Tunde Akinyanmi Date: Fri, 9 Dec 2022 12:39:03 +0100 Subject: [PATCH 2/5] test: ensure test case sets Selling Settings (cherry picked from commit d193a14b8f8e39367bb26e6595283ef5aa545dcc) --- 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 5cd65451870..b3c21c46ed1 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 5d410f114a92b6e811033213f54813d9cc3eb7d7 Mon Sep 17 00:00:00 2001 From: Tunde Akinyanmi Date: Fri, 9 Dec 2022 14:33:54 +0100 Subject: [PATCH 3/5] test: refactor test case (cherry picked from commit 71aa8c5e1c8f9ac71fc3a5a8246f8a15f896a57d) --- 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 b3c21c46ed1..b151dd5e79c 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 From 416d17820944e926a0ac336f4f7748baebfbe5e7 Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Fri, 9 Dec 2022 22:41:43 +0530 Subject: [PATCH 4/5] fix: `Material Request` reference in internal `Sales Order` (cherry picked from commit 78b438f6cf952829cbac907203f0f31584add668) --- erpnext/selling/doctype/sales_order/sales_order_dashboard.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/doctype/sales_order/sales_order_dashboard.py b/erpnext/selling/doctype/sales_order/sales_order_dashboard.py index ace2e29c2b4..5c4b57813d3 100644 --- a/erpnext/selling/doctype/sales_order/sales_order_dashboard.py +++ b/erpnext/selling/doctype/sales_order/sales_order_dashboard.py @@ -12,7 +12,10 @@ def get_data(): "Auto Repeat": "reference_document", "Maintenance Visit": "prevdoc_docname", }, - "internal_links": {"Quotation": ["items", "prevdoc_docname"]}, + "internal_links": { + "Quotation": ["items", "prevdoc_docname"], + "Material Request": ["items", "material_request"], + }, "transactions": [ { "label": _("Fulfillment"), From 436e93c129551af187b62e6af7f216b09a46af39 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 12 Dec 2022 20:15:59 +0530 Subject: [PATCH 5/5] fix: incorrect balance on parent company due to key mismatch (cherry picked from commit 7b3316dc3175bcdd6c2c592d9abdb13ab477f015) --- .../consolidated_financial_statement.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py index 330e442a808..6c8f4bb6fe9 100644 --- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py +++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py @@ -533,12 +533,13 @@ def get_accounts(root_type, companies): ], filters={"company": company, "root_type": root_type}, ): - if account.account_name not in added_accounts: + if account.account_number: + account_key = account.account_number + "-" + account.account_name + else: + account_key = account.account_name + + if account_key not in added_accounts: accounts.append(account) - if account.account_number: - account_key = account.account_number + "-" + account.account_name - else: - account_key = account.account_name added_accounts.append(account_key) return accounts