naming series changes now saved as property setter
diff --git a/erpnext/patches/april_2012/naming_series_patch.py b/erpnext/patches/april_2012/naming_series_patch.py
new file mode 100644
index 0000000..574d036
--- /dev/null
+++ b/erpnext/patches/april_2012/naming_series_patch.py
@@ -0,0 +1,12 @@
+def execute():
+ import webnotes
+ from webnotes.model.code import get_obj
+ ns_list = webnotes.conn.sql("""\
+ SELECT `tabDocField`.`parent`, `tabDocField`.`options`
+ FROM `tabDocField`, `tabDocType`
+ WHERE `tabDocField`.`fieldname` = 'naming_series'
+ AND `tabDocType`.name=`tabDocField`.parent""")
+ ns_obj = get_obj('Naming Series')
+ for ns in ns_list:
+ if ns[0] and isinstance(ns[1], basestring):
+ ns_obj.set_series_for(ns[0], ns[1].split("\n"))
diff --git a/erpnext/patches/mar_2012/doctype_get_refactor.py b/erpnext/patches/mar_2012/doctype_get_refactor.py
index 1c84044..fb8c65a 100644
--- a/erpnext/patches/mar_2012/doctype_get_refactor.py
+++ b/erpnext/patches/mar_2012/doctype_get_refactor.py
@@ -8,10 +8,11 @@
* Remove 'no_column' from DocField
* Drop table DocFormat
"""
+ change_property_setter_fieldnames()
+
import webnotes.model.sync
webnotes.model.sync.sync_all(force=1)
- change_property_setter_fieldnames()
handle_custom_fields()
create_file_list()
@@ -19,6 +20,8 @@
change_to_decimal()
def change_property_setter_fieldnames():
+ import webnotes.model.sync
+ webnotes.model.sync.sync('core', 'property_setter')
docfield_list = webnotes.conn.sql("""\
SELECT name, fieldname FROM `tabDocField`""", as_list=1)
custom_field_list = webnotes.conn.sql("""\
@@ -94,22 +97,23 @@
WHERE name = %s""", (similar_idx_label[0], f.get('name')))
prev_field = field_list[label_index]
- webnotes.conn.sql("""\
- DELETE FROM `tabProperty Setter`
+ res = webnotes.conn.sql("""\
+ SELECT name FROM `tabProperty Setter`
WHERE doc_type = %s
AND field_name = %s
AND property = 'previous_field'""", (f.get('dt'), f.get('fieldname')))
- ps = Document('Property Setter', fielddata = {
- 'doctype_or_field': 'DocField',
- 'doc_type': f.get('dt'),
- 'field_name': f.get('fieldname'),
- 'property': 'previous_field',
- 'value': prev_field,
- 'property_type': 'Data',
- 'select_doctype': f.get('dt')
- })
- ps.save(1)
+ if not res:
+ ps = Document('Property Setter', fielddata = {
+ 'doctype_or_field': 'DocField',
+ 'doc_type': f.get('dt'),
+ 'field_name': f.get('fieldname'),
+ 'property': 'previous_field',
+ 'value': prev_field,
+ 'property_type': 'Data',
+ 'select_doctype': f.get('dt')
+ })
+ ps.save(1)
def remove_custom_from_docfield(cf):
for f in cf:
diff --git a/erpnext/patches/patch_list.py b/erpnext/patches/patch_list.py
index 1dfd0b5..94164f0 100644
--- a/erpnext/patches/patch_list.py
+++ b/erpnext/patches/patch_list.py
@@ -262,4 +262,9 @@
'patch_file': 'reload_c_form',
'description': 'Added attchemnt option and total field'
},
+ {
+ 'patch_module': 'patches.april_2012',
+ 'patch_file': 'naming_series_patch',
+ 'description': 'Move naming series options into property setter'
+ },
]
diff --git a/erpnext/setup/doctype/naming_series/naming_series.py b/erpnext/setup/doctype/naming_series/naming_series.py
index 3b820b8..5a9a265 100644
--- a/erpnext/setup/doctype/naming_series/naming_series.py
+++ b/erpnext/setup/doctype/naming_series/naming_series.py
@@ -34,14 +34,6 @@
def get_transactions(self):
return "\n".join([''] + [i[0] for i in sql("SELECT `tabDocField`.`parent` FROM `tabDocField`, `tabDocType` WHERE `tabDocField`.`fieldname` = 'naming_series' and `tabDocType`.name=`tabDocField`.parent order by `tabDocField`.parent")])
- #-----------------------------------------------------------------------------------------------------------------------------------
- def get_options_for(self, doctype):
- sr = webnotes.model.doctype.get_property(doctype, 'naming_series')
- if sr:
- return sr.split("\n")
- else:
- return []
-
def scrub_options_list(self, ol):
options = filter(lambda x: x, [cstr(n.upper()).strip() for n in ol])
return options
@@ -60,6 +52,7 @@
default = options[0]
# update in property setter
+ from webnotes.model.doc import Document
prop_dict = {'options': "\n".join(options), 'default': default}
for prop in prop_dict:
ps_exists = webnotes.conn.sql("""SELECT name FROM `tabProperty Setter`
@@ -82,6 +75,9 @@
ps.save(1)
self.doc.set_options = "\n".join(options)
+
+ from webnotes.utils.cache import CacheItem
+ CacheItem(doctype).clear()
#-----------------------------------------------------------------------------------------------------------------------------------
def update_series(self):
@@ -95,7 +91,7 @@
dt = DocType()
parent = sql("select parent from `tabDocField` where fieldname='naming_series' and parent != %s", self.doc.select_doc_for_series)
- sr = ([p[0], webnotes.model.doctype.get_property(p[0], 'naming_series')] for p in parent)
+ sr = ([webnotes.model.doctype.get_property(p[0], 'options', 'naming_series'), p[0]] for p in parent)
options = self.scrub_options_list(self.doc.set_options.split("\n"))
for series in options:
dt.validate_series(series, self.doc.select_doc_for_series)
@@ -113,9 +109,8 @@
#-----------------------------------------------------------------------------------------------------------------------------------
def get_options(self, arg=''):
- so = sql("select options from `tabDocField` where parent=%s and fieldname='naming_series'", self.doc.select_doc_for_series)
- if so:
- return so[0][0] or ''
+ sr = webnotes.model.doctype.get_property(self.doc.select_doc_for_series, 'options', 'naming_series')
+ return sr
#-----------------------------------------------------------------------------------------------------------------------------------