Merge pull request #39325 from frappe/mergify/bp/version-15-hotfix/pr-39305
fix: naming series variable parsing for FY (backport #39305)
This commit is contained in:
commit
15e116375b
@ -23,6 +23,10 @@ class TestUtils(unittest.TestCase):
|
|||||||
super(TestUtils, cls).setUpClass()
|
super(TestUtils, cls).setUpClass()
|
||||||
make_test_objects("Address", ADDRESS_RECORDS)
|
make_test_objects("Address", ADDRESS_RECORDS)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
frappe.db.rollback()
|
||||||
|
|
||||||
def test_get_party_shipping_address(self):
|
def test_get_party_shipping_address(self):
|
||||||
address = get_party_shipping_address("Customer", "_Test Customer 1")
|
address = get_party_shipping_address("Customer", "_Test Customer 1")
|
||||||
self.assertEqual(address, "_Test Billing Address 2 Title-Billing")
|
self.assertEqual(address, "_Test Billing Address 2 Title-Billing")
|
||||||
@ -126,6 +130,38 @@ class TestUtils(unittest.TestCase):
|
|||||||
self.assertEqual(len(payment_entry.references), 1)
|
self.assertEqual(len(payment_entry.references), 1)
|
||||||
self.assertEqual(payment_entry.difference_amount, 0)
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
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))
|
||||||
|
frappe.db.set_default("supp_master_name", "Supplier Name")
|
||||||
|
|
||||||
|
|
||||||
ADDRESS_RECORDS = [
|
ADDRESS_RECORDS = [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1263,12 +1263,12 @@ def get_autoname_with_number(number_value, doc_title, company):
|
|||||||
def parse_naming_series_variable(doc, variable):
|
def parse_naming_series_variable(doc, variable):
|
||||||
if variable == "FY":
|
if variable == "FY":
|
||||||
if doc:
|
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")
|
company = doc.get("company")
|
||||||
else:
|
else:
|
||||||
date = getdate()
|
date = getdate()
|
||||||
company = None
|
company = None
|
||||||
return get_fiscal_year(date=date, company=company).name
|
return get_fiscal_year(date=date, company=company)[0]
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user