Use range instead xrange (#13128)
* Use range instead of xrange
* convert float to int
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index b866794..3fa16f7 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -418,7 +418,7 @@
si.get("items")[0].price_list_rate = 62.5
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
# tax type "Actual" cannot be inclusive
diff --git a/erpnext/accounts/doctype/shipping_rule/shipping_rule.py b/erpnext/accounts/doctype/shipping_rule/shipping_rule.py
index 08e2018..a20f5c0 100644
--- a/erpnext/accounts/doctype/shipping_rule/shipping_rule.py
+++ b/erpnext/accounts/doctype/shipping_rule/shipping_rule.py
@@ -133,8 +133,8 @@
return (not separate)
overlaps = []
- for i in xrange(0, len(self.conditions)):
- for j in xrange(i+1, len(self.conditions)):
+ for i in range(0, len(self.conditions)):
+ for j in range(i+1, len(self.conditions)):
d1, d2 = self.conditions[i], self.conditions[j]
if d1.as_dict() != d2.as_dict():
# in our case, to_value can be zero, hence pass the from_value if so
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index da8214a..f3e5203 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -38,7 +38,7 @@
start_date = year_start_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({
"from_date": start_date
})
diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py
index bd33a1b..cb14484 100644
--- a/erpnext/assets/doctype/asset/asset.py
+++ b/erpnext/assets/doctype/asset/asset.py
@@ -114,15 +114,15 @@
and getdate(self.next_depreciation_date) < next_depr_date):
number_of_pending_depreciations += 1
- for n in xrange(number_of_pending_depreciations):
- if n == xrange(number_of_pending_depreciations)[-1]:
+ for n in range(number_of_pending_depreciations):
+ if n == range(number_of_pending_depreciations)[-1]:
schedule_date = add_months(self.available_for_use_date, n * 12)
previous_scheduled_date = add_months(self.next_depreciation_date, (n-1) * 12)
depreciation_amount = \
self.get_depreciation_amount_prorata_temporis(value_after_depreciation,
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
depreciation_amount = \
self.get_depreciation_amount_prorata_temporis(value_after_depreciation,
@@ -141,7 +141,7 @@
"depreciation_amount": depreciation_amount
})
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,
n * cint(self.frequency_of_depreciation))
diff --git a/erpnext/controllers/trends.py b/erpnext/controllers/trends.py
index c5db223..ef698c2 100644
--- a/erpnext/controllers/trends.py
+++ b/erpnext/controllers/trends.py
@@ -182,7 +182,7 @@
}.get(period)
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)
if period_end_date > getdate(year_end_date):
period_end_date = year_end_date
diff --git a/erpnext/demo/demo.py b/erpnext/demo/demo.py
index 42ef896..f765469 100644
--- a/erpnext/demo/demo.py
+++ b/erpnext/demo/demo.py
@@ -63,7 +63,7 @@
# runs_for = 100
fixed_asset.work()
- for i in xrange(runs_for):
+ for i in range(runs_for):
sys.stdout.write("\rSimulating {0}: Day {1}".format(
current_date.strftime("%Y-%m-%d"), i))
sys.stdout.flush()
diff --git a/erpnext/demo/setup/healthcare.py b/erpnext/demo/setup/healthcare.py
index d645e30..b48e0bc 100644
--- a/erpnext/demo/setup/healthcare.py
+++ b/erpnext/demo/setup/healthcare.py
@@ -65,7 +65,7 @@
i += 1
def make_consulation():
- for i in xrange(3):
+ for i in range(3):
physician = get_random("Physician")
department = frappe.get_value("Physician", physician, "department")
patient = get_random("Patient")
@@ -74,7 +74,7 @@
consultation.save(ignore_permissions=True)
def consulation_on_appointment():
- for i in xrange(3):
+ for i in range(3):
appointment = get_random("Patient Appointment")
appointment = frappe.get_doc("Patient Appointment",appointment)
consultation = set_consultation(appointment.patient, appointment.patient_sex, appointment.physician, appointment.department, appointment.appointment_date, i)
diff --git a/erpnext/demo/setup/setup_data.py b/erpnext/demo/setup/setup_data.py
index 64a04d5..4ed4df9 100644
--- a/erpnext/demo/setup/setup_data.py
+++ b/erpnext/demo/setup/setup_data.py
@@ -80,7 +80,7 @@
def setup_fiscal_year():
fiscal_year = None
- for year in xrange(2010, now_datetime().year + 1, 1):
+ for year in range(2010, now_datetime().year + 1, 1):
try:
fiscal_year = frappe.get_doc({
"doctype": "Fiscal Year",
diff --git a/erpnext/demo/user/education.py b/erpnext/demo/user/education.py
index 8c82f87..4fc9c6a 100644
--- a/erpnext/demo/user/education.py
+++ b/erpnext/demo/user/education.py
@@ -15,7 +15,7 @@
def work():
frappe.set_user(frappe.db.get_global('demo_education_user'))
- for d in xrange(20):
+ for d in range(20):
approve_random_student_applicant()
enroll_random_student(frappe.flags.current_date)
# if frappe.flags.current_date.weekday()== 0:
@@ -94,7 +94,7 @@
cs.course_start_date = cstr(start_date)
cs.course_end_date = cstr(end_date)
day = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
- for x in xrange(3):
+ for x in range(3):
random_day = random.choice(day)
cs.day = random_day
cs.from_time = timedelta(hours=(random.randrange(7, 17,1)))
diff --git a/erpnext/demo/user/purchase.py b/erpnext/demo/user/purchase.py
index 8769b09..d9fc1f3 100644
--- a/erpnext/demo/user/purchase.py
+++ b/erpnext/demo/user/purchase.py
@@ -116,7 +116,7 @@
return mr
def add_suppliers(rfq):
- for i in xrange(2):
+ for i in range(2):
supplier = get_random("Supplier")
if supplier not in [d.supplier for d in rfq.get('suppliers')]:
rfq.append("suppliers", { "supplier": supplier })
diff --git a/erpnext/demo/user/sales.py b/erpnext/demo/user/sales.py
index 54ea173..2fd2565 100644
--- a/erpnext/demo/user/sales.py
+++ b/erpnext/demo/user/sales.py
@@ -13,27 +13,27 @@
def work():
frappe.set_user(frappe.db.get_global('demo_sales_user_2'))
if random.random() < 0.5:
- for i in xrange(random.randint(1,7)):
+ for i in range(random.randint(1,7)):
make_opportunity()
if random.random() < 0.5:
- for i in xrange(random.randint(1,3)):
+ for i in range(random.randint(1,3)):
make_quotation()
# lost quotations / inquiries
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)
if quotation and quotation.status == 'Submitted':
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)
if opportunity and opportunity.status in ('Open', 'Replied'):
opportunity.declare_enquiry_lost('Did not ask')
if random.random() < 0.3:
- for i in xrange(random.randint(1,3)):
+ for i in range(random.randint(1,3)):
make_sales_order()
if random.random() < 0.1:
diff --git a/erpnext/education/report/student_and_guardian_contact_details/student_and_guardian_contact_details.py b/erpnext/education/report/student_and_guardian_contact_details/student_and_guardian_contact_details.py
index 641b783..19136ea 100644
--- a/erpnext/education/report/student_and_guardian_contact_details/student_and_guardian_contact_details.py
+++ b/erpnext/education/report/student_and_guardian_contact_details/student_and_guardian_contact_details.py
@@ -34,7 +34,7 @@
student_guardians = guardian_map.get(d.student)
if student_guardians:
- for i in xrange(2):
+ for i in range(2):
if i < len(student_guardians):
g = student_guardians[i]
row += [g.guardian_name, g.relation, g.mobile_number, g.email_address]
diff --git a/erpnext/hotels/doctype/hotel_room_reservation/hotel_room_reservation.py b/erpnext/hotels/doctype/hotel_room_reservation/hotel_room_reservation.py
index f3f76a9..9a81405 100644
--- a/erpnext/hotels/doctype/hotel_room_reservation/hotel_room_reservation.py
+++ b/erpnext/hotels/doctype/hotel_room_reservation/hotel_room_reservation.py
@@ -18,7 +18,7 @@
self.validate_availability()
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)
self.rooms_booked = {}
@@ -54,7 +54,7 @@
self.net_total = 0
for d in self.items:
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)
if not d.item:
continue
diff --git a/erpnext/hotels/report/hotel_room_occupancy/hotel_room_occupancy.py b/erpnext/hotels/report/hotel_room_occupancy/hotel_room_occupancy.py
index aebeb45..f77d43b 100644
--- a/erpnext/hotels/report/hotel_room_occupancy/hotel_room_occupancy.py
+++ b/erpnext/hotels/report/hotel_room_occupancy/hotel_room_occupancy.py
@@ -24,7 +24,7 @@
out = []
for room_type in frappe.get_all('Hotel Room Type'):
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)
total_booked += get_rooms_booked(room_type.name, day)
diff --git a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py
index fa3bcf5..6015bd6 100644
--- a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py
+++ b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py
@@ -112,7 +112,7 @@
if not validated and holidays:
# max iterations = len(holidays)
- for i in xrange(len(holidays)):
+ for i in range(len(holidays)):
if schedule_date in holidays:
schedule_date = add_days(schedule_date, -1)
else:
diff --git a/erpnext/selling/report/customer_acquisition_and_loyalty/customer_acquisition_and_loyalty.py b/erpnext/selling/report/customer_acquisition_and_loyalty/customer_acquisition_and_loyalty.py
index bf274cd..4509904 100644
--- a/erpnext/selling/report/customer_acquisition_and_loyalty/customer_acquisition_and_loyalty.py
+++ b/erpnext/selling/report/customer_acquisition_and_loyalty/customer_acquisition_and_loyalty.py
@@ -41,8 +41,8 @@
cint(from_year), cint(from_month), cint(to_year), cint(to_month)
out = []
- for year in xrange(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 year in range(from_year, to_year+1):
+ 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)
new = new_customers_in.get(key, [0,0.0])
diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py
index 80c93ef..0520a8d 100644
--- a/erpnext/stock/doctype/serial_no/serial_no.py
+++ b/erpnext/stock/doctype/serial_no/serial_no.py
@@ -272,7 +272,7 @@
and item_det.has_serial_no == 1 and item_det.serial_no_series:
from frappe.model.naming import make_autoname
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"))
frappe.db.set(sle, "serial_no", "\n".join(serial_nos))
validate_serial_no(sle, item_det)
diff --git a/erpnext/templates/pages/home.py b/erpnext/templates/pages/home.py
index 9a4c89c..82d525a 100644
--- a/erpnext/templates/pages/home.py
+++ b/erpnext/templates/pages/home.py
@@ -19,7 +19,7 @@
# show atleast 3 products
if len(homepage.products) < 3:
- for i in xrange(3 - len(homepage.products)):
+ for i in range(3 - len(homepage.products)):
homepage.append('products', {
'item_code': 'product-{0}'.format(i),
'item_name': frappe._('Product {0}').format(i),
diff --git a/erpnext/utilities/user_progress_utils.py b/erpnext/utilities/user_progress_utils.py
index 58a03e3..bc89b08 100644
--- a/erpnext/utilities/user_progress_utils.py
+++ b/erpnext/utilities/user_progress_utils.py
@@ -18,7 +18,7 @@
def create_customers(args_data):
args = json.loads(args_data)
defaults = frappe.defaults.get_defaults()
- for i in xrange(1,4):
+ for i in range(1,4):
customer = args.get("customer_" + str(i))
if customer:
try:
@@ -56,7 +56,7 @@
def create_suppliers(args_data):
args = json.loads(args_data)
defaults = frappe.defaults.get_defaults()
- for i in xrange(1,4):
+ for i in range(1,4):
supplier = args.get("supplier_" + str(i))
if supplier:
try:
@@ -89,7 +89,7 @@
def create_items(args_data):
args = json.loads(args_data)
defaults = frappe.defaults.get_defaults()
- for i in xrange(1,4):
+ for i in range(1,4):
item = args.get("item_" + str(i))
if item:
default_warehouse = ""
@@ -137,7 +137,7 @@
@frappe.whitelist()
def create_program(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)):
program = frappe.new_doc("Program")
program.program_code = args.get("program_" + str(i))
@@ -150,7 +150,7 @@
@frappe.whitelist()
def create_course(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)):
course = frappe.new_doc("Course")
course.course_code = args.get("course_" + str(i))
@@ -163,7 +163,7 @@
@frappe.whitelist()
def create_instructor(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)):
instructor = frappe.new_doc("Instructor")
instructor.instructor_name = args.get("instructor_" + str(i))
@@ -175,7 +175,7 @@
@frappe.whitelist()
def create_room(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)):
room = frappe.new_doc("Room")
room.room_name = args.get("room_" + str(i))
@@ -191,7 +191,7 @@
return
args = json.loads(args_data)
defaults = frappe.defaults.get_defaults()
- for i in xrange(1,4):
+ for i in range(1,4):
email = args.get("user_email_" + str(i))
fullname = args.get("user_fullname_" + str(i))
if email: