Use range instead xrange (#13128)
* Use range instead of xrange * convert float to int
This commit is contained in:
		
							parent
							
								
									72d8509b3d
								
							
						
					
					
						commit
						96698c9a77
					
				| @ -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 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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 | ||||
| 		}) | ||||
|  | ||||
| @ -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)) | ||||
| 
 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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() | ||||
|  | ||||
| @ -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) | ||||
|  | ||||
| @ -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", | ||||
|  | ||||
| @ -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))) | ||||
|  | ||||
| @ -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 }) | ||||
|  | ||||
| @ -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: | ||||
|  | ||||
| @ -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] | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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) | ||||
| 
 | ||||
|  | ||||
| @ -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: | ||||
|  | ||||
| @ -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]) | ||||
|  | ||||
| @ -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) | ||||
|  | ||||
| @ -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), | ||||
|  | ||||
| @ -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: | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user