import frappe

def calculate_totals(doc, method):
    """Auto-calculate Load totals from child tables."""
    total_devices = 0
    total_weight = 0.0
    
    for item in doc.get("material_items", []):
        total_devices += item.total_count or 0
        total_weight += item.weight or 0.0
    
    doc.total_devices = total_devices
    doc.total_weight = total_weight
    
    total_hdd_wiped = 0
    total_hdd_degaussed = 0
    
    for hdd in doc.get("hdd_serials", []):
        if hdd.wiped:
            total_hdd_wiped += 1
        if hdd.degaussed or hdd.shredded:
            total_hdd_degaussed += 1
    
    doc.total_hdd_wiped = total_hdd_wiped
    doc.total_hdd_degaussed = total_hdd_degaussed
