2018-09-06 13:51:48 +00:00
|
|
|
# Copyright (c) 2017, Frappe and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2018-09-06 13:51:48 +00:00
|
|
|
import frappe
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2018-09-07 10:44:44 +00:00
|
|
|
from erpnext.manufacturing.doctype.work_order.work_order import create_job_card
|
2018-09-06 13:51:48 +00:00
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2018-09-06 13:51:48 +00:00
|
|
|
def execute():
|
2022-03-28 13:22:46 +00:00
|
|
|
frappe.reload_doc("manufacturing", "doctype", "work_order")
|
|
|
|
frappe.reload_doc("manufacturing", "doctype", "work_order_item")
|
|
|
|
frappe.reload_doc("manufacturing", "doctype", "job_card")
|
|
|
|
frappe.reload_doc("manufacturing", "doctype", "job_card_item")
|
2018-09-06 13:51:48 +00:00
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
fieldname = frappe.db.get_value(
|
|
|
|
"DocField", {"fieldname": "work_order", "parent": "Timesheet"}, "fieldname"
|
|
|
|
)
|
2018-09-09 13:48:41 +00:00
|
|
|
if not fieldname:
|
2022-03-28 13:22:46 +00:00
|
|
|
fieldname = frappe.db.get_value(
|
|
|
|
"DocField", {"fieldname": "production_order", "parent": "Timesheet"}, "fieldname"
|
|
|
|
)
|
|
|
|
if not fieldname:
|
|
|
|
return
|
2018-09-09 13:48:41 +00:00
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
for d in frappe.get_all(
|
|
|
|
"Timesheet", filters={fieldname: ["!=", ""], "docstatus": 0}, fields=[fieldname, "name"]
|
|
|
|
):
|
2018-09-09 13:48:41 +00:00
|
|
|
if d[fieldname]:
|
2022-03-28 13:22:46 +00:00
|
|
|
doc = frappe.get_doc("Work Order", d[fieldname])
|
2018-09-07 10:44:44 +00:00
|
|
|
for row in doc.operations:
|
|
|
|
create_job_card(doc, row, auto_create=True)
|
2022-03-28 13:22:46 +00:00
|
|
|
frappe.delete_doc("Timesheet", d.name)
|