Skip to content

Commit

Permalink
feat: prefill allowances table with selected date range (#60)
Browse files Browse the repository at this point in the history
Co-authored-by: barredterra <[email protected]>
  • Loading branch information
0xD0M1M0 and barredterra authored Feb 20, 2025
1 parent 057fd44 commit 6212319
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ trim_trailing_whitespace = true
charset = utf-8

# python, js indentation settings
[{*.py,*.js,*.vue}]
[{*.py,*.js,*.vue,*.css,*.scss,*.html}]
indent_style = tab
indent_size = 4
max_line_length = 99
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ frappe.ui.form.on("Business Trip", {
frm.set_query("region", (doc) => {
return {
filters: {
valid_from: ["<=", doc.from_date],
}
valid_from: ["<=", doc.from_date],
},
};
});
},
Expand Down Expand Up @@ -42,3 +42,35 @@ frappe.ui.form.on("Business Trip Accommodation", {
frappe.model.set_value(cdt, cdn, "to_date", frm.doc.to_date);
},
});

frappe.ui.form.on("Business Trip Allowance", {
allowances_add(frm) {
if (!frm.doc.from_date || !frm.doc.to_date) {
frappe.msgprint(__("Please enter a start and end date of the trip!"));
return;
}

let start = new Date(frm.doc.from_date);
let end = new Date(frm.doc.to_date);

if (end < start) {
frappe.msgprint(__("The end date should not be before the start date!"));
return;
}

if (frm.doc.allowances && frm.doc.allowances.length == 1 && !frm.doc.allowances[0].date) {
frm.clear_table("allowances");

for (let d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) {
let child = frm.add_child("allowances");
let d_string = d.toISOString().slice(0, 10);
frappe.model.set_value(child.doctype, child.name, "date", d_string);
if (d_string != frm.doc.from_date && d_string != frm.doc.to_date) {
frappe.model.set_value(child.doctype, child.name, "whole_day", true);
}
}

frm.refresh_field("allowances");
}
},
});

0 comments on commit 6212319

Please sign in to comment.