fix: pause button not working for sub-operation

This commit is contained in:
Rohit Waghchaure
2025-10-31 16:36:14 +05:30
parent e43c2ac5c1
commit 1f183a7e06
2 changed files with 34 additions and 3 deletions

View File

@@ -199,7 +199,10 @@ frappe.ui.form.on("Job Card", {
last_row = get_last_row(frm.doc.time_logs);
}
if (!frm.doc.time_logs?.length || (frm.doc.sub_operations?.length && last_row?.to_time)) {
if (
(!frm.doc.time_logs?.length || (frm.doc.sub_operations?.length && last_row?.to_time)) &&
!frm.doc.is_paused
) {
frm.add_custom_button(__("Start Job"), () => {
let from_time = frappe.datetime.now_datetime();
if ((frm.doc.employee && !frm.doc.employee.length) || !frm.doc.employee) {
@@ -327,6 +330,26 @@ frappe.ui.form.on("Job Card", {
},
];
if (frm.doc.sub_operations?.length) {
fields.push({
fieldtype: "Link",
label: __("Sub Operation"),
fieldname: "sub_operation",
options: "Operation",
get_query() {
let non_completed_operations = frm.doc.sub_operations.filter(
(d) => d.status === "Pending"
);
return {
filters: {
name: ["in", non_completed_operations.map((d) => d.sub_operation)],
},
};
},
reqd: 1,
});
}
let last_completed_row = get_last_completed_row(frm.doc.time_logs);
let last_row = {};
if (frm.doc.sub_operations?.length && frm.doc.time_logs?.length) {
@@ -356,6 +379,7 @@ frappe.ui.form.on("Job Card", {
qty: data.completed_qty,
for_quantity: data.for_quantity,
end_time: data.end_time,
sub_operation: data.sub_operation,
},
callback: function (r) {
frm.reload_doc();

View File

@@ -643,7 +643,7 @@ class JobCard(Document):
op_row.employee.append(time_log.employee)
if time_log.time_in_mins:
op_row.completed_time += time_log.time_in_mins
op_row.completed_qty += time_log.completed_qty
op_row.completed_qty += flt(time_log.completed_qty)
for row in self.sub_operations:
operation_deatils = operation_wise_completed_time.get(row.sub_operation)
@@ -1224,6 +1224,8 @@ class JobCard(Document):
row.to_time = kwargs.to_time
row.time_in_mins = time_diff_in_minutes(row.to_time, row.from_time)
if kwargs.get("sub_operation"):
row.operation = kwargs.get("sub_operation")
if kwargs.employees[-1].get("employee") == row.employee:
row.completed_qty = kwargs.completed_qty
@@ -1276,7 +1278,12 @@ class JobCard(Document):
kwargs = frappe._dict(kwargs)
if kwargs.end_time:
self.add_time_logs(to_time=kwargs.end_time, completed_qty=kwargs.qty, employees=self.employee)
self.add_time_logs(
to_time=kwargs.end_time,
completed_qty=kwargs.qty,
employees=self.employee,
sub_operation=kwargs.get("sub_operation"),
)
if kwargs.for_quantity:
self.for_quantity = kwargs.for_quantity