Code :-
import json
import frappe
from frappe import _, msgprint
from frappe.model.mapper import get_mapped_doc
from frappe.query_builder.functions import Sum
from frappe.utils import cint, cstr, flt, get_link_to_form, getdate, new_line_sep, nowdate
from frappe.model.document import Document
class Log_Test(Document):
pass
@frappe.whitelist()
def make_log_schedule(source_name, target_doc=None):
print(f"source_name: {source_name}")
log_test = frappe.get_doc("Log_Test", source_name)
print(f"log_test: {log_test}")
log_schedule = frappe.new_doc("Log_Schedule")
log_schedule.update({
"machine_related_readings": log_schedule.machine_related_readings,
"other_measurable_readings": log_schedule.other_measurable_readings,
})
for machine in log_test.get("machine_related_readings"):
new_machine = frappe.new_doc("Log_Schedule_Machines")
new_machine.log_test = log_schedule.name
new_machine.machine_group = machine.machine_group
new_machine.unit_measure = machine.unit_measure
new_machine.unit = machine.unit
new_machine.min_max = machine.min_max
new_machine.save()
log_schedule = frappe.new_doc("Log_Schedule")
log_schedule.append("log_schedule_machines", new_machine)
for reading in log_test.get("other_measurable_readings"):
new_reading = frappe.new_doc("Log_Schedule_Readings")
new_reading.log_test = log_schedule.name
new_reading.unit_measure = reading.unit_measure
new_reading.unit = reading.unit
new_reading.min_max = reading.min_max
new_reading.save()
log_schedule.append("log_schedule_readings", new_reading)
log_schedule.save()