Skip to content

Commit

Permalink
feat: update whole_day times (#61)
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 6d7f915 commit 757d6c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ frappe.ui.form.on("Business Trip Allowance", {
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) {

if (d_string == frm.doc.from_date) {
frappe.model.set_value(child.doctype, child.name, "to_time", "23:59");
} else if (d_string == frm.doc.to_date) {
frappe.model.set_value(child.doctype, child.name, "from_time", "00:00");
} else {
frappe.model.set_value(child.doctype, child.name, "whole_day", true);
frappe.model.set_value(child.doctype, child.name, "from_time", "00:00");
frappe.model.set_value(child.doctype, child.name, "to_time", "23:59");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class BusinessTrip(Document):
def before_save(self):
self.set_regional_amount()
self.set_whole_day_time()
self.calculate_total()

def validate(self):
Expand Down Expand Up @@ -39,6 +40,12 @@ def set_regional_amount(self):

allowance.amount = max(amount, 0.0)

def set_whole_day_time(self):
for allowance in self.allowances:
if allowance.whole_day:
allowance.from_time = "00:00"
allowance.to_time = "23:59"

def calculate_total(self):
self.total_allowance = sum(allowance.amount for allowance in self.allowances)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@
},
{
"columns": 1,
"depends_on": "eval:!doc.whole_day",
"fieldname": "from_time",
"fieldtype": "Time",
"label": "From Time",
"mandatory_depends_on": "eval:!doc.whole_day"
"mandatory_depends_on": "eval:!doc.whole_day",
"read_only_depends_on": "eval:doc.whole_day"
},
{
"depends_on": "eval:!doc.whole_day",
"fieldname": "to_time",
"fieldtype": "Time",
"label": "To Time",
"mandatory_depends_on": "eval:!doc.whole_day"
"mandatory_depends_on": "eval:!doc.whole_day",
"read_only_depends_on": "eval:doc.whole_day"
},
{
"columns": 2,
Expand Down Expand Up @@ -90,7 +90,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-09-04 22:59:26.731082",
"modified": "2025-02-20 15:25:04.594624",
"modified_by": "Administrator",
"module": "ERPNext Germany",
"name": "Business Trip Allowance",
Expand Down

0 comments on commit 757d6c6

Please sign in to comment.