Last active
August 29, 2015 14:11
-
-
Save mixmix/1bd2241164c79b501fb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Storey.switch 'amc' | |
a = Account.current | |
suppliers = Supplier.where(account_number: 'BLA') + Supplier.where(account_number: 'HAINES') | |
supplier_ids = suppliers.map(&:id) | |
target_parts = Part.where supplier_id: supplier_ids ; p 'got' | |
parts_in_use = JobPart.select(:part_id).map(&:part_id).uniq | |
target_parts_in_use = target_parts.select {|p| parts_in_use.include? p.id } ; p 'got' | |
target_parts_in_use.count | |
target_parts_not_in_use = target_parts - target_parts_in_use ; p 'got' | |
target_parts_not_in_use.count | |
target_parts_in_use.each {|p| p.update_attribute(:active,false)} | |
#target_parts_not_in_use.destroy_all | |
# Part.where(id: target_parts_not_in_use.map(&:id)).destroy_all | |
Part.where(id: target_parts_not_in_use.map(&:id)).limit(200).find_each(batch_size: 50) do |p| | |
p.destroy ; print '.' | |
end |
to see the jobs involved:
parts = Part.where(id: [9, 10, 11, 12, 13, 14, 15, 16, 24770, 26135, 33402, 66585, 66586, 66588, 66589]) ; p 'done'
jobs = parts.map(&:jobs).flatten.map(&:id)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
target parts in use:
these belong to BLA or HAINES, but are attached to a job already. I've marked them as
not active