Project

General

Profile

Feature #36823 » 0001-allow-imported-time-entries-to-override-the-selected.patch

Jens Krämer, 2022-03-22 12:04

View differences:

app/models/time_entry_import.rb
105 105
    end
106 106

  
107 107
    attributes = {
108
      :project_id  => project.id,
109 108
      :activity_id => activity_id,
110 109
      :author_id   => user.id,
111 110
      :user_id     => user_id,
112 111

  
113
      :issue_id    => row_value(row, 'issue_id'),
114 112
      :spent_on    => row_date(row, 'spent_on'),
115 113
      :hours       => row_value(row, 'hours'),
116 114
      :comments    => row_value(row, 'comments')
117 115
    }
118 116

  
117
    if issue_id = row_value(row, 'issue_id').presence
118
      attributes[:issue_id] = issue_id
119
    else
120
      attributes[:project_id] = project.id
121
    end
122

  
119 123
    attributes['custom_field_values'] = object.custom_field_values.inject({}) do |h, v|
120 124
      value =
121 125
        case v.custom_field.field_format
test/unit/time_entry_import_test.rb
165 165
    assert_equal 2, fourth.user_id
166 166
  end
167 167

  
168
  def test_imports_timelogs_for_issues_in_other_project
169
    import = generate_import
170
    import.settings = {
171
      'separator' => ';', 'wrapper' => '"', 'encoding' => 'UTF-8',
172
      'mapping' => {
173
        'project_id' => '3',
174
        'activity'   => 'value:10',
175
        'issue_id'   => '1',
176
        'spent_on'   => '2',
177
        'hours'      => '3',
178
        'comments'   => '4',
179
        'user'       => '7'
180
      }
181
    }
182
    import.save!
183
    first, second, third, fourth = new_records(TimeEntry, 4) {import.run}
184
    assert_equal 3, first.project_id
185
    assert_equal 3, second.project_id
186
    assert_equal 1, third.project_id
187
    assert_equal 1, fourth.project_id
188
  end
189

  
168 190
  protected
169 191

  
170 192
  def generate_import(fixture_name='import_time_entries.csv')
    (1-1/1)