feat(Naming Series): Option to Add field_value in Naming Series (#7027)

To use field_value in naming_series, just add field_name in curly braces instead of the old naming convention which was kinda confusing and not easily understandable.
eg: {field_name}.-.YYYY.-.MM.-.DD.-.####
This commit is contained in:
Himanshu 2019-03-25 11:43:08 +05:30 committed by Faris Ansari
parent b7b061105f
commit 7dc1fec27c
3 changed files with 1958 additions and 1956 deletions

File diff suppressed because it is too large Load diff

View file

@ -213,12 +213,12 @@ class Document(BaseDocument):
self.set_docstatus()
self.check_if_latest()
self.run_method("before_insert")
self._validate_links()
self.set_new_name()
self.set_parent_in_children()
self.validate_higher_perm_levels()
self.flags.in_insert = True
self._validate_links()
self.run_before_save_methods()
self._validate()
self.set_docstatus()

View file

@ -88,21 +88,21 @@ def set_name_by_naming_series(doc):
def make_autoname(key='', doctype='', doc=''):
"""
Creates an autoname from the given key:
Creates an autoname from the given key:
**Autoname rules:**
**Autoname rules:**
* The key is separated by '.'
* '####' represents a series. The string before this part becomes the prefix:
Example: ABC.#### creates a series ABC0001, ABC0002 etc
* 'MM' represents the current month
* 'YY' and 'YYYY' represent the current year
* The key is separated by '.'
* '####' represents a series. The string before this part becomes the prefix:
Example: ABC.#### creates a series ABC0001, ABC0002 etc
* 'MM' represents the current month
* 'YY' and 'YYYY' represent the current year
*Example:*
* DE/./.YY./.MM./.##### will create a series like
DE/09/01/0001 where 09 is the year, 01 is the month and 0001 is the series
* DE/./.YY./.MM./.##### will create a series like
DE/09/01/0001 where 09 is the year, 01 is the month and 0001 is the series
"""
if key == "hash":
return frappe.generate_hash(doctype, 10)
@ -121,7 +121,6 @@ def parse_naming_series(parts, doctype='', doc=''):
n = ''
if isinstance(parts, string_types):
parts = parts.split('.')
series_set = False
today = now_datetime()
for e in parts:
@ -141,6 +140,9 @@ def parse_naming_series(parts, doctype='', doc=''):
part = today.strftime('%Y')
elif e == 'FY':
part = frappe.defaults.get_user_default("fiscal_year")
elif e.startswith('{') and doc:
e = e.replace('{', '').replace('}', '')
part = doc.get(e)
elif doc and doc.get(e):
part = doc.get(e)
else: