mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-05 03:23:35 +00:00
Merge pull request #46732 from rohitwaghchaure/fixed-job-card-hours-issue
fix: not able to set hours manually in job card
This commit is contained in:
@@ -86,6 +86,11 @@ frappe.ui.form.on("Job Card", {
|
||||
|
||||
frm.toggle_enable("for_quantity", !has_stock_entry);
|
||||
|
||||
if (frm.doc.docstatus != 0) {
|
||||
frm.fields_dict["time_logs"].grid.update_docfield_property("completed_qty", "read_only", 1);
|
||||
frm.fields_dict["time_logs"].grid.update_docfield_property("time_in_mins", "read_only", 1);
|
||||
}
|
||||
|
||||
if (!frm.is_new() && !frm.doc.skip_material_transfer && has_items && frm.doc.docstatus < 2) {
|
||||
let to_request = frm.doc.for_quantity > frm.doc.transferred_qty;
|
||||
let excess_transfer_allowed = frm.doc.__onload.job_card_excess_transfer;
|
||||
@@ -219,13 +224,17 @@ frappe.ui.form.on("Job Card", {
|
||||
reqd: 1,
|
||||
default: frm.doc.for_quantity - frm.doc.total_completed_qty,
|
||||
},
|
||||
{
|
||||
];
|
||||
|
||||
let last_completed_row = get_last_completed_row(frm.doc.time_logs);
|
||||
if (!last_completed_row || !last_completed_row.to_time) {
|
||||
fields.push({
|
||||
fieldtype: "Datetime",
|
||||
label: __("End Time"),
|
||||
fieldname: "end_time",
|
||||
default: frappe.datetime.now_datetime(),
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
frappe.prompt(
|
||||
fields,
|
||||
@@ -626,8 +635,31 @@ frappe.ui.form.on("Job Card Time Log", {
|
||||
to_time: function (frm) {
|
||||
frm.set_value("started_time", "");
|
||||
},
|
||||
|
||||
time_in_mins(frm, cdt, cdn) {
|
||||
let d = locals[cdt][cdn];
|
||||
if (d.time_in_mins) {
|
||||
d.to_time = add_mins_to_time(d.from_time, d.time_in_mins);
|
||||
frappe.model.set_value(cdt, cdn, "to_time", d.to_time);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
function get_seconds_diff(d1, d2) {
|
||||
return moment(d1).diff(d2, "seconds");
|
||||
}
|
||||
|
||||
function add_mins_to_time(datetime, mins) {
|
||||
let new_date = moment(datetime).add(mins, "minutes");
|
||||
|
||||
return new_date.format("YYYY-MM-DD HH:mm:ss");
|
||||
}
|
||||
|
||||
function get_last_completed_row(time_logs) {
|
||||
let completed_rows = time_logs.filter((d) => d.to_time);
|
||||
|
||||
if (completed_rows?.length) {
|
||||
let last_completed_row = completed_rows[completed_rows.length - 1];
|
||||
return last_completed_row;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -525,7 +525,7 @@
|
||||
"fieldname": "finished_good",
|
||||
"fieldtype": "Link",
|
||||
"in_preview": 1,
|
||||
"label": "Finished Good",
|
||||
"label": "Item to Manufacture",
|
||||
"options": "Item",
|
||||
"read_only": 1
|
||||
},
|
||||
@@ -555,7 +555,7 @@
|
||||
{
|
||||
"fieldname": "semi_fg_bom",
|
||||
"fieldtype": "Link",
|
||||
"label": "Semi Finished Goods BOM",
|
||||
"label": "Manufacturing BOM",
|
||||
"options": "BOM",
|
||||
"read_only": 1
|
||||
},
|
||||
@@ -612,9 +612,10 @@
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"grid_page_length": 50,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2024-06-03 17:44:18.324743",
|
||||
"modified": "2025-03-25 17:50:18.608869",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "Job Card",
|
||||
@@ -667,10 +668,11 @@
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"row_format": "Dynamic",
|
||||
"show_preview_popup": 1,
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"title_field": "operation",
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1187,6 +1187,14 @@ class JobCard(Document):
|
||||
row = self.append("time_logs", kwargs)
|
||||
row.db_update()
|
||||
self.db_set("status", "Work In Progress")
|
||||
elif not kwargs.from_time and not kwargs.to_time and kwargs.completed_qty:
|
||||
update_status = True
|
||||
for row in self.time_logs:
|
||||
if row.employee != kwargs.employee:
|
||||
continue
|
||||
|
||||
row.completed_qty = kwargs.completed_qty
|
||||
row.db_update()
|
||||
else:
|
||||
update_status = True
|
||||
for row in self.time_logs:
|
||||
@@ -1247,6 +1255,9 @@ class JobCard(Document):
|
||||
if kwargs.end_time:
|
||||
self.add_time_logs(to_time=kwargs.end_time, completed_qty=kwargs.qty, employees=self.employee)
|
||||
self.save()
|
||||
else:
|
||||
self.add_time_logs(completed_qty=kwargs.qty, employees=self.employee)
|
||||
self.save()
|
||||
|
||||
if kwargs.auto_submit:
|
||||
self.submit()
|
||||
@@ -1423,9 +1434,19 @@ def make_stock_entry(source_name, target_doc=None):
|
||||
target.qty = pending_rm_qty
|
||||
|
||||
def set_missing_values(source, target):
|
||||
if source.finished_good and not source.target_warehouse:
|
||||
frappe.throw(_("Please set the Target Warehouse in the Job Card"))
|
||||
|
||||
if not source.skip_material_transfer or source.backflush_from_wip_warehouse:
|
||||
if not source.wip_warehouse:
|
||||
frappe.throw(_("Please set the WIP Warehouse in the Job Card"))
|
||||
|
||||
target.purpose = "Material Transfer for Manufacture"
|
||||
target.from_bom = 1
|
||||
|
||||
if source.semi_fg_bom:
|
||||
target.bom_no = source.semi_fg_bom
|
||||
|
||||
# avoid negative 'For Quantity'
|
||||
pending_fg_qty = flt(source.get("for_quantity", 0)) - flt(source.get("transferred_qty", 0))
|
||||
target.fg_completed_qty = pending_fg_qty if pending_fg_qty > 0 else 0
|
||||
|
||||
@@ -37,8 +37,7 @@
|
||||
"fieldname": "time_in_mins",
|
||||
"fieldtype": "Float",
|
||||
"in_list_view": 1,
|
||||
"label": "Time In Mins",
|
||||
"read_only": 1
|
||||
"label": "Time In Mins"
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
@@ -64,18 +63,20 @@
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"grid_page_length": 50,
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2024-05-21 12:41:55.765860",
|
||||
"modified": "2025-03-25 20:05:13.807905",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "Job Card Time Log",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"quick_entry": 1,
|
||||
"row_format": "Dynamic",
|
||||
"sort_field": "creation",
|
||||
"sort_order": "ASC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user