naming series changes now saved as property setter
This commit is contained in:
parent
71841df9ab
commit
a9ccc7d6bd
12
erpnext/patches/april_2012/naming_series_patch.py
Normal file
12
erpnext/patches/april_2012/naming_series_patch.py
Normal file
@ -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"))
|
@ -8,10 +8,11 @@ def execute():
|
|||||||
* Remove 'no_column' from DocField
|
* Remove 'no_column' from DocField
|
||||||
* Drop table DocFormat
|
* Drop table DocFormat
|
||||||
"""
|
"""
|
||||||
|
change_property_setter_fieldnames()
|
||||||
|
|
||||||
import webnotes.model.sync
|
import webnotes.model.sync
|
||||||
webnotes.model.sync.sync_all(force=1)
|
webnotes.model.sync.sync_all(force=1)
|
||||||
|
|
||||||
change_property_setter_fieldnames()
|
|
||||||
handle_custom_fields()
|
handle_custom_fields()
|
||||||
create_file_list()
|
create_file_list()
|
||||||
|
|
||||||
@ -19,6 +20,8 @@ def execute():
|
|||||||
change_to_decimal()
|
change_to_decimal()
|
||||||
|
|
||||||
def change_property_setter_fieldnames():
|
def change_property_setter_fieldnames():
|
||||||
|
import webnotes.model.sync
|
||||||
|
webnotes.model.sync.sync('core', 'property_setter')
|
||||||
docfield_list = webnotes.conn.sql("""\
|
docfield_list = webnotes.conn.sql("""\
|
||||||
SELECT name, fieldname FROM `tabDocField`""", as_list=1)
|
SELECT name, fieldname FROM `tabDocField`""", as_list=1)
|
||||||
custom_field_list = webnotes.conn.sql("""\
|
custom_field_list = webnotes.conn.sql("""\
|
||||||
@ -94,22 +97,23 @@ def create_prev_field_prop_setter(cf):
|
|||||||
WHERE name = %s""", (similar_idx_label[0], f.get('name')))
|
WHERE name = %s""", (similar_idx_label[0], f.get('name')))
|
||||||
|
|
||||||
prev_field = field_list[label_index]
|
prev_field = field_list[label_index]
|
||||||
webnotes.conn.sql("""\
|
res = webnotes.conn.sql("""\
|
||||||
DELETE FROM `tabProperty Setter`
|
SELECT name FROM `tabProperty Setter`
|
||||||
WHERE doc_type = %s
|
WHERE doc_type = %s
|
||||||
AND field_name = %s
|
AND field_name = %s
|
||||||
AND property = 'previous_field'""", (f.get('dt'), f.get('fieldname')))
|
AND property = 'previous_field'""", (f.get('dt'), f.get('fieldname')))
|
||||||
|
|
||||||
ps = Document('Property Setter', fielddata = {
|
if not res:
|
||||||
'doctype_or_field': 'DocField',
|
ps = Document('Property Setter', fielddata = {
|
||||||
'doc_type': f.get('dt'),
|
'doctype_or_field': 'DocField',
|
||||||
'field_name': f.get('fieldname'),
|
'doc_type': f.get('dt'),
|
||||||
'property': 'previous_field',
|
'field_name': f.get('fieldname'),
|
||||||
'value': prev_field,
|
'property': 'previous_field',
|
||||||
'property_type': 'Data',
|
'value': prev_field,
|
||||||
'select_doctype': f.get('dt')
|
'property_type': 'Data',
|
||||||
})
|
'select_doctype': f.get('dt')
|
||||||
ps.save(1)
|
})
|
||||||
|
ps.save(1)
|
||||||
|
|
||||||
def remove_custom_from_docfield(cf):
|
def remove_custom_from_docfield(cf):
|
||||||
for f in cf:
|
for f in cf:
|
||||||
|
@ -262,4 +262,9 @@ patch_list = [
|
|||||||
'patch_file': 'reload_c_form',
|
'patch_file': 'reload_c_form',
|
||||||
'description': 'Added attchemnt option and total field'
|
'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'
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
@ -34,14 +34,6 @@ class DocType:
|
|||||||
def get_transactions(self):
|
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")])
|
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):
|
def scrub_options_list(self, ol):
|
||||||
options = filter(lambda x: x, [cstr(n.upper()).strip() for n in ol])
|
options = filter(lambda x: x, [cstr(n.upper()).strip() for n in ol])
|
||||||
return options
|
return options
|
||||||
@ -60,6 +52,7 @@ class DocType:
|
|||||||
default = options[0]
|
default = options[0]
|
||||||
|
|
||||||
# update in property setter
|
# update in property setter
|
||||||
|
from webnotes.model.doc import Document
|
||||||
prop_dict = {'options': "\n".join(options), 'default': default}
|
prop_dict = {'options': "\n".join(options), 'default': default}
|
||||||
for prop in prop_dict:
|
for prop in prop_dict:
|
||||||
ps_exists = webnotes.conn.sql("""SELECT name FROM `tabProperty Setter`
|
ps_exists = webnotes.conn.sql("""SELECT name FROM `tabProperty Setter`
|
||||||
@ -82,6 +75,9 @@ class DocType:
|
|||||||
ps.save(1)
|
ps.save(1)
|
||||||
|
|
||||||
self.doc.set_options = "\n".join(options)
|
self.doc.set_options = "\n".join(options)
|
||||||
|
|
||||||
|
from webnotes.utils.cache import CacheItem
|
||||||
|
CacheItem(doctype).clear()
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
def update_series(self):
|
def update_series(self):
|
||||||
@ -95,7 +91,7 @@ class DocType:
|
|||||||
dt = DocType()
|
dt = DocType()
|
||||||
|
|
||||||
parent = sql("select parent from `tabDocField` where fieldname='naming_series' and parent != %s", self.doc.select_doc_for_series)
|
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"))
|
options = self.scrub_options_list(self.doc.set_options.split("\n"))
|
||||||
for series in options:
|
for series in options:
|
||||||
dt.validate_series(series, self.doc.select_doc_for_series)
|
dt.validate_series(series, self.doc.select_doc_for_series)
|
||||||
@ -113,9 +109,8 @@ class DocType:
|
|||||||
|
|
||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
def get_options(self, arg=''):
|
def get_options(self, arg=''):
|
||||||
so = sql("select options from `tabDocField` where parent=%s and fieldname='naming_series'", self.doc.select_doc_for_series)
|
sr = webnotes.model.doctype.get_property(self.doc.select_doc_for_series, 'options', 'naming_series')
|
||||||
if so:
|
return sr
|
||||||
return so[0][0] or ''
|
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user