From 6ce5cc7bffa252b7fbbd59138e6fed40b5891a9c Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Wed, 12 Jul 2017 17:06:37 +0530 Subject: [PATCH] [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 --- frappe/model/naming.py | 6 ++++++ frappe/tests/test_document.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/frappe/model/naming.py b/frappe/model/naming.py index 3f0b1b7228..c47422c3ec 100644 --- a/frappe/model/naming.py +++ b/frappe/model/naming.py @@ -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: diff --git a/frappe/tests/test_document.py b/frappe/tests/test_document.py index 3182b33f45..147771c393 100644 --- a/frappe/tests/test_document.py +++ b/frappe/tests/test_document.py @@ -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)