fix: "Qty To Manufacture" field as non mandatory in job card (#21081)
This commit is contained in:
parent
86aff0de1f
commit
d274923ae1
@ -135,6 +135,7 @@ frappe.ui.form.on("BOM", {
|
|||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.manufacturing.doctype.work_order.work_order.make_work_order",
|
method: "erpnext.manufacturing.doctype.work_order.work_order.make_work_order",
|
||||||
args: {
|
args: {
|
||||||
|
bom_no: frm.doc.name,
|
||||||
item: frm.doc.item,
|
item: frm.doc.item,
|
||||||
qty: data.qty || 0.0,
|
qty: data.qty || 0.0,
|
||||||
project: frm.doc.project
|
project: frm.doc.project
|
||||||
|
|||||||
@ -20,7 +20,7 @@ frappe.ui.form.on('Job Card', {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.doc.items.length || frm.doc.for_quantity == frm.doc.transferred_qty)) {
|
||||||
frm.trigger("prepare_timer_buttons");
|
frm.trigger("prepare_timer_buttons");
|
||||||
}
|
}
|
||||||
@ -59,10 +59,14 @@ frappe.ui.form.on('Job Card', {
|
|||||||
let completed_time = frappe.datetime.now_datetime();
|
let completed_time = frappe.datetime.now_datetime();
|
||||||
frm.trigger("hide_timer");
|
frm.trigger("hide_timer");
|
||||||
|
|
||||||
frappe.prompt({fieldtype: 'Float', label: __('Completed Quantity'),
|
if (frm.doc.for_quantity) {
|
||||||
fieldname: 'qty', reqd: 1, default: frm.doc.for_quantity}, data => {
|
frappe.prompt({fieldtype: 'Float', label: __('Completed Quantity'),
|
||||||
frm.events.complete_job(frm, completed_time, data.qty);
|
fieldname: 'qty', reqd: 1, default: frm.doc.for_quantity}, data => {
|
||||||
}, __("Enter Value"), __("Complete"));
|
frm.events.complete_job(frm, completed_time, data.qty);
|
||||||
|
}, __("Enter Value"), __("Complete"));
|
||||||
|
} else {
|
||||||
|
frm.events.complete_job(frm, completed_time, 0);
|
||||||
|
}
|
||||||
}).addClass("btn-primary");
|
}).addClass("btn-primary");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -99,8 +99,7 @@
|
|||||||
"fieldname": "for_quantity",
|
"fieldname": "for_quantity",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Qty To Manufacture",
|
"label": "Qty To Manufacture"
|
||||||
"reqd": 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "wip_warehouse",
|
"fieldname": "wip_warehouse",
|
||||||
@ -122,6 +121,7 @@
|
|||||||
"options": "Employee"
|
"options": "Employee"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"allow_bulk_edit": 1,
|
||||||
"fieldname": "time_logs",
|
"fieldname": "time_logs",
|
||||||
"fieldtype": "Table",
|
"fieldtype": "Table",
|
||||||
"label": "Time Logs",
|
"label": "Time Logs",
|
||||||
@ -290,7 +290,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"modified": "2019-12-03 13:08:57.926201",
|
"modified": "2020-03-27 13:36:35.417502",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Manufacturing",
|
"module": "Manufacturing",
|
||||||
"name": "Job Card",
|
"name": "Job Card",
|
||||||
|
|||||||
@ -191,12 +191,9 @@ class JobCard(Document):
|
|||||||
if not self.time_logs:
|
if not self.time_logs:
|
||||||
frappe.throw(_("Time logs are required for job card {0}").format(self.name))
|
frappe.throw(_("Time logs are required for job card {0}").format(self.name))
|
||||||
|
|
||||||
if self.total_completed_qty <= 0.0:
|
if self.for_quantity and self.total_completed_qty != self.for_quantity:
|
||||||
frappe.throw(_("Total completed qty must be greater than zero"))
|
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.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):
|
def update_work_order(self):
|
||||||
if not self.work_order:
|
if not self.work_order:
|
||||||
@ -205,27 +202,34 @@ class JobCard(Document):
|
|||||||
for_quantity, time_in_mins = 0, 0
|
for_quantity, time_in_mins = 0, 0
|
||||||
from_time_list, to_time_list = [], []
|
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
|
data = frappe.get_all('Job Card',
|
||||||
time_in_mins += doc.total_time_in_mins
|
fields = ["sum(total_time_in_mins) as time_in_mins", "sum(total_completed_qty) as completed_qty"],
|
||||||
for time_log in doc.time_logs:
|
filters = {"docstatus": 1, "work_order": self.work_order,
|
||||||
if time_log.from_time:
|
"workstation": self.workstation, "operation": self.operation})
|
||||||
from_time_list.append(time_log.from_time)
|
|
||||||
if time_log.to_time:
|
if data and len(data) > 0:
|
||||||
to_time_list.append(time_log.to_time)
|
for_quantity = data[0].completed_qty
|
||||||
|
time_in_mins = data[0].time_in_mins
|
||||||
|
|
||||||
if for_quantity:
|
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)
|
wo = frappe.get_doc('Work Order', self.work_order)
|
||||||
|
|
||||||
for data in wo.operations:
|
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.completed_qty = for_quantity
|
||||||
data.actual_operation_time = time_in_mins
|
data.actual_operation_time = time_in_mins
|
||||||
data.actual_start_time = min(from_time_list) if from_time_list else None
|
data.actual_start_time = time_data[0].start_time if time_data else None
|
||||||
data.actual_end_time = max(to_time_list) if to_time_list 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.flags.ignore_validate_update_after_submit = True
|
||||||
wo.update_operation_status()
|
wo.update_operation_status()
|
||||||
|
|||||||
@ -648,7 +648,7 @@ def get_item_details(item, project = None):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
@frappe.whitelist()
|
@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"):
|
if not frappe.has_permission("Work Order", "write"):
|
||||||
frappe.throw(_("Not permitted"), frappe.PermissionError)
|
frappe.throw(_("Not permitted"), frappe.PermissionError)
|
||||||
|
|
||||||
@ -657,6 +657,7 @@ def make_work_order(item, qty=0, project=None):
|
|||||||
wo_doc = frappe.new_doc("Work Order")
|
wo_doc = frappe.new_doc("Work Order")
|
||||||
wo_doc.production_item = item
|
wo_doc.production_item = item
|
||||||
wo_doc.update(item_details)
|
wo_doc.update(item_details)
|
||||||
|
wo_doc.bom_no = bom_no
|
||||||
|
|
||||||
if flt(qty) > 0:
|
if flt(qty) > 0:
|
||||||
wo_doc.qty = flt(qty)
|
wo_doc.qty = flt(qty)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user