Skip to content

Instantly share code, notes, and snippets.

@pedrozath
Last active June 7, 2018 16:39
Show Gist options
  • Save pedrozath/3d2d1754c84f6fa8fe9636cb495d5ea2 to your computer and use it in GitHub Desktop.
Save pedrozath/3d2d1754c84f6fa8fe9636cb495d5ea2 to your computer and use it in GitHub Desktop.
def breakbulk_cargo_originids
Manifest.find(43445)
.bol_segments
.first
.containers
.pluck(:originid)
.compact
.uniq
end
def breakbulk_cargo_and_offsprings
Container.where originid: breakbulk_cargo_originids
end
def fix_weights(dry_run: true)
breakbulk_cargo_and_offsprings.each do |c|
w = c.package_weight.to_f
puts "Working on Cargo #{c.goods}, id: #{c.id}"
puts "package weight is #{w} kg, but should be #{double_convert_back(w)} lb"
puts "\n"
puts "Wanna fix? y/n"
if gets.chomp == 'y'
new_package_weight = convert_from_lb_to_kg(w)
puts "changed to #{new_package_weight}"
if dry_run
puts '-- this is a dry-run so actually nothing was made'
else
c.update package_weight: new_package_weight,
disable_auto_weight_conversion: true
end
end
puts "\n"
end
end
def double_convert_back(value)
convert_from_lb_to_kg(convert_from_lb_to_kg(value))
end
def convert_from_lb_to_kg(value)
value.to_s.+(' kg').convert_to('lb').scalar.to_f.round(7)
end
fix_weights
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment