We generally have no use for the seconds slider in most datetime entries, and I’m always looking for ways to make the process of daily entries a little easier. I found through another post that setting Today as the default works well, but I was curious if there was a command via custom script that would be able to set a certain time aswell?
For example, Today, 8am as default
This post is very informative for setting days, but couldn’t tool around enough to make it add time/hours
Great news. I’m curious about the formatting. Datetimes are a single string, I’m assuming, and to keep a default as “today” but set a value for time, is that possible through setvalue? Or is it possible to use scripting to add hours/seconds to the default value onload?
In example, I’d like the date to be relative to the current, but the time to be specific, and I’m not sure besides “now” and “today” how I’d write that…
If that’s not the case, I may be on the search for how hours and date are called (if they end up in seperate fields upon submission)
Had a look into the moments.js. Very cool stuff can be done with that.
It took me a while, but I came mangled together the following script:
`
frappe.ui.form.on(“Time Log”, “refresh”, function(frm) {
if (frm.doc.islocal){
var d = moment().startOf(‘day’)
cur_frm.set_value(“from_time”, moment(d).add(8, ‘hours’))
refresh_field(“from_time”)
frm.add_custom_button((“7:30 start”), function() {
var d = moment().startOf(‘day’)
cur_frm.set_value(“from_time”, moment(d).add(7.5, ‘hours’))
refresh_field(“from_time”)
refresh_field(“hours”)
});
frm.add_custom_button(__("8:30 start"), function() {
var d = moment().startOf('day')
cur_frm.set_value("from_time", moment(d).add(8.5, 'hours'))
refresh_field("from_time")
});
}
});
`
but when the time log is saved, it throws the error following the snippet:
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/projects/doctype/time_log/time_log.py”, line 109, in validate_timings
if self.to_time and self.from_time and get_datetime(self.to_time) <= get_datetime(self.from_time):
TypeError: can’t compare offset-naive and offset-aware datetimes
Do I have to insert a recalculation script on each button press (and default time setting)? Or is there a method to call the recalculation for the doctype? Unless I’m just doing something odd, which is likely because I’m shooting in the dark when it comes to putting code together
edit: seems that I don’t even know how to put it in a code wrapper for this post. damn it