From 96698c9a77f66b179f4d0c5fb84e484dcd985739 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Wed, 28 Feb 2018 16:12:51 +0530 Subject: [PATCH] Use range instead xrange (#13128) * Use range instead of xrange * convert float to int --- .../doctype/sales_invoice/test_sales_invoice.py | 2 +- .../doctype/shipping_rule/shipping_rule.py | 4 ++-- erpnext/accounts/report/financial_statements.py | 2 +- erpnext/assets/doctype/asset/asset.py | 8 ++++---- erpnext/controllers/trends.py | 2 +- erpnext/demo/demo.py | 2 +- erpnext/demo/setup/healthcare.py | 4 ++-- erpnext/demo/setup/setup_data.py | 2 +- erpnext/demo/user/education.py | 4 ++-- erpnext/demo/user/purchase.py | 2 +- erpnext/demo/user/sales.py | 10 +++++----- .../student_and_guardian_contact_details.py | 2 +- .../hotel_room_reservation.py | 4 ++-- .../hotel_room_occupancy/hotel_room_occupancy.py | 2 +- .../maintenance_schedule/maintenance_schedule.py | 2 +- .../customer_acquisition_and_loyalty.py | 4 ++-- erpnext/stock/doctype/serial_no/serial_no.py | 2 +- erpnext/templates/pages/home.py | 2 +- erpnext/utilities/user_progress_utils.py | 16 ++++++++-------- 19 files changed, 38 insertions(+), 38 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index b866794b89..3fa16f7618 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 @@ class TestSalesInvoice(unittest.TestCase): 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 08e2018bb5..a20f5c0872 100644 --- a/erpnext/accounts/doctype/shipping_rule/shipping_rule.py +++ b/erpnext/accounts/doctype/shipping_rule/shipping_rule.py @@ -133,8 +133,8 @@ class ShippingRule(Document): 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 da8214a851..f3e52031ed 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -38,7 +38,7 @@ def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, accumulated_v 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 bd33a1b211..cb14484916 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -114,15 +114,15 @@ class Asset(Document): 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 @@ class Asset(Document): "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 c5db2239b3..ef698c2a16 100644 --- a/erpnext/controllers/trends.py +++ b/erpnext/controllers/trends.py @@ -182,7 +182,7 @@ def get_period_date_ranges(period, fiscal_year=None, year_start_date=None): }.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 42ef8963bc..f765469499 100644 --- a/erpnext/demo/demo.py +++ b/erpnext/demo/demo.py @@ -63,7 +63,7 @@ def simulate(domain='Manufacturing', days=100): # 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 d645e309f8..b48e0bcbc1 100644 --- a/erpnext/demo/setup/healthcare.py +++ b/erpnext/demo/setup/healthcare.py @@ -65,7 +65,7 @@ def make_appointment(): 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 @@ def make_consulation(): 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 64a04d57d7..4ed4df9176 100644 --- a/erpnext/demo/setup/setup_data.py +++ b/erpnext/demo/setup/setup_data.py @@ -80,7 +80,7 @@ def setup_demo_page(): 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 8c82f879ab..4fc9c6abc5 100644 --- a/erpnext/demo/user/education.py +++ b/erpnext/demo/user/education.py @@ -15,7 +15,7 @@ from erpnext.education.api import get_student_group_students, make_attendance_re 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 @@ def make_course_schedule(start_date, end_date): 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 8769b09156..d9fc1f3c4a 100644 --- a/erpnext/demo/user/purchase.py +++ b/erpnext/demo/user/purchase.py @@ -116,7 +116,7 @@ def make_material_request(item_code, qty): 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 54ea173f87..2fd2565aad 100644 --- a/erpnext/demo/user/sales.py +++ b/erpnext/demo/user/sales.py @@ -13,27 +13,27 @@ from erpnext.accounts.doctype.payment_request.payment_request import make_paymen 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 641b78372c..19136ea9c9 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 @@ def execute(filters=None): 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 f3f76a9218..9a81405c5d 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 @@ class HotelRoomReservation(Document): 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 @@ class HotelRoomReservation(Document): 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 aebeb4578f..f77d43b314 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 @@ def get_data(filters): 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 fa3bcf5b2a..6015bd6917 100644 --- a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py @@ -112,7 +112,7 @@ class MaintenanceSchedule(TransactionBase): 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 bf274cd13d..4509904249 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 @@ def execute(filters=None): 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 80c93ef434..0520a8d3f0 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -272,7 +272,7 @@ def update_serial_nos(sle, item_det): 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 9a4c89c812..82d525ac77 100644 --- a/erpnext/templates/pages/home.py +++ b/erpnext/templates/pages/home.py @@ -19,7 +19,7 @@ def get_context(context): # 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 58a03e3af3..bc89b08cf2 100644 --- a/erpnext/utilities/user_progress_utils.py +++ b/erpnext/utilities/user_progress_utils.py @@ -18,7 +18,7 @@ def set_sales_target(args_data): 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_letterhead(args_data): 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_contact(contact, party_type, party): 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 @@ def make_item_price(item, price_list_name, item_price): @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 @@ def create_program(args_data): @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 @@ def create_course(args_data): @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 @@ def create_instructor(args_data): @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 @@ def create_users(args_data): 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: