set_default function added into utils
This commit is contained in:
parent
b3b0f37dc2
commit
7157c5328e
1 changed files with 11 additions and 1 deletions
|
|
@ -21,6 +21,8 @@
|
|||
#
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes.model.doc import Document
|
||||
"""
|
||||
Model utilities, unclassified functions
|
||||
"""
|
||||
|
|
@ -197,4 +199,12 @@ def to_html(doclist):
|
|||
def round_doc(doc, precision_map):
|
||||
from webnotes.utils import flt
|
||||
for fieldname, precision in precision_map.items():
|
||||
doc.fields[fieldname] = flt(doc.fields.get(fieldname), precision)
|
||||
doc.fields[fieldname] = flt(doc.fields.get(fieldname), precision)
|
||||
|
||||
def set_default(doc, key):
|
||||
if not doc.is_default:
|
||||
webnotes.conn.set(doc, "is_default", 1)
|
||||
|
||||
webnotes.conn.sql("""update `tab%s` set `is_default`=0
|
||||
where `%s`=%s and name!=%s""" % (doc.doctype, key, "%s", "%s"),
|
||||
(doc.fields.get(key), doc.name))
|
||||
Loading…
Add table
Reference in a new issue