sales person fix

This commit is contained in:
Ravi Dey 2011-07-05 12:11:40 +05:30
parent d958262761
commit 1b6d158f27

View File

@ -5,64 +5,60 @@ from webnotes.model.doc import Document
from webnotes.model.doclist import getlist from webnotes.model.doclist import getlist
from webnotes.model.code import get_obj from webnotes.model.code import get_obj
from webnotes import session, form, is_testing, msgprint, errprint from webnotes import session, form, is_testing, msgprint, errprint
from webnotes.utils import flt
sql = webnotes.conn.sql sql = webnotes.conn.sql
convert_to_lists = webnotes.conn.convert_to_lists convert_to_lists = webnotes.conn.convert_to_lists
# ----------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------
class DocType: class DocType:
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_sales_person'; self.nsm_parent_field = 'parent_sales_person';
def check_state(self): def check_state(self):
return "\n" + "\n".join([i[0] for i in sql("select state_name from `tabState` where `tabState`.country='%s' " % self.doc.country)]) return "\n" + "\n".join([i[0] for i in sql("select state_name from `tabState` where `tabState`.country='%s' " % self.doc.country)])
# update Node Set Model # update Node Set Model
def update_nsm_model(self): def update_nsm_model(self):
import webnotes import webnotes
import webnotes.utils.nestedset import webnotes.utils.nestedset
webnotes.utils.nestedset.update_nsm(self) webnotes.utils.nestedset.update_nsm(self)
# ON UPDATE # ON UPDATE
#-------------------------------------- #--------------------------------------
def on_update(self): def on_update(self):
# update nsm # update nsm
self.update_nsm_model() self.update_nsm_model()
def validate(self): def validate(self):
from webnotes.utils import flt for d in getlist(self.doclist, 'target_details'):
for d in getlist(self.doclist, 'target_details'): if not flt(d.target_qty) and not flt(d.target_amount):
if not flt(d.target_qty) and not flt(d.target_amount): msgprint("Either target qty or target amount is mandatory.")
msgprint("Either target qty or target amount is mandatory.") raise Exception
raise Exception
#self.sync_with_contact()
#self.sync_with_contact()
def sync_with_contact(self):
def sync_with_contact(self): cid = sql("select name from tabContact where sales_person_id = %s and is_sales_person=1", self.doc.name)
cid = sql("select name from tabContact where sales_person_id = %s and is_sales_person=1", self.doc.name) if cid:
if cid: d = Document('Contact', cid[0][0])
d = Document('Contact', cid[0][0]) else:
else: d = Document('Contact')
d = Document('Contact')
name_split = self.doc.sales_person_name.split()
name_split = self.doc.sales_person_name.split() d.contact_name = self.doc.sales_person_name
d.contact_name = self.doc.sales_person_name d.first_name = name_split[0]
d.first_name = name_split[0] d.last_name = len(name_split) > 1 and name_split[1] or ''
d.last_name = len(name_split) > 1 and name_split[1] or '' d.email_id = self.doc.email_id
d.email_id = self.doc.email_id d.contact_no = d.mobile_no = self.doc.mobile_no
d.contact_no = d.mobile_no = self.doc.mobile_no d.designation = self.doc.designation
d.designation = self.doc.designation d.department = self.doc.department
d.department = self.doc.department d.sales_person_id = self.doc.name
d.sales_person_id = self.doc.name d.is_sales_person = 1
d.is_sales_person = 1
d.save(new = (not d.name))
d.save(new = (not d.name))