From 7157c5328e89ccffc615d51e3e9c19fa6e02ac3d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 14 Dec 2012 19:05:07 +0530 Subject: [PATCH] set_default function added into utils --- webnotes/model/utils.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/webnotes/model/utils.py b/webnotes/model/utils.py index 011360f9b2..10e2903346 100644 --- a/webnotes/model/utils.py +++ b/webnotes/model/utils.py @@ -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) \ No newline at end of file + 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)) \ No newline at end of file