check item/item group with same name while creating item group/item

This commit is contained in:
Nabin Hait 2013-01-24 14:58:21 +05:30
parent dd8e2b161d
commit 8cf90f18f0
2 changed files with 21 additions and 8 deletions

View File

@ -24,10 +24,13 @@ class DocType(DocTypeNestedSet):
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
self.nsm_parent_field = 'parent_item_group'; self.nsm_parent_field = 'parent_item_group'
def on_update(self): def on_update(self):
super(DocType, self).on_update() super(DocType, self).on_update()
self.validate_name_with_item()
if self.doc.show_in_website: if self.doc.show_in_website:
# webpage updates # webpage updates
from website.utils import update_page_name from website.utils import update_page_name
@ -43,6 +46,11 @@ class DocType(DocTypeNestedSet):
from website.helpers.product import invalidate_cache_for from website.helpers.product import invalidate_cache_for
invalidate_cache_for(self.doc.name) invalidate_cache_for(self.doc.name)
def validate_name_with_item(self):
if webnotes.conn.exists("Item", self.doc.name):
webnotes.msgprint("An item exists with same name (%s), please change the \
item group name or rename the item" % self.doc.name, raise_exception=1)
def prepare_template_args(self): def prepare_template_args(self):
from website.helpers.product import get_product_list_for_group, \ from website.helpers.product import get_product_list_for_group, \
get_parent_item_groups, get_group_item_count get_parent_item_groups, get_group_item_count

View File

@ -18,9 +18,8 @@ from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cstr, flt from webnotes.utils import cstr, flt
from webnotes.model import db_exists
from webnotes.model.doc import addchild from webnotes.model.doc import addchild
from webnotes.model.wrapper import getlist, copy_doclist from webnotes.model.wrapper import getlist
from webnotes import msgprint from webnotes import msgprint
sql = webnotes.conn.sql sql = webnotes.conn.sql
@ -38,6 +37,8 @@ class DocType:
return ret return ret
def on_update(self): def on_update(self):
self.validate_name_with_item_group()
if self.doc.show_in_website: if self.doc.show_in_website:
# webpage updates # webpage updates
self.update_website() self.update_website()
@ -62,8 +63,6 @@ class DocType:
if flt(d.conversion_factor) != 1: if flt(d.conversion_factor) != 1:
msgprint("Conversion Factor of UOM : %s should be equal to 1. As UOM : %s is Stock UOM of Item: %s." % ( cstr(d.uom), cstr(d.uom), cstr(self.doc.name))) msgprint("Conversion Factor of UOM : %s should be equal to 1. As UOM : %s is Stock UOM of Item: %s." % ( cstr(d.uom), cstr(d.uom), cstr(self.doc.name)))
raise Exception raise Exception
# else set uom_exist as true
uom_exist='true'
elif cstr(d.uom) != cstr(self.doc.stock_uom) and flt(d.conversion_factor) == 1: elif cstr(d.uom) != cstr(self.doc.stock_uom) and flt(d.conversion_factor) == 1:
msgprint("Conversion Factor of UOM : %s should not be equal to 1. As UOM : %s is not Stock UOM of Item: %s." % ( cstr(d.uom), cstr(d.uom), cstr(self.doc.name))) msgprint("Conversion Factor of UOM : %s should not be equal to 1. As UOM : %s is not Stock UOM of Item: %s." % ( cstr(d.uom), cstr(d.uom), cstr(self.doc.name)))
raise Exception raise Exception
@ -75,6 +74,12 @@ class DocType:
child.conversion_factor = 1 child.conversion_factor = 1
child.save() child.save()
def validate_name_with_item_group(self):
if webnotes.conn.exists("Item Group", self.doc.name):
webnotes.msgprint("An item group exists with same name (%s), \
please change the item name or rename the item group" %
self.doc.name, raise_exception=1)
def update_website(self): def update_website(self):
from website.utils import update_page_name from website.utils import update_page_name
if self.doc.name==self.doc.item_name: if self.doc.name==self.doc.item_name: