From 9aae439b1f773ce634c41fe4d63a57169978b23a Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 10 Jan 2024 22:05:02 +0530 Subject: [PATCH 1/3] fix: date in master document for dictionary condition (cherry picked from commit d96a777edd9cad698b9d9bb90863c1080eacb36f) --- erpnext/accounts/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index af1c3c6d10..8f899c3e76 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -1263,12 +1263,12 @@ def get_autoname_with_number(number_value, doc_title, company): def parse_naming_series_variable(doc, variable): if variable == "FY": if doc: - date = doc.get("posting_date") or doc.get("transaction_date") + date = doc.get("posting_date") or doc.get("transaction_date") or getdate() company = doc.get("company") else: date = getdate() company = None - return get_fiscal_year(date=date, company=company).name + return get_fiscal_year(date=date, company=company)[0] @frappe.whitelist() From 2beb3f87180f91b43e24718d69375022e0d7b4ac Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 10 Jan 2024 22:06:06 +0530 Subject: [PATCH 2/3] test: naming series variable parsing (cherry picked from commit bbdf98a8f0a53b0b4c5a73eb1842401d67314760) --- erpnext/accounts/test/test_utils.py | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/erpnext/accounts/test/test_utils.py b/erpnext/accounts/test/test_utils.py index 3cb5e42e7a..51141d3828 100644 --- a/erpnext/accounts/test/test_utils.py +++ b/erpnext/accounts/test/test_utils.py @@ -23,6 +23,9 @@ class TestUtils(unittest.TestCase): super(TestUtils, cls).setUpClass() make_test_objects("Address", ADDRESS_RECORDS) + def tearDown(self): + frappe.db.rollback() + def test_get_party_shipping_address(self): address = get_party_shipping_address("Customer", "_Test Customer 1") self.assertEqual(address, "_Test Billing Address 2 Title-Billing") @@ -126,6 +129,38 @@ class TestUtils(unittest.TestCase): self.assertEqual(len(payment_entry.references), 1) self.assertEqual(payment_entry.difference_amount, 0) + def test_naming_series_variable_parsing(self): + """ + Tests parsing utility used by Naming Series Variable hook for FY + """ + from frappe.custom.doctype.property_setter.property_setter import make_property_setter + from frappe.utils import nowdate + + from erpnext.accounts.utils import get_fiscal_year + from erpnext.buying.doctype.supplier.test_supplier import create_supplier + + # Configure Supplier Naming in Buying Settings + frappe.db.set_default("supp_master_name", "Auto Name") + + # Configure Autoname in Supplier DocType + make_property_setter( + "Supplier", None, "naming_rule", "Expression", "Data", for_doctype="Doctype" + ) + make_property_setter( + "Supplier", None, "autoname", "SUP-.FY.-.#####", "Data", for_doctype="Doctype" + ) + + # Create Fiscal Year for Current Year + fiscal_year = get_fiscal_year(nowdate())[0] + + # Create Supplier + supplier = create_supplier() + + # Check Naming Series in generated Supplier ID + doc_name = supplier.name.split("-") + self.assertEqual(len(doc_name), 3) + self.assertSequenceEqual(doc_name[0:2], ("SUP", fiscal_year)) + ADDRESS_RECORDS = [ { From e6f3a14289e8a52864792bd9498eca3f31077ba7 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Thu, 11 Jan 2024 12:22:08 +0530 Subject: [PATCH 3/3] fix: reset default after test (cherry picked from commit 813b7a96fbb0ff048c112dec5551edf5980d0955) --- erpnext/accounts/test/test_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/test/test_utils.py b/erpnext/accounts/test/test_utils.py index 51141d3828..c439d4b190 100644 --- a/erpnext/accounts/test/test_utils.py +++ b/erpnext/accounts/test/test_utils.py @@ -23,7 +23,8 @@ class TestUtils(unittest.TestCase): super(TestUtils, cls).setUpClass() make_test_objects("Address", ADDRESS_RECORDS) - def tearDown(self): + @classmethod + def tearDownClass(cls): frappe.db.rollback() def test_get_party_shipping_address(self): @@ -150,7 +151,6 @@ class TestUtils(unittest.TestCase): "Supplier", None, "autoname", "SUP-.FY.-.#####", "Data", for_doctype="Doctype" ) - # Create Fiscal Year for Current Year fiscal_year = get_fiscal_year(nowdate())[0] # Create Supplier @@ -160,6 +160,7 @@ class TestUtils(unittest.TestCase): doc_name = supplier.name.split("-") self.assertEqual(len(doc_name), 3) self.assertSequenceEqual(doc_name[0:2], ("SUP", fiscal_year)) + frappe.db.set_default("supp_master_name", "Supplier Name") ADDRESS_RECORDS = [