From 3046c7e09ddd9f3dfd50dfa5b110525d4afc7955 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Fri, 2 Oct 2026 11:09:31 +0200 Subject: [PATCH] #14829: Emit insert-date event comment above DATES keyword Fixes #14829. --- .../RicScheduleDataGenerator.cpp | 24 +++++++++---------- .../Python/rips/tests/test_well_events.py | 5 +++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp index 3907bd0094..8d4c84603a 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp @@ -278,6 +278,18 @@ std::expected RicScheduleDataGenerator::generateDateSection( c auto serializeKeyword = [&]( const Opm::DeckKeyword& kw ) { return alignColumns ? RimKeywordFactory::deckKeywordToAlignedString( kw ) : RimKeywordFactory::deckKeywordToString( kw ); }; + // Comments from insert-date events describe the date itself, and are emitted directly above it. + for ( const auto* event : events ) + { + if ( event->eventType() != RimWellEvent::EventType::INSERT_DATE ) continue; + if ( event->comment().isEmpty() ) continue; + + for ( QString line : event->comment().split( '\n' ) ) + { + line.remove( '\r' ); + result += line.isEmpty() ? "--\n" : QString( "-- %1\n" ).arg( line ); + } + } // Generate DATES keyword, or a date comment when requested (e.g. for the first date, which // equals the simulation start date and is rejected as a DATES entry by some simulators). if ( dateAsComment ) @@ -300,18 +312,6 @@ std::expected RicScheduleDataGenerator::generateDateSection( c result += serializeKeyword( RimKeywordFactory::datesKeyword( date ) ) + "\n"; } - // Comments from insert-date events describe the date itself, and are emitted directly below it. - for ( const auto* event : events ) - { - if ( event->eventType() != RimWellEvent::EventType::INSERT_DATE ) continue; - if ( event->comment().isEmpty() ) continue; - - for ( QString line : event->comment().split( '\n' ) ) - { - line.remove( '\r' ); - result += line.isEmpty() ? "--\n" : QString( "-- %1\n" ).arg( line ); - } - } appendRawText( RimWellEventRawText::Placement::AFTER_DATE ); // Records for each keyword name are accumulated across wells, then serialised once below. diff --git a/GrpcInterface/Python/rips/tests/test_well_events.py b/GrpcInterface/Python/rips/tests/test_well_events.py index a2a59b37e0..bd060adcc6 100644 --- a/GrpcInterface/Python/rips/tests/test_well_events.py +++ b/GrpcInterface/Python/rips/tests/test_well_events.py @@ -488,8 +488,11 @@ class TestScheduleGeneration: "Inserted date 2024-06-01 should be emitted as a DATES entry" ) assert "-- Mid-year summary report" in schedule_text, ( - "The comment of an insert-date event should be emitted below its date" + "The comment of an insert-date event should be emitted above its date" ) + assert schedule_text.index("-- Mid-year summary report") < schedule_text.index( + "1 'JUN' 2024" + ), "The comment must precede the DATES keyword of its insert-date event" # Dates must appear in chronological order: JAN (event), FEB, MAR (event), JUN positions = [ schedule_text.index(date_str)