Production Plan extension

This commit is contained in:
2024-08-08 10:37:37 +00:00
parent 43d9b0dc0f
commit cd98dffbab
2 changed files with 84 additions and 76 deletions

View File

@@ -104,6 +104,12 @@ app_include_js = "manufacturing_overview.bundle.js"
# }
# }
# doc_events = {
# "Subcontracting Receipt": {
# "on_submit": "manufacturing_overview.manufacturing_overview.productionplan.update_productionplan_status",
# }
# }
# Scheduled Tasks
# ---------------

View File

@@ -6,102 +6,104 @@ from frappe.utils import (
frappe.utils.logger.set_log_level("DEBUG")
logger = frappe.logger("manufacturing_overview",
allow_site=True, file_count=50)
allow_site=True, file_count=50)
# logger.debug(f"{wo_id}")
@frappe.whitelist()
def makepp(sales_order):
"""
Check if Production Plan already exists and break when it does.
"""
so = frappe.get_doc("Sales Order", sales_order)
"""
Check if Production Plan already exists and break when it does.
"""
so = frappe.get_doc("Sales Order", sales_order)
checkpp = frappe.get_all('Production Plan Item', filters={'sales_order': so.name}, fields=[
'name', 'parent'])
checkpp = frappe.get_all('Production Plan Item', filters={'sales_order': so.name}, fields=[
'name', 'parent'])
if checkpp:
return {'status': 400,
'docname': [checkpp[0].parent]}
if checkpp:
return {'status': 400,
'docname': [checkpp[0].parent]}
"""
Create Production Plan
"""
sales_orders = [{
"sales_order": so.name,
"customer": so.customer,
"sales_order_date": so.transaction_date,
"grand_total": so.grand_total,
}]
"""
Create Production Plan
"""
sales_orders = [{
"sales_order": so.name,
"customer": so.customer,
"sales_order_date": so.transaction_date,
"grand_total": so.grand_total,
}]
po_items = []
for item in so.items:
i = {
"item_code": item.item_code,
"bom_no": get_default_bom(item.item_code),
"planned_qty": item.qty,
"planned_start_date": frappe.utils.nowdate(),
"stock_uom": "Stk",
"sales_order": so.name,
"sales_order_item": item.name
}
po_items = []
for item in so.items:
i = {
"item_code": item.item_code,
"bom_no": get_default_bom(item.item_code),
"planned_qty": item.qty,
"planned_start_date": frappe.utils.nowdate(),
"stock_uom": "Stk",
"sales_order": so.name,
"sales_order_item": item.name
}
po_items.append(i)
po_items.append(i)
pp = frappe.get_doc({
'doctype': 'Production Plan',
'get_items_from': 'Sales Order',
'sales_orders': sales_orders,
'po_items': po_items,
'for_warehouse': "Lagerräume - HP"
})
pp.insert()
pp = frappe.get_doc({
'doctype': 'Production Plan',
'get_items_from': 'Sales Order',
'sales_orders': sales_orders,
'po_items': po_items,
'for_warehouse': "Lagerräume - HP"
})
pp.insert()
return {'status': 201,
'docname': [pp.name]}
return {'status': 201,
'docname': [pp.name]}
@frappe.whitelist()
def fixfinisheditemwopo(production_plan):
pp = frappe.get_doc("Production Plan", production_plan)
wo_id = frappe.get_all('Work Order', filters={'production_plan_item': pp.po_items[0].name})
wo_id = wo_id[0]["name"]
pp = frappe.get_doc("Production Plan", production_plan)
wo_id = frappe.get_all('Work Order', filters={'production_plan_item': pp.po_items[0].name})
wo_id = wo_id[0]["name"]
frappe.delete_doc("Work Order", wo_id)
frappe.delete_doc("Work Order", wo_id)
po = frappe.new_doc("Purchase Order")
po.supplier = pp.po_items[0].custom_supplier
po.schedule_date = nowdate()
po.is_subcontracted = 1
po = frappe.new_doc("Purchase Order")
po.supplier = pp.po_items[0].custom_supplier
po.schedule_date = nowdate()
po.is_subcontracted = 1
for row in pp.po_items:
po_data = {
for row in pp.po_items:
po_data = {
"fg_item": row.item_code,
# "warehouse": row.fg_warehouse,
# "production_plan_sub_assembly_item": row.name,
# "bom": row.bom_no,
# "production_plan": pp.name,
# "fg_item_qty": row.qty,
"warehouse": row.warehouse,
"bom": row.bom_no,
"production_plan": pp.name,
"fg_item_qty": row.planned_qty,
"supplier_warehouse": "Externe Arbeiten - HP"
}
# for field in [
# "schedule_date",
# "qty",
# "description",
# "production_plan_item",
# ]:
# po_data[field] = row.get(field)
for field in [
"schedule_date",
"qty",
"description",
"production_plan_item",
]:
po_data[field] = row.get(field)
po.append("items", po_data)
po.append("items", po_data)
po.set_service_items_for_finished_goods()
po.set_missing_values()
po.flags.ignore_mandatory = True
po.flags.ignore_validate = True
po.insert()
po.set_service_items_for_finished_goods()
po.set_missing_values()
# po.flags.ignore_mandatory = True
# po.flags.ignore_validate = True
po.insert()
# pp.db_set("total_produced_qty", pp.total_planned_qty)
# pp.db_set("status", "Completed")
return {'status': 201,
'docname': po.name}
return {'status': 201,
'docname': po.name}