Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty lat/lng as nil & unknown tag id #208

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
### Added
- API: Allow commas for float fields [#205](https://github.com/cartoway/planner-web/pull/205)
- Planning: Add router name to vehicle selector [#202](https://github.com/cartoway/planner-web/pull/202)
- Destination: Allow commas for float columns during import [#203](https://github.com/cartoway/planner-web/pull/203)
- Destination: Allow commas for float columns during import [#203](https://github.com/cartoway/planner-web/pull/203) & [#208](https://github.com/cartoway/planner-web/pull/208)
- Zoning: Simplify polygons geometries [#207](https://github.com/cartoway/planner-web/pull/207)

### Changed
Expand All @@ -25,7 +25,7 @@
- Route: Avoid unexpected stops reloading during creation [#200](https://github.com/cartoway/planner-web/pull/200)
- Destination
- Import: New quantities columns are immediatly usable [#203](https://github.com/cartoway/planner-web/pull/203)
- Import: Cumulative lines with tags were failing [#203](https://github.com/cartoway/planner-web/pull/203)
- Import: Cumulative lines with tags were failing [#203](https://github.com/cartoway/planner-web/pull/203) & [#208](https://github.com/cartoway/planner-web/pull/208)
- Controller: edit params indirectly [#205](https://github.com/cartoway/planner-web/pull/205)
- Planning: Selectors are no more resizing on click [#202](https://github.com/cartoway/planner-web/pull/202)
- Vehicle Usage: _form was unrechable with an active device [#205](https://github.com/cartoway/planner-web/pull/205)
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/importer_destinations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def prepare_tags(row, key)
if tag.is_a?(Integer) && @tag_ids.key?(tag)
tag
else
tag = tag.strip
tag = tag.strip if tag.is_a?(String)
if !@tag_labels.key?(tag)
@tag_labels[tag] = @customer.tags.create(label: tag)
end
Expand Down
1 change: 1 addition & 0 deletions lib/coerce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def self.parse(str)

class CoerceFloatString
def self.parse(str)
str = nil if str.is_a?(String) && str.empty?
str.gsub!(',', '.') if str.is_a?(String) && str.match(',')
Float(str) if str
end
Expand Down
39 changes: 39 additions & 0 deletions test/api/v01/destinations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,45 @@ def api(part = nil, param = {})
end
end

test 'should create bulk from json with empty strings for coords' do
assert_difference('Destination.count', 1) do
assert_difference('Visit.count', 1) do
assert_difference('Stop.count',
@customer.plannings.select{ |p| p.tags_compatible?([tags(:tag_one), tags(:tag_two)]) }.size * 1) do
put api(), nil, input: {
destinations: [{
name: 'Nouveau client',
street: nil,
postalcode: nil,
city: 'Tule',
state: 'Limousin',
lat: "",
lng: "",
detail: nil,
comment: nil,
phone_number: nil,
ref: 'z',
tags: ['tag1', 'tag2', 999],
geocoding_accuracy: nil,
foo: 'bar',
visits: [{
ref: 'v1',
quantities: [{deliverable_unit_id: deliverable_units(:deliverable_unit_one_one).id, quantity: 1}],
time_window_start_1: '08:00',
time_window_end_1: '12:00',
time_window_start_2: '14:00',
time_window_end_2: '18:00',
duration: nil
}]
}]
}.to_json, CONTENT_TYPE: 'application/json'
assert last_response.ok?, last_response.body
assert_equal 1, JSON.parse(last_response.body).size, 'Bad response size: ' + last_response.body.inspect
end
end
end
end

test 'should create bulk from json with time exceeding one day' do
assert_difference('Destination.count', 1) do
assert_difference('Planning.count', 1) do
Expand Down
Loading