naming series changes now saved as property setter

This commit is contained in:
Anand Doshi 2012-04-10 15:31:48 +05:30
parent 71841df9ab
commit a9ccc7d6bd
4 changed files with 41 additions and 25 deletions

View 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"))

View File

@ -8,10 +8,11 @@ def execute():
* 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 @@ def execute():
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 @@ def create_prev_field_prop_setter(cf):
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:

View File

@ -262,4 +262,9 @@ patch_list = [
'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'
},
]

View File

@ -34,14 +34,6 @@ class DocType:
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 @@ class DocType:
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 @@ class DocType:
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 @@ class DocType:
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 @@ class DocType:
#-----------------------------------------------------------------------------------------------------------------------------------
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
#-----------------------------------------------------------------------------------------------------------------------------------