fix: check if 'All Item Group' exists before settings it as parent_item_group (#18956)

* fix: check if 'All Item Group' exists before settings it as parent_item_group

* feat: get cached value to avoid db call on each insert
This commit is contained in:
Saurabh 2019-09-07 12:29:29 +05:30 committed by Nabin Hait
parent 4726fc4893
commit 8e67a3a8a8

View File

@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe
import copy
from frappe import _
from frappe.utils import nowdate, cint, cstr
from frappe.utils.nestedset import NestedSet
from frappe.website.website_generator import WebsiteGenerator
@ -28,7 +29,8 @@ class ItemGroup(NestedSet, WebsiteGenerator):
super(ItemGroup, self).validate()
if not self.parent_item_group and not frappe.flags.in_test:
self.parent_item_group = 'All Item Groups'
if frappe.db.exists("Item Group", _('All Item Groups'), cache=True):
self.parent_item_group = _('All Item Groups')
self.make_route()