Revert "fix: Set default only if the dependent field is set (#7130)" (#7644)

This reverts commit 73c1f531e8.
This commit is contained in:
Nabin Hait 2019-06-05 20:30:13 +05:30 committed by GitHub
parent 4853284d27
commit df438c1697
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 35 deletions

View file

@ -60,24 +60,15 @@ def set_user_and_static_default_values(doc):
allowed_records = get_allowed_docs_for_doctype(doctype_user_permissions, df.parent)
user_default_value = get_user_default_value(df, defaults, doctype_user_permissions, allowed_records)
if user_default_value != None:
# do not set default if the field on which current field is dependent is not set
if is_dependent_field_set(df.depends_on, doc):
doc.set(df.fieldname, user_default_value)
if user_default_value is not None:
doc.set(df.fieldname, user_default_value)
else:
if df.fieldname != doc.meta.title_field:
static_default_value = get_static_default_value(df, doctype_user_permissions, allowed_records)
if static_default_value != None and is_dependent_field_set(df.depends_on, doc):
if static_default_value is not None:
doc.set(df.fieldname, static_default_value)
def is_dependent_field_set(fieldname, doc):
value_dict = doc.as_dict()
if not fieldname: return True
# to check if fieldname passed is valid
if fieldname not in value_dict: return True
return value_dict[fieldname]
def get_user_default_value(df, defaults, doctype_user_permissions, allowed_records):
# don't set defaults for "User" link field using User Permissions!
if df.fieldtype == "Link" and df.options != "User":

View file

@ -5,7 +5,6 @@ from __future__ import unicode_literals
import frappe, unittest, os
from frappe.utils import cint
from frappe.model.naming import revert_series_if_last, make_autoname, parse_naming_series
from frappe.utils.testutils import add_custom_field, clear_custom_fields
class TestDocument(unittest.TestCase):
def test_get_return_empty_list_for_table_field_if_none(self):
@ -236,20 +235,3 @@ class TestDocument(unittest.TestCase):
new_current = cint(frappe.db.get_value('Series', prefix, "current", order_by="name"))
self.assertEqual(cint(old_current) - 1, new_current)
def test_default_of_dependent_field(self):
add_custom_field('ToDo', 'parent_field', 'Data')
add_custom_field('ToDo', 'dependent_field', 'Data',
default='Some Data', depends_on='parent_field')
add_custom_field('ToDo', 'independent_field', 'Data',
default='Some Data')
doc = frappe.new_doc('ToDo')
self.assertFalse(doc.get('dependent_field'))
self.assertEqual(doc.get('independent_field'), 'Some Data')
clear_custom_fields('ToDo')

View file

@ -4,15 +4,13 @@ from __future__ import unicode_literals
import frappe
def add_custom_field(doctype, fieldname, fieldtype='Data', options=None, default=None, depends_on=None):
def add_custom_field(doctype, fieldname, fieldtype='Data', options=None):
frappe.get_doc({
"doctype": "Custom Field",
"dt": doctype,
"fieldname": fieldname,
"fieldtype": fieldtype,
"options": options,
"default": default,
"depends_on": depends_on
"options": options
}).insert()
def clear_custom_fields(doctype):