sheno
March 15, 2018, 8:04am
1
Dears i need an easy way to fulfill my need
i made a new doctype and named it Feed
i create a three filed in it
starttime --------- type time
endtime ----------- type time
difference ---------- type time
i need the filed difference= endtime - starttime
For example
if starttime = 02:00:20
endtime = 04:20:20
difference = 2:20
Exactly What i need to fulfil is to know how much time i spend
by using this equoation .
is there a way to make a custome script ? and choose my doctype feed against it ?
best regards
i will look, just a moment
1 Like
sheno
March 16, 2018, 12:50pm
4
Thank u brother waiting your help
sheno
March 16, 2018, 1:19pm
5
This is my attempts
1- the doctype name is feed
frappe@erpnext:~/frappe-bench/apps/erpnext/erpnext/healthcare/doctype/feed/
2- i edit the file feed.py
-- coding: utf-8 - -
Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
For license information, please see license.txt
from future import unicode_literals
import frappe
from frappe.model.document import Document
class Feed(Document):
def validate(self):
import frappe.utils
time_diff=frappe.utils.data.time_diff(self.endtime,self.starttime,)
self.difference=time_diff
But i didnt see any progress
Notes the three fileds
starttime
endtime
difference
all those type Date
sheno
March 16, 2018, 1:42pm
7
-- coding: utf-8 - -
Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
For license information, please see license.txt
from future import unicode_literals
import frappe
from frappe.model.document import Document
class Feed(Document):
def validate(self):
import frappe.utils
time_diff=frappe.utils.data.time_diff(self.endtime,self.starttime,)
self.difference=time_diff
self.save()
ah you want to put the code in feed.py?
thats not a custom script, but its also possible.
could you please insert your code here in a format which allows me to read it correct?
e.g.:
class Feed(Document):
def validate(self):
and so on...
then i can maybe say you whats wrong…
sheno
March 16, 2018, 1:49pm
10
joelios:
custom script
actually dear
i want to be a custom script because
it will easy for me to understand as i am not a coder
but after i searched a lot i find some guy say we have to put in doctyp.py
so i try his method but didnt work
so if it possible to be a custom script it will be so great and awsome
my need is
i need to get a number wich resemble the differnce between
Two time fileds
starttime ---- type time
endtime ----- type time
difference type (?) should it be Time Or data Or integer ??
the equoation aim mainly to get how many minute the difference between the start and the end time
for example
starttime 2:20:01
endtime 2:40:02
difference = (endtime-starttime)= 20 minute
i need to make it easy as possible to understand it and can fulfil it .
thanks brothers for your help/
@sheno this customscript should work:
frappe.ui.form.on('ToDo', {
refresh: function(frm) {
var start = frm.doc.starttime.split(":");
var end = frm.doc.endtime.split(":");
var date1 = new Date(2000, 0, 1, start[0], start[1]);
var date2 = new Date(2000, 0, 1, end[0], end[1]);
if (date2 < date1) {
date2.setDate(date2.getDate() + 1);
}
var diff = date2 - date1;
var msec = diff;
var hh = Math.floor(msec / 1000 / 60 / 60);
msec -= hh * 1000 * 60 * 60;
var mm = Math.floor(msec / 1000 / 60);
msec -= mm * 1000 * 60;
var ss = Math.floor(msec / 1000);
msec -= ss * 1000;
frm.set_value('difference', hh+":"+mm+":"+ss);
}
});
2 Likes
sheno
March 16, 2018, 2:04pm
14
Dear Joelios
i will try it now and feed u back.
you have to change “ToDo” to your Doctype!
1 Like
sheno
March 16, 2018, 2:05pm
16
should i use differnce type as a time or as int or as a data filed ?
i wrote this customscript for:
starttime → time
endtime → time
difference → time
1 Like
sheno
March 16, 2018, 2:07pm
18
joelios:
dif
i will try it now dear
and feed u back
sheno
March 16, 2018, 2:14pm
19
Dear Joelios
u did it man
really i am so so thankful for u .
1 Like