Custom script help , advice

Hello there. We are currently testing erpnext platform.

I am quite new in this, so i would like to ask you some details.

I am trying to make weekly timesheet. I created parent doctype Timesheet and child Timesheet detail. Now I am struggling on these 3 problems.

  1. Each line in chid table represent hours on the selected project per week. I would like to calculate total hours per week to show this info on parent Weekly Timesheet

Edit :
Here is what i have :

frappe.ui.form.on("Weekly Timesheet", {
    validate: function(frm) {
        total_hours = 0
        $.each(frm.doc.sheets), function(i, d) {    //go over all the lines and calculate total monday hours 
            total_hours += flt(d.monday)
        };

    frm.set_value("totalhrs", total_hours)    //set value on the timesheet
    frm.refresh()     //refresh page , not sure about this , just to show the calculated value
    }
})
  • sheets is child table, but after I save the timesheet, it remains frozen.
  1. Somehow if i am using regular OOTB timesheet, the hours are added to the Project , where is this connection ? I wke to also weekly timesheet hours added to the projects

3)Is there a way to create records in OOTB timesheet according to my weekly timesheet. I mean the situation where I Crete weekly timesheet the records of OOTB timesheet will be created per day.

Also can you give me a hint on where I can find more details on scripring ? The few examples that i found was not sufficient for me to create more complex scripts. Is there any Intelisense function in some IDE for this type of scripting?

Sorry for long question.

Looking forward to your replies,

Regards Juraj

Can you explain better what you’re trying to create a separate for a weekly timesheet? I believe the current system can more than accommodate what you’re trying to do. You just create a Timesheet and add Timesheet details (rows to the table) on a weekly basis - it will prevent a huge amount of duplication. If there are specific things you are looking to do, you probably can customize the current Timesheet.

There are quite a few examples for the scripting, but the best place is looking at the Frappe · GitHub repositories. The javascript code is all usable in the custom script forms. As well, there are many examples in the frappe wiki:
Home · frappe/frappe Wiki · GitHub

Dear Ben,

thanks for reply.

I checked again the OOTB timesheet functionality. i think we might use OOTB timesheet after some modification.This is currently how it’s looking. (I changed the date and hours per day)

Timesheet Detail :

This is what is desired : Layout will be updated

my point is to have not hours per day but hours per week. So total hours per project will be per week. And this hours will be add to the project. Total hours per week will be calculated (summary of rows for different projects per week and it will be displayed on Timesheet form (not timesheet detail))

On the Timesheet level there should be a control to show week. and for each week there will be weekly timesheet row.

Is this achievable ?

Thanks!

Regards, Juraj

Hi there,

so I created custom fields on “Timesheet Detail”

field are “Mon” , “Tue”, “Wed”, “Thu”, “Fri”

Also there is OOTB field “hours”

I want to canculate “hours” automatically when I enter value to some of days do at the end, hours = mon + tue + …

frappe.ui.form.on("Timesheet Detail", "hours", function(frm) {
  frm.set_value("hours", frm.doc.mon + frm.doc.tue + frm.doc.wed + frm.doc.thu + frm.doc.frii + frm.doc.sat + frm.doc.sun);
});

Any idea what am I doing wrong ? Also is there some way for field to be refreshed after each value entered for days or this is always calculated after submit ?

Thanks!

Regards,

Juraj