Filter activity type by project

Hello,

I’ve been using ERPNext for some days now in a testing environment. I really like it but I want to do some modifications to it. One modification is to allow me to create actvitity types per project. When we create timesheets entries in our current system we use different rates per project per customer. To get this working in a timesheet with ERPNext I though I would do the following:

  • Add a project link to activity types (done).

So now each actvitity type is linked to one project, so each project will get it’s own set of activity types to attach billing rates to.

  • The next part is to filter the timesheet detail activity type based on the selected project in the same grid

So in the picture above i’ve added project “SLA 2020 Vaste kosten” to the Activity Type “UItvoering”, but i’m also seeing other activity types which I don’t care about in this project. Imagine with our 500 projects per year and about 3 activity types per project, this list would get useless.

I’ve been trying to get this filter to work with a Custom Script but none seem to have brought me what I want.

Can anyone help me with a proper script for this?

I’ve just found the correct solution, seems a little rest did the trick:

frappe.ui.form.on('Timesheet', "refresh", function(frm) {
frm.fields_dict['time_logs'].grid.get_field('activity_type').get_query = function(doc, cdt, cdn) {
    var child = locals[cdt][cdn];
    console.log(child);
    return {    
        filters:[
            ['customer', '=', child.project]
        ]
    }
}

});