Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't assign new shift assignment in Roster for employees when start date and end date difference is more than 1 week #2394

Open
1 task done
Mahin-Abrar opened this issue Nov 7, 2024 · 2 comments
Assignees
Labels
bug Something isn't working can't replicate

Comments

@Mahin-Abrar
Copy link

Information about bug

In roster i wanted to assign an employee to a new shift but when i assign him within a week it is working fine . But when the start and end date difference is more than a week It shows up with an error .

Screenshot from 2024-11-07 10-34-45

Module

HR

Version

erpnext 15.41.0
frappe 15.47.0
hrms 15.34.0

Installation method

manual install

Relevant log output / Stack trace / Full Error Message.

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 114, in application
    response = frappe.api.handle(request)
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1781, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/hrms/hrms/api/roster.py", line 59, in create_shift_assignment_schedule
    return schedule.create_shifts(start_date, end_date)
  File "apps/hrms/hrms/hr/doctype/shift_assignment_schedule/shift_assignment_schedule.py", line 22, in create_shifts
    week_end_day = get_weekday(add_days(start_date, -1))
  File "apps/frappe/frappe/utils/data.py", line 716, in get_weekday
    return weekdays[datetime.weekday()]
AttributeError: 'str' object has no attribute 'weekday'

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
index-B9DvsdXp.js:175 Uncaught (in promise) Error: /api/method/hrms.api.roster.create_shift_assignment_schedule AttributeError
    at index-B9DvsdXp.js:175:1686
    at Generator.next (<anonymous>)
    at i (index-B9DvsdXp.js:2:668)

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Mahin-Abrar Mahin-Abrar added the bug Something isn't working label Nov 7, 2024
@Mahin-Abrar
Copy link
Author

Mahin-Abrar commented Nov 7, 2024

in the create shifts function get_weekday() accepts a date time object but a string was passed . i altered the code for testing and it is working. but i dont no if it will effect in any other section .
`

def create_shifts(self, start_date: str, end_date: str | None = None) -> None:
		gap = {
			"Every Week": 0,
			"Every 2 Weeks": 1,
			"Every 3 Weeks": 2,
			"Every 4 Weeks": 3,
		}[self.frequency]

		date = start_date
		individual_assignment_start = None
		# Convert the result of add_days to a date object
		week_end_day = get_weekday(getdate(add_days(start_date, -1)))
		repeat_on_days = [day.day for day in self.repeat_on_days]

		if not end_date:
			end_date = add_days(start_date, 90)

		while date <= end_date:
			# Convert date string to date object before getting weekday
			weekday = get_weekday(getdate(date))
			if weekday in repeat_on_days:
				if not individual_assignment_start:
					individual_assignment_start = date
				if date == end_date:
					self.create_individual_assignment(individual_assignment_start, date)

			elif individual_assignment_start:
				self.create_individual_assignment(individual_assignment_start, add_days(date, -1))
				individual_assignment_start = None

			if weekday == week_end_day and gap:
				if individual_assignment_start:
					self.create_individual_assignment(individual_assignment_start, date)
					individual_assignment_start = None
				date = add_days(date, 7 * gap)

			date = add_days(date, 1)

`

@krantheman
Copy link
Member

Unable to replicate currently.

The get_weekday function does convert string arguments to datetime objects (ref).

	if isinstance(datetime, str):
		datetime = get_datetime(datetime)

@krantheman krantheman self-assigned this Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working can't replicate
Projects
None yet
Development

No branches or pull requests

2 participants