removed while loop

This commit is contained in:
Akhilesh Darjee 2014-01-15 11:43:47 +05:30
parent 5dd92fd5d6
commit 6a749e3a8e

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import add_days, cstr, getdate from webnotes.utils import add_days, cstr, getdate, cint
from webnotes.model.doc import addchild from webnotes.model.doc import addchild
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes import msgprint, throw, _ from webnotes import msgprint, throw, _
@ -93,14 +93,15 @@ class DocType(TransactionBase):
date_diff = (getdate(end_date) - getdate(start_date)).days date_diff = (getdate(end_date) - getdate(start_date)).days
add_by = date_diff / no_of_visit add_by = date_diff / no_of_visit
while (getdate(start_date_copy) < getdate(end_date)): for visit in range(0, cint(no_of_visit)):
start_date_copy = add_days(start_date_copy, add_by) if (getdate(start_date_copy) < getdate(end_date)):
if len(schedule_list) < no_of_visit: start_date_copy = add_days(start_date_copy, add_by)
schedule_date = self.validate_schedule_date_for_holiday_list(getdate(start_date_copy), if len(schedule_list) < no_of_visit:
sales_person) schedule_date = self.validate_schedule_date_for_holiday_list(getdate(start_date_copy),
if schedule_date > getdate(end_date): sales_person)
schedule_date = getdate(end_date) if schedule_date > getdate(end_date):
schedule_list.append(schedule_date) schedule_date = getdate(end_date)
schedule_list.append(schedule_date)
return schedule_list return schedule_list
@ -115,6 +116,7 @@ class DocType(TransactionBase):
pass pass
if fy_details and fy_details[0]: if fy_details and fy_details[0]:
# check holiday list in employee master
holiday_list = webnotes.conn.sql_list("""select h.holiday_date from `tabEmployee` emp, holiday_list = webnotes.conn.sql_list("""select h.holiday_date from `tabEmployee` emp,
`tabSales Person` sp, `tabHoliday` h, `tabHoliday List` hl `tabSales Person` sp, `tabHoliday` h, `tabHoliday List` hl
where sp.name=%s and emp.name=sp.employee where sp.name=%s and emp.name=sp.employee
@ -122,12 +124,13 @@ class DocType(TransactionBase):
h.parent=hl.name and h.parent=hl.name and
hl.fiscal_year=%s""", (sales_person, fy_details[0])) hl.fiscal_year=%s""", (sales_person, fy_details[0]))
if not holiday_list: if not holiday_list:
# check global holiday list
holiday_list = webnotes.conn.sql("""select h.holiday_date from holiday_list = webnotes.conn.sql("""select h.holiday_date from
`tabHoliday` h, `tabHoliday List` hl `tabHoliday` h, `tabHoliday List` hl
where h.parent=hl.name and ifnull(hl.is_default, 0) = 1 where h.parent=hl.name and ifnull(hl.is_default, 0) = 1
and hl.fiscal_year=%s""", fy_details[0]) and hl.fiscal_year=%s""", fy_details[0])
while not validated and holiday_list: if not validated and holiday_list:
if schedule_date in holiday_list: if schedule_date in holiday_list:
schedule_date = add_days(schedule_date, -1) schedule_date = add_days(schedule_date, -1)
else: else: