[naming series] [minor] [fix]
diff --git a/setup/doctype/naming_series/naming_series.py b/setup/doctype/naming_series/naming_series.py
index 527ec6e..51ca437 100644
--- a/setup/doctype/naming_series/naming_series.py
+++ b/setup/doctype/naming_series/naming_series.py
@@ -140,14 +140,28 @@
if naming_series:
make_property_setter(doctype, "naming_series", "hidden", 0, "Check")
make_property_setter(doctype, "naming_series", "reqd", 1, "Check")
+
+ # set values for mandatory
+ webnotes.conn.sql("""update `tab{doctype}` set naming_series={s} where
+ ifnull(naming_series, '')=''""".format(doctyp=doctype, s="%s"), get_default_naming_series(doctype))
+
if hide_name_field:
make_property_setter(doctype, fieldname, "reqd", 0, "Check")
make_property_setter(doctype, fieldname, "hidden", 1, "Check")
else:
make_property_setter(doctype, "naming_series", "reqd", 0, "Check")
make_property_setter(doctype, "naming_series", "hidden", 1, "Check")
+
if hide_name_field:
make_property_setter(doctype, fieldname, "hidden", 0, "Check")
make_property_setter(doctype, fieldname, "reqd", 1, "Check")
+
+ # set values for mandatory
+ webnotes.conn.sql("""update `tab{doctype}` set `{fieldname}`=`name` where
+ ifnull({fieldname}, '')=''""".format(doctyp=doctype, fieldname=fieldname))
-
\ No newline at end of file
+def get_default_naming_series(doctype):
+ from webnotes.model.doctype import get_property
+ naming_series = get_property(doctype, "options", "naming_series")
+ naming_series = naming_series.split("\n")
+ return naming_series[0] or naming_series[1]
\ No newline at end of file
diff --git a/support/doctype/newsletter/newsletter.py b/support/doctype/newsletter/newsletter.py
index 8e45768..b480b7d 100644
--- a/support/doctype/newsletter/newsletter.py
+++ b/support/doctype/newsletter/newsletter.py
@@ -111,6 +111,7 @@
def create_lead(email_id):
"""create a lead if it does not exist"""
from email.utils import parseaddr
+ from webnotes.model.doc import get_default_naming_series
real_name, email_id = parseaddr(email_id)
if webnotes.conn.get_value("Lead", {"email_id": email_id}):
@@ -121,24 +122,8 @@
"email_id": email_id,
"lead_name": real_name or email_id,
"status": "Contacted",
- "naming_series": get_lead_naming_series(),
+ "naming_series": get_default_naming_series("Lead"),
"company": webnotes.conn.get_default("company"),
"source": "Email"
})
- lead.insert()
-
-def get_lead_naming_series():
- """gets lead's default naming series"""
- lead_naming_series = None
- naming_series_field = webnotes.get_doctype("Lead").get_field("naming_series")
- if naming_series_field.default:
- lead_naming_series = naming_series_field.default
- else:
- latest_naming_series = webnotes.conn.sql("""select naming_series
- from `tabLead` order by creation desc limit 1""")
- if latest_naming_series:
- lead_naming_series = latest_naming_series[0][0]
- else:
- lead_naming_series = filter(None, naming_series_field.options.split("\n"))[0]
-
- return lead_naming_series
+ lead.insert()
\ No newline at end of file