Merge pull request #17141 from vishdha/_format_naming
fix: Use date/time field in document naming
This commit is contained in:
commit
6a91c2cf14
2 changed files with 17 additions and 3 deletions
|
|
@ -317,9 +317,9 @@ def parse_naming_series(
|
|||
part = frappe.defaults.get_user_default("fiscal_year")
|
||||
elif e.startswith("{") and doc:
|
||||
e = e.replace("{", "").replace("}", "")
|
||||
part = doc.get(e)
|
||||
part = (cstr(doc.get(e)) or "").strip()
|
||||
elif doc and doc.get(e):
|
||||
part = doc.get(e)
|
||||
part = (cstr(doc.get(e)) or "").strip()
|
||||
else:
|
||||
part = e
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from frappe.model.naming import (
|
|||
revert_series_if_last,
|
||||
)
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
from frappe.utils import now_datetime
|
||||
from frappe.utils import now_datetime, nowdate, nowtime
|
||||
|
||||
|
||||
class TestNaming(FrappeTestCase):
|
||||
|
|
@ -100,6 +100,20 @@ class TestNaming(FrappeTestCase):
|
|||
|
||||
self.assertEqual(doc.name, f"TODO-{now_datetime().strftime('%m')}-{description}-{series:02}")
|
||||
|
||||
def test_format_autoname_for_datetime_field(self):
|
||||
"""Test if datetime, date and time objects get converted to strings for naming."""
|
||||
doctype = new_doctype(autoname="format:TODO-{field}-{##}").insert()
|
||||
|
||||
for field in [now_datetime(), nowdate(), nowtime()]:
|
||||
doc = frappe.new_doc(doctype.name)
|
||||
doc.field = field
|
||||
doc.insert()
|
||||
|
||||
series = getseries("", 2)
|
||||
series = int(series) - 1
|
||||
|
||||
self.assertEqual(doc.name, f"TODO-{field}-{series:02}")
|
||||
|
||||
def test_format_autoname_for_consecutive_week_number(self):
|
||||
"""
|
||||
Test if braced params are replaced for consecutive week number in format autoname
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue