Use range instead xrange (#13128)

* Use range instead of xrange

* convert float to int
This commit is contained in:
Achilles Rasquinha 2018-02-28 16:12:51 +05:30 committed by Faris Ansari
parent 72d8509b3d
commit 96698c9a77
19 changed files with 38 additions and 38 deletions

View File

@ -418,7 +418,7 @@ class TestSalesInvoice(unittest.TestCase):
si.get("items")[0].price_list_rate = 62.5 si.get("items")[0].price_list_rate = 62.5
si.get("items")[0].price_list_rate = 191 si.get("items")[0].price_list_rate = 191
for i in xrange(6): for i in range(6):
si.get("taxes")[i].included_in_print_rate = 1 si.get("taxes")[i].included_in_print_rate = 1
# tax type "Actual" cannot be inclusive # tax type "Actual" cannot be inclusive

View File

@ -133,8 +133,8 @@ class ShippingRule(Document):
return (not separate) return (not separate)
overlaps = [] overlaps = []
for i in xrange(0, len(self.conditions)): for i in range(0, len(self.conditions)):
for j in xrange(i+1, len(self.conditions)): for j in range(i+1, len(self.conditions)):
d1, d2 = self.conditions[i], self.conditions[j] d1, d2 = self.conditions[i], self.conditions[j]
if d1.as_dict() != d2.as_dict(): if d1.as_dict() != d2.as_dict():
# in our case, to_value can be zero, hence pass the from_value if so # in our case, to_value can be zero, hence pass the from_value if so

View File

@ -38,7 +38,7 @@ def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, accumulated_v
start_date = year_start_date start_date = year_start_date
months = get_months(year_start_date, year_end_date) months = get_months(year_start_date, year_end_date)
for i in xrange(months / months_to_add): for i in range(months // months_to_add):
period = frappe._dict({ period = frappe._dict({
"from_date": start_date "from_date": start_date
}) })

View File

@ -114,15 +114,15 @@ class Asset(Document):
and getdate(self.next_depreciation_date) < next_depr_date): and getdate(self.next_depreciation_date) < next_depr_date):
number_of_pending_depreciations += 1 number_of_pending_depreciations += 1
for n in xrange(number_of_pending_depreciations): for n in range(number_of_pending_depreciations):
if n == xrange(number_of_pending_depreciations)[-1]: if n == range(number_of_pending_depreciations)[-1]:
schedule_date = add_months(self.available_for_use_date, n * 12) schedule_date = add_months(self.available_for_use_date, n * 12)
previous_scheduled_date = add_months(self.next_depreciation_date, (n-1) * 12) previous_scheduled_date = add_months(self.next_depreciation_date, (n-1) * 12)
depreciation_amount = \ depreciation_amount = \
self.get_depreciation_amount_prorata_temporis(value_after_depreciation, self.get_depreciation_amount_prorata_temporis(value_after_depreciation,
previous_scheduled_date, schedule_date) previous_scheduled_date, schedule_date)
elif n == xrange(number_of_pending_depreciations)[0]: elif n == range(number_of_pending_depreciations)[0]:
schedule_date = self.next_depreciation_date schedule_date = self.next_depreciation_date
depreciation_amount = \ depreciation_amount = \
self.get_depreciation_amount_prorata_temporis(value_after_depreciation, self.get_depreciation_amount_prorata_temporis(value_after_depreciation,
@ -141,7 +141,7 @@ class Asset(Document):
"depreciation_amount": depreciation_amount "depreciation_amount": depreciation_amount
}) })
else: else:
for n in xrange(number_of_pending_depreciations): for n in range(number_of_pending_depreciations):
schedule_date = add_months(self.next_depreciation_date, schedule_date = add_months(self.next_depreciation_date,
n * cint(self.frequency_of_depreciation)) n * cint(self.frequency_of_depreciation))

View File

@ -182,7 +182,7 @@ def get_period_date_ranges(period, fiscal_year=None, year_start_date=None):
}.get(period) }.get(period)
period_date_ranges = [] period_date_ranges = []
for i in xrange(1, 13, increment): for i in range(1, 13, increment):
period_end_date = getdate(year_start_date) + relativedelta(months=increment, days=-1) period_end_date = getdate(year_start_date) + relativedelta(months=increment, days=-1)
if period_end_date > getdate(year_end_date): if period_end_date > getdate(year_end_date):
period_end_date = year_end_date period_end_date = year_end_date

View File

