diff --git a/lib/interpreters/split_clustering.rb b/lib/interpreters/split_clustering.rb index 05126d875..8da5db3db 100644 --- a/lib/interpreters/split_clustering.rb +++ b/lib/interpreters/split_clustering.rb @@ -680,7 +680,7 @@ def self.build_partial_service_vrp(service_vrp, partial_service_ids, available_v sub_vrp.points.uniq! sub_vrp = add_corresponding_entity_skills(entity, sub_vrp) - sub_vrp_hash = JSON.parse(sub_vrp.to_json, symbolize_names: true) + sub_vrp_hash = sub_vrp.as_json vehicle_ids = sub_vrp_hash[:vehicles]&.map{ |v| v[:id] } || [] sub_vrp_hash[:services]&.each{ |service| diff --git a/models/relation.rb b/models/relation.rb index 336f5cde8..a8ef6c1ac 100644 --- a/models/relation.rb +++ b/models/relation.rb @@ -43,16 +43,18 @@ class Relation < Base def self.create(hash) # TODO: remove it after the linked_ids is replaced with linked_service_ids in the api definition - exclusive = [:linked_service_ids, :linked_ids, :linked_services].freeze - raise "#{exclusive} fields are mutually exclusive" if hash.keys.count{ |k| exclusive.include? k } > 1 + if hash.key?(:linked_service_ids) && hash.key?(:linked_ids) && hash[:linked_service_ids] != hash[:linked_ids] + raise 'linked_service_ids and linked_ids should have the same content if both used' + end + + # Raise condition required due to the use of lib/helper deep_copy + raise 'linked_services should not belong to vrp hash' if hash.key?(:linked_services) # TODO: remove it after the linked_ids is replaced with linked_service_ids in the api definition if hash.key?(:linked_ids) hash[:linked_service_ids] = hash[:linked_ids] elsif hash.key?(:linked_service_ids) hash[:linked_ids] = hash[:linked_service_ids] - elsif hash.key?(:linked_services) - hash[:linked_ids] = hash[:linked_services].map(&:id) end super(hash) diff --git a/wrappers/wrapper.rb b/wrappers/wrapper.rb index fefa84818..07f949e55 100644 --- a/wrappers/wrapper.rb +++ b/wrappers/wrapper.rb @@ -981,13 +981,10 @@ def simplify_complex_multi_pickup_or_delivery_shipments(vrp, solution = nil, opt quantity.value = -shipment_quantity + extra_per_quantity[q_index] } - new_shipment_relation = Helper.deep_copy( - relation, - override: { - linked_ids: nil, # this line can be removed when linked_ids is replaced with linked_service_ids - linked_services: relation.linked_services.map{ |s| s.id == service.id ? new_service : s } - } - ) + relation_hash = relation.as_json + relation_hash.delete(:linked_ids) + relation_hash[:linked_service_ids] = relation.linked_services.map{ |s| s.id == service.id ? new_service.id : s.id } + new_shipment_relation = Models::Relation.create(relation_hash) new_service.relations << new_shipment_relation