How to stop autofilling of Time filedtype on saving the doctype?

Currently I add “Time” as a filedtype in my doctype(Service2) of my custom app(seva_management). When I create new document and fills the values in fields except “Time” and save. It automatically takes the current time. This feature I want to stop. How I can achieve this?

Code I tried in my file

	def stop_now(self):
		if self.end_time:
			end_time = self.end_time
			end_time !=
			return self.end_time
			return None

	def on_update(self):
		end_time = self.stop_now()
		if end_time:
			self.end_time = end_time

Help please!

    def before_save(self):
        if self.end_time:
            # Clear the end_time field if it's set
            self.end_time = None

Try it. also use the ‘on_update’ method.

@NCP should i keep this part ?

No @adi09

Please try it.

Hey @NCP This code is banning the autofilling of end_time as time but my requirement is i want to fill it manually. Currently if this field end_time i keep empty and save the documnet it automatically takes current time. But i want to fill it manually and if i do not fill it manually then only it should be banned.
How can i do that?

        if not self.end_time:
            self.end_time = None

@NCP This also is not working. This code is giving the same result as it gives without any code(defaultly takes current time). Wherease the code:

    def before_save(self):
        if self.end_time:
            # Clear the end_time field if it's set
            self.end_time = None

replaces the manual value of end_time with None and after saving the value in End Time obtain is empty.

What exactly do you need? Could you provide a video or image? Also, could you explain the specific problem you’re facing? If it’s a standard document type, you can override it, but if it’s a custom one, you can adjust it to fit your needs.

Let’s say you have 2 time fields in any doctype. For ex: Start Time & End Time.
When you fill only Start time, End time should be null, but if no value is provided then it is taking current time.

According to what @Sandeep_Kakde said, the script will appear like this:

def before_save(doc, method):
    if doc.start_time and not doc.end_time:
        doc.end_time = None
    elif not doc.start_time and not doc.end_time:
        doc.end_time = frappe.utils.now_datetime()

No @NCP @Sandeep_Kakde then also it should be null. It should be filled/take values only when I fill it using this:
or manually

Yes if no value is provided then it should be null & not auto populate it with the current time.

1 Like

If have no code, then can’t be auto populate. It’s become a none and I think no code is required for it. and @Sandeep_Kakde is right.

Check on Version 15, it is auto-populating.
Follow the following steps:

  1. Create a doctype with 2 time fields. Let’s say Start Time & End Time.
  2. Now create a new record & select only start time.

Expected O/P: Record should contain the selected start time & empty end time.

Actual O/P: Record contains the selected start time & autopopulated current time in end time field.

We want to stop this auto-population of end time.

Yes @NCP this is my exact problem. In fact If Start Time also I keep empty, after saving it gets auto-populated. I am using version 15 of frappe

Please verify if any default value is set or not for fields.
Otherwise, please share the video with us for better understanding.

Hey @NCP @Sandeep_Kakde I am not able to send video directly here, there is no option for that ig, so i am sending using a website:

  1. In Normal condition when we saved without giving any values both in Start Time or End Time
    Auto-population of Start Time and End Time

  2. Checking the default value of field:
    Checking Dafault value

  3. When Default is set to None by me:
    When I set default as None

@Sandeep_Kakde @NCP Any update? I have shared videos!

I agree with you. When you save the doctype, it automatically sets the default value if the field type is “Time.” Similarly, this applies to the field type “Int” where it sets the value to 0. In your situation, it seems that the default current time value is being set.

Then what can be done in that case to stop this feature?