[Fix] Auto increment of series not working if series has multiple dot(.) (#3661)

* [Fix] Auto increment of series not working if series has multiple dot(.)

* Test case for naming series
This commit is contained in:
rohitwaghchaure 2017-07-12 17:06:37 +05:30 committed by Rushabh Mehta
parent e86e69b4e7
commit 6ce5cc7bff
2 changed files with 25 additions and 0 deletions

View file

@ -99,6 +99,9 @@ def make_autoname(key='', doctype='', doc=''):
def parse_naming_series(parts, doctype= '', doc = ''):
n = ''
if isinstance(parts, basestring):
parts = parts.split('.')
series_set = False
today = now_datetime()
for e in parts:
@ -142,6 +145,9 @@ def getseries(key, digits, doctype=''):
def revert_series_if_last(key, name):
if ".#" in key:
prefix, hashes = key.rsplit(".", 1)
if '.' in prefix:
prefix = parse_naming_series(prefix.split('.'))
if "#" not in hashes:
return
else:

View file

@ -3,6 +3,8 @@
from __future__ import unicode_literals
import frappe, unittest, os
from frappe.utils import cint
from frappe.model.naming import revert_series_if_last, make_autoname, parse_naming_series
class TestDocument(unittest.TestCase):
def test_get_return_empty_list_for_table_field_if_none(self):
@ -217,3 +219,20 @@ class TestDocument(unittest.TestCase):
self.assertEquals(before_update + new_count, after_update)
def test_naming_series(self):
data = ["TEST-", "TEST/17-18/.test_data./.####", "TEST.YYYY.MM.####"]
for series in data:
name = make_autoname(series)
prefix = series
if ".#" in series:
prefix = series.rsplit('.',1)[0]
prefix = parse_naming_series(prefix)
old_current = frappe.db.get_value('Series', prefix, "current", order_by="name")
revert_series_if_last(series, name)
new_current = cint(frappe.db.get_value('Series', prefix, "current", order_by="name"))
self.assertEquals(cint(old_current) - 1, new_current)