fix: "Qty To Manufacture" field as non mandatory in job card (#21081)
diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js
index 3acaee4..4f08bbc 100644
--- a/erpnext/manufacturing/doctype/bom/bom.js
+++ b/erpnext/manufacturing/doctype/bom/bom.js
@@ -135,6 +135,7 @@
frappe.call({
method: "erpnext.manufacturing.doctype.work_order.work_order.make_work_order",
args: {
+ bom_no: frm.doc.name,
item: frm.doc.item,
qty: data.qty || 0.0,
project: frm.doc.project
diff --git a/erpnext/manufacturing/doctype/job_card/job_card.js b/erpnext/manufacturing/doctype/job_card/job_card.js
index bc8c229..8c7876d 100644
--- a/erpnext/manufacturing/doctype/job_card/job_card.js
+++ b/erpnext/manufacturing/doctype/job_card/job_card.js
@@ -20,7 +20,7 @@
}
}
- if (frm.doc.docstatus == 0 && frm.doc.for_quantity > frm.doc.total_completed_qty
+ if (frm.doc.docstatus == 0 && (frm.doc.for_quantity > frm.doc.total_completed_qty || !frm.doc.for_quantity)
&& (!frm.doc.items.length || frm.doc.for_quantity == frm.doc.transferred_qty)) {
frm.trigger("prepare_timer_buttons");
}
@@ -59,10 +59,14 @@
let completed_time = frappe.datetime.now_datetime();
frm.trigger("hide_timer");
- frappe.prompt({fieldtype: 'Float', label: __('Completed Quantity'),
- fieldname: 'qty', reqd: 1, default: frm.doc.for_quantity}, data => {
- frm.events.complete_job(frm, completed_time, data.qty);
- }, __("Enter Value"), __("Complete"));
+ if (frm.doc.for_quantity) {
+ frappe.prompt({fieldtype: 'Float', label: __('Completed Quantity'),
+ fieldname: 'qty', reqd: 1, default: frm.doc.for_quantity}, data => {
+ frm.events.complete_job(frm, completed_time, data.qty);
+ }, __("Enter Value"), __("Complete"));
+ } else {
+ frm.events.complete_job(frm, completed_time, 0);
+ }
}).addClass("btn-primary");
}
},
diff --git a/erpnext/manufacturing/doctype/job_card/job_card.json b/erpnext/manufacturing/doctype/job_card/job_card.json
index 156acce..7661fff 100644
--- a/erpnext/manufacturing/doctype/job_card/job_card.json
+++ b/erpnext/manufacturing/doctype/job_card/job_card.json
@@ -99,8 +99,7 @@
"fieldname": "for_quantity",
"fieldtype": "Float",
"in_list_view": 1,
- "label": "Qty To Manufacture",
- "reqd": 1
+ "label": "Qty To Manufacture"
},
{
"fieldname": "wip_warehouse",
@@ -122,6 +121,7 @@
"options": "Employee"
},
{
+ "allow_bulk_edit": 1,
"fieldname": "time_logs",
"fieldtype": "Table",
"label": "Time Logs",
@@ -290,7 +290,7 @@
}
],
"is_submittable": 1,
- "modified": "2019-12-03 13:08:57.926201",
+ "modified": "2020-03-27 13:36:35.417502",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Job Card",
diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py
index 029db1c..f8c60f2 100644
--- a/erpnext/manufacturing/doctype/job_card/job_card.py
+++ b/erpnext/manufacturing/doctype/job_card/job_card.py
@@ -191,12 +191,9 @@
if not self.time_logs:
frappe.throw(_("Time logs are required for job card {0}").format(self.name))
- if self.total_completed_qty <= 0.0:
- frappe.throw(_("Total completed qty must be greater than zero"))
-
- if self.total_completed_qty != self.for_quantity:
- frappe.throw(_("The total completed qty({0}) must be equal to qty to manufacture({1})")
- .format(frappe.bold(self.total_completed_qty),frappe.bold(self.for_quantity)))
+ if self.for_quantity and self.total_completed_qty != self.for_quantity:
+ frappe.throw(_("The total completed qty({0}) must be equal to qty to manufacture({1})"
+ .format(frappe.bold(self.total_completed_qty),frappe.bold(self.for_quantity))))
def update_work_order(self):
if not self.work_order:
@@ -205,27 +202,34 @@
for_quantity, time_in_mins = 0, 0
from_time_list, to_time_list = [], []
- for d in frappe.get_all('Job Card',
- filters = {'docstatus': 1, 'operation_id': self.operation_id}):
- doc = frappe.get_doc('Job Card', d.name)
- for_quantity += doc.total_completed_qty
- time_in_mins += doc.total_time_in_mins
- for time_log in doc.time_logs:
- if time_log.from_time:
- from_time_list.append(time_log.from_time)
- if time_log.to_time:
- to_time_list.append(time_log.to_time)
+ data = frappe.get_all('Job Card',
+ fields = ["sum(total_time_in_mins) as time_in_mins", "sum(total_completed_qty) as completed_qty"],
+ filters = {"docstatus": 1, "work_order": self.work_order,
+ "workstation": self.workstation, "operation": self.operation})
+
+ if data and len(data) > 0:
+ for_quantity = data[0].completed_qty
+ time_in_mins = data[0].time_in_mins
if for_quantity:
+ time_data = frappe.db.sql("""
+ SELECT
+ min(from_time) as start_time, max(to_time) as end_time
+ FROM `tabJob Card` jc, `tabJob Card Time Log` jctl
+ WHERE
+ jctl.parent = jc.name and jc.work_order = %s
+ and jc.workstation = %s and jc.operation = %s and jc.docstatus = 1
+ """, (self.work_order, self.workstation, self.operation), as_dict=1)
+
wo = frappe.get_doc('Work Order', self.work_order)
for data in wo.operations:
- if data.name == self.operation_id:
+ if data.workstation == self.workstation and data.operation == self.operation:
data.completed_qty = for_quantity
data.actual_operation_time = time_in_mins
- data.actual_start_time = min(from_time_list) if from_time_list else None
- data.actual_end_time = max(to_time_list) if to_time_list else None
+ data.actual_start_time = time_data[0].start_time if time_data else None
+ data.actual_end_time = time_data[0].end_time if time_data else None
wo.flags.ignore_validate_update_after_submit = True
wo.update_operation_status()
diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py
index 71a62e4..a124b1f 100644
--- a/erpnext/manufacturing/doctype/work_order/work_order.py
+++ b/erpnext/manufacturing/doctype/work_order/work_order.py
@@ -648,7 +648,7 @@
return res
@frappe.whitelist()
-def make_work_order(item, qty=0, project=None):
+def make_work_order(bom_no, item, qty=0, project=None):
if not frappe.has_permission("Work Order", "write"):
frappe.throw(_("Not permitted"), frappe.PermissionError)
@@ -657,6 +657,7 @@
wo_doc = frappe.new_doc("Work Order")
wo_doc.production_item = item
wo_doc.update(item_details)
+ wo_doc.bom_no = bom_no
if flt(qty) > 0:
wo_doc.qty = flt(qty)