fix: Set Root as Parent if no parent in new tree view node (#22507)

This commit is contained in:
Marica
2020-06-30 08:21:07 +05:30
committed by GitHub
parent a20957d355
commit 5d5cb0ac28
3 changed files with 12 additions and 3 deletions

View File

@@ -6,9 +6,12 @@ import frappe
from frappe import _
from frappe.utils.nestedset import NestedSet
from frappe.utils.nestedset import NestedSet, get_root_of
class CustomerGroup(NestedSet):
nsm_parent_field = 'parent_customer_group'
def validate(self):
if not self.parent_customer_group:
self.parent_customer_group = get_root_of("Customer Group")
def on_update(self):
self.validate_name_with_customer()

View File

@@ -5,13 +5,16 @@ from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import flt
from frappe.utils.nestedset import NestedSet
from frappe.utils.nestedset import NestedSet, get_root_of
from erpnext import get_default_currency
class SalesPerson(NestedSet):
nsm_parent_field = 'parent_sales_person'
def validate(self):
if not self.parent_sales_person:
self.parent_sales_person = get_root_of("Sales Person")
for d in self.get('targets') or []:
if not flt(d.target_qty) and not flt(d.target_amount):
frappe.throw(_("Either target qty or target amount is mandatory."))

View File

@@ -8,12 +8,15 @@ import frappe
from frappe.utils import flt
from frappe import _
from frappe.utils.nestedset import NestedSet
from frappe.utils.nestedset import NestedSet, get_root_of
class Territory(NestedSet):
nsm_parent_field = 'parent_territory'
def validate(self):
if not self.parent_territory:
self.parent_territory = get_root_of("Territory")
for d in self.get('targets') or []:
if not flt(d.target_qty) and not flt(d.target_amount):
frappe.throw(_("Either target qty or target amount is mandatory"))