@ -63,7 +63,7 @@ def simulate(domain='Manufacturing', days=100):
# runs_for = 100 # runs_for = 100
fixed_asset.work() fixed_asset.work()
for i in xrange(runs_for): for i in range(runs_for):
sys.stdout.write("\rSimulating {0}: Day {1}".format( sys.stdout.write("\rSimulating {0}: Day {1}".format(
current_date.strftime("%Y-%m-%d"), i)) current_date.strftime("%Y-%m-%d"), i))
sys.stdout.flush() sys.stdout.flush()

View File

@ -65,7 +65,7 @@ def make_appointment():
i += 1 i += 1
def make_consulation(): def make_consulation():
for i in xrange(3): for i in range(3):
physician = get_random("Physician") physician = get_random("Physician")
department = frappe.get_value("Physician", physician, "department") department = frappe.get_value("Physician", physician, "department")
patient = get_random("Patient") patient = get_random("Patient")
@ -74,7 +74,7 @@ def make_consulation():
consultation.save(ignore_permissions=True) consultation.save(ignore_permissions=True)
def consulation_on_appointment(): def consulation_on_appointment():
for i in xrange(3): for i in range(3):
appointment = get_random("Patient Appointment") appointment = get_random("Patient Appointment")
appointment = frappe.get_doc("Patient Appointment",appointment) appointment = frappe.get_doc("Patient Appointment",appointment)
consultation = set_consultation(appointment.patient, appointment.patient_sex, appointment.physician, appointment.department, appointment.appointment_date, i) consultation = set_consultation(appointment.patient, appointment.patient_sex, appointment.physician, appointment.department, appointment.appointment_date, i)

View File

