Fix webnotes.conn.sql issue in custom_field.py
This commit is contained in:
parent
c498f01c55
commit
bcbf417a02
1 changed files with 8 additions and 12 deletions
|
|
@ -5,6 +5,7 @@ from webnotes.utils import cint, cstr, flt, formatdate, now
|
|||
from webnotes.model.doc import Document
|
||||
from webnotes import msgprint, errprint
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------------------
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
|
|
@ -13,9 +14,8 @@ class DocType:
|
|||
# Get Fields
|
||||
# -----------
|
||||
def get_fields_label(self):
|
||||
sql = webnotes.conn.sql
|
||||
label_name = []
|
||||
for i in sql("SELECT idx, label FROM tabDocField WHERE parent = '%s' and ifnull(hidden,0) = 0 and fieldname != '%s' order by idx" % (self.doc.dt, cstr(self.doc.fieldname))): i[1] and i[0] and label_name.append(i[1]+' - '+cstr(i[0]))
|
||||
for i in webnotes.conn.sql("SELECT idx, label FROM tabDocField WHERE parent = '%s' and ifnull(hidden,0) = 0 and fieldname != '%s' order by idx" % (self.doc.dt, cstr(self.doc.fieldname))): i[1] and i[0] and label_name.append(i[1]+' - '+cstr(i[0]))
|
||||
return "\n".join(label_name)
|
||||
|
||||
|
||||
|
|
@ -31,13 +31,12 @@ class DocType:
|
|||
# Validate Field
|
||||
# ---------------
|
||||
def validate_field(self):
|
||||
sql = webnotes.conn.sql
|
||||
if self.doc.__islocal == 1 and sql("select name from tabDocField where parent = %s and (label = %s or fieldname = %s)" , (self.doc.dt, self.doc.label, self.doc.fieldname)):
|
||||
if self.doc.__islocal == 1 and webnotes.conn.sql("select name from tabDocField where parent = %s and (label = %s or fieldname = %s)" , (self.doc.dt, self.doc.label, self.doc.fieldname)):
|
||||
msgprint("%s field already exists in Document : %s" % (self.doc.label, self.doc.dt))
|
||||
raise Exception
|
||||
|
||||
if self.doc.fieldtype=='Link' and self.doc.options:
|
||||
if not sql("select name from tabDocType where name=%s", self.doc.options):
|
||||
if not webnotes.conn.sql("select name from tabDocType where name=%s", self.doc.options):
|
||||
msgprint("%s is not a valid Document" % self.doc.options)
|
||||
raise Exception
|
||||
|
||||
|
|
@ -45,9 +44,8 @@ class DocType:
|
|||
# Update Field
|
||||
# -------------
|
||||
def update_field(self, df, new):
|
||||
sql = webnotes.conn.sql
|
||||
import webnotes.model
|
||||
sql("update tabDocField set idx = idx + 1, modified = %s where parent = %s and idx > %s", (now(),self.doc.dt, self.idx))
|
||||
webnotes.conn.sql("update tabDocField set idx = idx + 1, modified = %s where parent = %s and idx > %s", (now(),self.doc.dt, self.idx))
|
||||
for k in self.doc.fields:
|
||||
if k not in webnotes.model.default_fields and k not in self.ignore_fields and not k.startswith('_'):
|
||||
df.fields[k] = self.doc.fields[k]
|
||||
|
|
@ -61,8 +59,7 @@ class DocType:
|
|||
# Add Field
|
||||
# ----------
|
||||
def add_field(self):
|
||||
sql = webnotes.conn.sql
|
||||
field_exists = sql("select name from tabDocField where parent = %s and (label = %s or fieldname = %s)" , (self.doc.dt, self.doc.label, self.doc.fieldname))
|
||||
field_exists = webnotes.conn.sql("select name from tabDocField where parent = %s and (label = %s or fieldname = %s)" , (self.doc.dt, self.doc.label, self.doc.fieldname))
|
||||
field_exists = field_exists and field_exists[0][0] or ''
|
||||
self.ignore_fields = ['dt','trash_reason','insert_after','index','customfield1','length']
|
||||
if field_exists:
|
||||
|
|
@ -88,9 +85,8 @@ class DocType:
|
|||
# Trash
|
||||
# ------
|
||||
def on_trash(self):
|
||||
sql = webnotes.conn.sql
|
||||
sql("update tabDocField set idx = idx - 1 where parent = %s and idx > %s" , (self.doc.dt, cint((self.doc.insert_after).split(' - ')[1])))
|
||||
sql("delete from tabDocField where parent = %s and fieldname = %s", (self.doc.dt, self.doc.fieldname))
|
||||
webnotes.conn.sql("update tabDocField set idx = idx - 1 where parent = %s and idx > %s" , (self.doc.dt, cint((self.doc.insert_after).split(' - ')[1])))
|
||||
webnotes.conn.sql("delete from tabDocField where parent = %s and fieldname = %s", (self.doc.dt, self.doc.fieldname))
|
||||
|
||||
|
||||
# Restore
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue