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({
|
||||
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
|
||||
|
@ -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.trigger("prepare_timer_buttons");
|
||||
}
|
||||
@ -59,10 +59,14 @@ frappe.ui.form.on('Job Card', {
|
||||
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");
|
||||
}
|
||||
},
|
||||
|
@ -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",
|
||||
|
@ -191,12 +191,9 @@ class JobCard(Document):
|
||||
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 @@ class JobCard(Document):
|
||||
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()
|
||||
|
@ -648,7 +648,7 @@ def get_item_details(item, project = None):
|
||||
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 @@ def make_work_order(item, qty=0, project=None):
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user