Environment
- ERPNext: 15.102.0
- Frappe: 15.103.1
- URY: 0.2.1
Error
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str'
Location
ury/ury/hooks/ury_pos_invoice.py line 93 — calculate_and_set_times()
Traceback
File "apps/ury/ury/ury/hooks/ury_pos_invoice.py", line 93, in calculate_and_set_times
time_difference = current_time - doc.creation
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str'
Cause
current_time is a datetime object created via datetime.strptime()
but doc.creation arrives as a string when submitted via the API/form.
Subtracting a datetime from a str raises TypeError.
Fix
Convert doc.creation to datetime before the subtraction:
# Before (broken)
time_difference = current_time - doc.creation
# After (fixed)
time_difference = current_time - datetime.strptime(str(doc.creation), "%Y-%m-%d %H:%M:%S.%f")
Fixed function
def calculate_and_set_times(doc, method):
doc.arrived_time = doc.creation
current_time_str = now()
current_time = datetime.strptime(current_time_str, "%Y-%m-%d %H:%M:%S.%f")
time_difference = current_time - datetime.strptime(str(doc.creation), "%Y-%m-%d %H:%M:%S.%f")
total_seconds = int(time_difference.total_seconds())
hours, remainder = divmod(total_seconds, 3600)
minutes, seconds = divmod(remainder, 60)
formatted_spend_time = f"{hours:02d}:{minutes:02d}:{seconds:02d}"
doc.total_spend_time = formatted_spend_time
Impact
POS Invoice cannot be submitted through the ERPNext UI or API
when URY is installed. Affects all restaurants using URY on ERPNext v15.
Environment
Error
Location
ury/ury/hooks/ury_pos_invoice.pyline 93 —calculate_and_set_times()Traceback
Cause
current_timeis adatetimeobject created viadatetime.strptime()but
doc.creationarrives as a string when submitted via the API/form.Subtracting a
datetimefrom astrraisesTypeError.Fix
Convert
doc.creationto datetime before the subtraction:Fixed function
Impact
POS Invoice cannot be submitted through the ERPNext UI or API
when URY is installed. Affects all restaurants using URY on ERPNext v15.