timesheet logic changed to job card
This commit is contained in:
parent
e895845ae1
commit
e64dcfc2f9
@ -4,13 +4,17 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import frappe, random, erpnext
|
||||
from datetime import datetime, timedelta
|
||||
from frappe.utils.make_random import how_many
|
||||
from frappe.desk import query_report
|
||||
from erpnext.manufacturing.doctype.workstation.workstation import WorkstationHolidayError
|
||||
from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record
|
||||
|
||||
def work():
|
||||
if random.random() < 0.3: return
|
||||
|
||||
frappe.set_user(frappe.db.get_global('demo_manufacturing_user'))
|
||||
if not frappe.get_all('Sales Order'): return
|
||||
|
||||
from erpnext.projects.doctype.timesheet.timesheet import OverlapError
|
||||
|
||||
@ -20,6 +24,7 @@ def work():
|
||||
ppt.get_items_from = "Sales Order"
|
||||
# ppt.purchase_request_for_warehouse = "Stores - WPL" # refactored
|
||||
ppt.run_method("get_open_sales_orders")
|
||||
if not ppt.get("sales_orders"): return
|
||||
ppt.run_method("get_items")
|
||||
ppt.run_method("raise_material_requests")
|
||||
ppt.save()
|
||||
@ -41,12 +46,12 @@ def work():
|
||||
frappe.db.commit()
|
||||
|
||||
# stores -> wip
|
||||
if random.random() < 0.3:
|
||||
if random.random() < 0.4:
|
||||
for pro in query_report.run("Open Work Orders")["result"][:how_many("Stock Entry for WIP")]:
|
||||
make_stock_entry_from_pro(pro[0], "Material Transfer for Manufacture")
|
||||
|
||||
# wip -> fg
|
||||
if random.random() < 0.3:
|
||||
if random.random() < 0.4:
|
||||
for pro in query_report.run("Work Orders in Progress")["result"][:how_many("Stock Entry for FG")]:
|
||||
make_stock_entry_from_pro(pro[0], "Manufacture")
|
||||
|
||||
@ -57,17 +62,9 @@ def work():
|
||||
stock_uom = frappe.db.get_value('Item', bom.item, 'stock_uom'),
|
||||
planned_start_date = frappe.flags.current_date)
|
||||
|
||||
# submit time logs
|
||||
for timesheet in frappe.get_all("Timesheet", ["name"], {"docstatus": 0,
|
||||
"work_order": ("!=", ""), "to_time": ("<", frappe.flags.current_date)}):
|
||||
timesheet = frappe.get_doc("Timesheet", timesheet.name)
|
||||
try:
|
||||
timesheet.submit()
|
||||
frappe.db.commit()
|
||||
except OverlapError:
|
||||
pass
|
||||
except WorkstationHolidayError:
|
||||
pass
|
||||
# submit job card
|
||||
if random.random() < 0.4:
|
||||
submit_job_cards()
|
||||
|
||||
def make_stock_entry_from_pro(pro_id, purpose):
|
||||
from erpnext.manufacturing.doctype.work_order.work_order import make_stock_entry
|
||||
@ -88,3 +85,27 @@ def make_stock_entry_from_pro(pro_id, purpose):
|
||||
except (NegativeStockError, IncorrectValuationRateError, DuplicateEntryForWorkOrderError,
|
||||
OperationsNotCompleteError):
|
||||
frappe.db.rollback()
|
||||
|
||||
def submit_job_cards():
|
||||
work_orders = frappe.get_all("Work Order", ["name", "creation"], {"docstatus": 1, "status": "Not Started"})
|
||||
work_order = random.choice(work_orders)
|
||||
# for work_order in work_orders:
|
||||
start_date = work_order.creation
|
||||
work_order = frappe.get_doc("Work Order", work_order.name)
|
||||
job = frappe.get_all("Job Card", ["name", "operation", "work_order"],
|
||||
{"docstatus": 0, "work_order": work_order.name})
|
||||
|
||||
if not job: return
|
||||
job_map = {}
|
||||
for d in job:
|
||||
job_map[d.operation] = frappe.get_doc("Job Card", d.name)
|
||||
|
||||
for operation in work_order.operations:
|
||||
job = job_map[operation.operation]
|
||||
job.actual_start_date = start_date
|
||||
minutes = operation.get("time_in_mins")
|
||||
random_minutes = random.randint(int(minutes/2), minutes)
|
||||
job.actual_end_date = job.actual_start_date + timedelta(minutes=random_minutes)
|
||||
start_date = job.actual_end_date
|
||||
job.save()
|
||||
job.submit()
|
||||
|
Loading…
x
Reference in New Issue
Block a user