def METHOD_NAME(command, commit_enrolled_device=True):
    """Used in the inventory MDM commands to update the inventory tree
    Search for the other latest inventory MDM command to build a complete machine snapshot tree."""
    enrolled_device = command.enrolled_device
    blueprint = enrolled_device.blueprint
    ms_tree = {
        "source": {"module": "zentral.contrib.mdm",
                   "name": "MDM"},
        "reference": enrolled_device.udid,
        "serial_number": enrolled_device.serial_number
    }
    try:
        ms_tree["business_unit"] = command.meta_business_unit.api_enrollment_business_units()[0].serialize()
    except IndexError:
        pass
    for bp_attr, cmd_db_name, ts_attr in (
        (None, "DeviceInformation", "device_information_updated_at"),
        ("collect_apps", "InstalledApplicationList", "apps_updated_at"),
        ("collect_certificates", "CertificateList", "certificates_updated_at"),
        ("collect_profiles", "ProfileList", "profiles_updated_at")
    ):
        if (
            bp_attr is not None
            and (
                blueprint is None
                or getattr(blueprint, bp_attr) == Blueprint.InventoryItemCollectionOption.NO
            )
        ):
            # Skip inventory information
            continue
        latest_command = None
        if command.get_db_name() == cmd_db_name:
            latest_command = command
        else:
            latest_db_command = DeviceCommand.objects.filter(
                enrolled_device=enrolled_device,
                name=cmd_db_name,
                result__isnull=False,
                status=Command.Status.ACKNOWLEDGED
            ).order_by("-created_at").first()
            if latest_db_command:
                latest_command = load_command(latest_db_command)
        if latest_command:
            ms_tree.update(latest_command.get_inventory_partial_tree())
            setattr(enrolled_device, ts_attr, latest_command.result_time)
    commit_machine_snapshot_and_trigger_events(ms_tree)
    if commit_enrolled_device:
        enrolled_device.save()
    return ms_tree