@ -80,7 +80,7 @@ def setup_demo_page():
def setup_fiscal_year(): def setup_fiscal_year():
fiscal_year = None fiscal_year = None
for year in xrange(2010, now_datetime().year + 1, 1): for year in range(2010, now_datetime().year + 1, 1):
try: try:
fiscal_year = frappe.get_doc({ fiscal_year = frappe.get_doc({
"doctype": "Fiscal Year", "doctype": "Fiscal Year",

View File

@ -15,7 +15,7 @@ from erpnext.education.api import get_student_group_students, make_attendance_re
def work(): def work():
frappe.set_user(frappe.db.get_global('demo_education_user')) frappe.set_user(frappe.db.get_global('demo_education_user'))
for d in xrange(20): for d in range(20):
approve_random_student_applicant() approve_random_student_applicant()
enroll_random_student(frappe.flags.current_date) enroll_random_student(frappe.flags.current_date)
# if frappe.flags.current_date.weekday()== 0: # if frappe.flags.current_date.weekday()== 0:
@ -94,7 +94,7 @@ def make_course_schedule(start_date, end_date):
cs.course_start_date = cstr(start_date) cs.course_start_date = cstr(start_date)
cs.course_end_date = cstr(end_date) cs.course_end_date = cstr(end_date)
day = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] day = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
for x in xrange(3): for x in range(3):
random_day = random.choice(day) random_day = random.choice(day)
cs.day = random_day cs.day = random_day
cs.from_time = timedelta(hours=(random.randrange(7, 17,1))) cs.from_time = timedelta(hours=(random.randrange(7, 17,1)))

View File

@ -116,7 +116,7 @@ def make_material_request(item_code, qty):
return mr return mr
def add_suppliers(rfq): def add_suppliers(rfq):
for i in xrange(2): for i in range(2):
supplier = get_random("Supplier") supplier = get_random("Supplier")
if supplier not in [d.supplier for d in rfq.get('suppliers')]: if supplier not in [d.supplier for d in rfq.get('suppliers')]:
rfq.append("suppliers", { "supplier": supplier }) rfq.append("suppliers", { "supplier": supplier })

View File

@ -13,27 +13,27 @@ from erpnext.accounts.doctype.payment_request.payment_request import make_paymen
def work(): def work():
frappe.set_user(frappe.db.get_global('demo_sales_user_2')) frappe.set_user(frappe.db.get_global('demo_sales_user_2'))
if random.random() < 0.5: if random.random() < 0.5:
for i in xrange(random.randint(1,7)): for i in range(random.randint(1,7)):
make_opportunity() make_opportunity()
if random.random() < 0.5: if random.random() < 0.5:
for i in xrange(random.randint(1,3)): for i in range(random.randint(1,3)):
make_quotation() make_quotation()
# lost quotations / inquiries # lost quotations / inquiries
if random.random() < 0.3: if random.random() < 0.3:
for i in xrange(random.randint(1,3)): for i in range(random.randint(1,3)):
quotation = get_random('Quotation', doc=True) quotation = get_random('Quotation', doc=True)
if quotation and quotation.status == 'Submitted': if quotation and quotation.status == 'Submitted':
quotation.declare_order_lost('Did not ask') quotation.declare_order_lost('Did not ask')
for i in xrange(random.randint(1,3)): for i in range(random.randint(1,3)):
opportunity = get_random('Opportunity', doc=True) opportunity = get_random('Opportunity', doc=True)
if opportunity and opportunity.status in ('Open', 'Replied'): if opportunity and opportunity.status in ('Open', 'Replied'):
opportunity.declare_enquiry_lost('Did not ask') opportunity.declare_enquiry_lost('Did not ask')
if random.random() < 0.3: if random.random() < 0.3:
for i in xrange(random.randint(1,3)): for i in range(random.randint(1,3)):
make_sales_order() make_sales_order()
if random.random() < 0.1: if random.random() < 0.1:

View File

@ -34,7 +34,7 @@ def execute(filters=None):
student_guardians = guardian_map.get(d.student) student_guardians = guardian_map.get(d.student)
if student_guardians: if student_guardians:
for i in xrange(2): for i in range(2):
if i < len(student_guardians): if i < len(student_guardians):
g = student_guardians[i] g = student_guardians[i]
row += [g.guardian_name, g.relation, g.mobile_number, g.email_address] row += [g.guardian_name, g.relation, g.mobile_number, g.email_address]

View File

@ -18,7 +18,7 @@ class HotelRoomReservation(Document):
self.validate_availability() self.validate_availability()
def validate_availability(self): def validate_availability(self):
for i in xrange(date_diff(self.to_date, self.from_date)): for i in range(date_diff(self.to_date, self.from_date)):
day = add_days(self.from_date, i) day = add_days(self.from_date, i)
self.rooms_booked = {} self.rooms_booked = {}
@ -54,7 +54,7 @@ class HotelRoomReservation(Document):
self.net_total = 0 self.net_total = 0
for d in self.items: for d in self.items:
net_rate = 0.0 net_rate = 0.0
for i in xrange(date_diff(self.to_date, self.from_date)): for i in range(date_diff(self.to_date, self.from_date)):
day = add_days(self.from_date, i) day = add_days(self.from_date, i)
if not d.item: if not d.item:
continue continue

View File

@ -24,7 +24,7 @@ def get_data(filters):
out = [] out = []
for room_type in frappe.get_all('Hotel Room Type'): for room_type in frappe.get_all('Hotel Room Type'):
total_booked = 0 total_booked = 0
for i in xrange(date_diff(filters.to_date, filters.from_date)): for i in range(date_diff(filters.to_date, filters.from_date)):
day = add_days(filters.from_date, i) day = add_days(filters.from_date, i)
total_booked += get_rooms_booked(room_type.name, day) total_booked += get_rooms_booked(room_type.name, day)

View File

@ -112,7 +112,7 @@ class MaintenanceSchedule(TransactionBase):
if not validated and holidays: if not validated and holidays:
# max iterations = len(holidays) # max iterations = len(holidays)
for i in xrange(len(holidays)): for i in range(len(holidays)):
if schedule_date in holidays: if schedule_date in holidays:
schedule_date = add_days(schedule_date, -1) schedule_date = add_days(schedule_date, -1)
else: else:

View File

@ -41,8 +41,8 @@ def execute(filters=None):
cint(from_year), cint(from_month), cint(to_year), cint(to_month) cint(from_year), cint(from_month), cint(to_year), cint(to_month)
out = [] out = []
for year in xrange(from_year, to_year+1): for year in range(from_year, to_year+1):
for month in xrange(from_month if year==from_year else 1, (to_month+1) if year==to_year else 13): for month in range(from_month if year==from_year else 1, (to_month+1) if year==to_year else 13):
key = "{year}-{month:02d}".format(year=year, month=month) key = "{year}-{month:02d}".format(year=year, month=month)
new = new_customers_in.get(key, [0,0.0]) new = new_customers_in.get(key, [0,0.0])

View File

@ -272,7 +272,7 @@ def update_serial_nos(sle, item_det):
and item_det.has_serial_no == 1 and item_det.serial_no_series: and item_det.has_serial_no == 1 and item_det.serial_no_series:
from frappe.model.naming import make_autoname from frappe.model.naming import make_autoname
serial_nos = [] serial_nos = []
for i in xrange(cint(sle.actual_qty)): for i in range(cint(sle.actual_qty)):
serial_nos.append(make_autoname(item_det.serial_no_series, "Serial No")) serial_nos.append(make_autoname(item_det.serial_no_series, "Serial No"))
frappe.db.set(sle, "serial_no", "\n".join(serial_nos)) frappe.db.set(sle, "serial_no", "\n".join(serial_nos))
validate_serial_no(sle, item_det) validate_serial_no(sle, item_det)

View File

@ -19,7 +19,7 @@ def get_context(context):
# show atleast 3 products # show atleast 3 products
if len(homepage.products) < 3: if len(homepage.products) < 3:
for i in xrange(3 - len(homepage.products)): for i in range(3 - len(homepage.products)):
homepage.append('products', { homepage.append('products', {
'item_code': 'product-{0}'.format(i), 'item_code': 'product-{0}'.format(i),
'item_name': frappe._('Product {0}').format(i), 'item_name': frappe._('Product {0}').format(i),

View File

@ -18,7 +18,7 @@ def set_sales_target(args_data):
def create_customers(args_data): def create_customers(args_data):
args = json.loads(args_data) args = json.loads(args_data)
defaults = frappe.defaults.get_defaults() defaults = frappe.defaults.get_defaults()
for i in xrange(1,4): for i in range(1,4):
customer = args.get("customer_" + str(i)) customer = args.get("customer_" + str(i))
if customer: if customer:
try: try:
@ -56,7 +56,7 @@ def create_letterhead(args_data):
def create_suppliers(args_data): def create_suppliers(args_data):
args = json.loads(args_data) args = json.loads(args_data)
defaults = frappe.defaults.get_defaults() defaults = frappe.defaults.get_defaults()
for i in xrange(1,4): for i in range(1,4):
supplier = args.get("supplier_" + str(i)) supplier = args.get("supplier_" + str(i))
if supplier: if supplier:
try: try:
@ -89,7 +89,7 @@ def create_contact(contact, party_type, party):
def create_items(args_data): def create_items(args_data):
args = json.loads(args_data) args = json.loads(args_data)
defaults = frappe.defaults.get_defaults() defaults = frappe.defaults.get_defaults()
for i in xrange(1,4): for i in range(1,4):
item = args.get("item_" + str(i)) item = args.get("item_" + str(i))
if item: if item:
default_warehouse = "" default_warehouse = ""
@ -137,7 +137,7 @@ def make_item_price(item, price_list_name, item_price):
@frappe.whitelist() @frappe.whitelist()
def create_program(args_data): def create_program(args_data):
args = json.loads(args_data) args = json.loads(args_data)
for i in xrange(1,4): for i in range(1,4):
if args.get("program_" + str(i)): if args.get("program_" + str(i)):
program = frappe.new_doc("Program") program = frappe.new_doc("Program")
program.program_code = args.get("program_" + str(i)) program.program_code = args.get("program_" + str(i))
@ -150,7 +150,7 @@ def create_program(args_data):
@frappe.whitelist() @frappe.whitelist()
def create_course(args_data): def create_course(args_data):
args = json.loads(args_data) args = json.loads(args_data)
for i in xrange(1,4): for i in range(1,4):
if args.get("course_" + str(i)): if args.get("course_" + str(i)):
course = frappe.new_doc("Course") course = frappe.new_doc("Course")
course.course_code = args.get("course_" + str(i)) course.course_code = args.get("course_" + str(i))
@ -163,7 +163,7 @@ def create_course(args_data):
@frappe.whitelist() @frappe.whitelist()
def create_instructor(args_data): def create_instructor(args_data):
args = json.loads(args_data) args = json.loads(args_data)
for i in xrange(1,4): for i in range(1,4):
if args.get("instructor_" + str(i)): if args.get("instructor_" + str(i)):
instructor = frappe.new_doc("Instructor") instructor = frappe.new_doc("Instructor")
instructor.instructor_name = args.get("instructor_" + str(i)) instructor.instructor_name = args.get("instructor_" + str(i))
@ -175,7 +175,7 @@ def create_instructor(args_data):
@frappe.whitelist() @frappe.whitelist()
def create_room(args_data): def create_room(args_data):
args = json.loads(args_data) args = json.loads(args_data)
for i in xrange(1,4): for i in range(1,4):
if args.get("room_" + str(i)): if args.get("room_" + str(i)):
room = frappe.new_doc("Room") room = frappe.new_doc("Room")
room.room_name = args.get("room_" + str(i)) room.room_name = args.get("room_" + str(i))
@ -191,7 +191,7 @@ def create_users(args_data):
return return
args = json.loads(args_data) args = json.loads(args_data)
defaults = frappe.defaults.get_defaults() defaults = frappe.defaults.get_defaults()
for i in xrange(1,4): for i in range(1,4):
email = args.get("user_email_" + str(i)) email = args.get("user_email_" + str(i))
fullname = args.get("user_fullname_" + str(i)) fullname = args.get("user_fullname_" + str(i))
if email: if email: