finished price updating
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
class Item < ActiveRecord::Base
|
||||
|
||||
CSV_COL = {
|
||||
:code => 0,
|
||||
:input_price => 1,
|
||||
:list_price => 2
|
||||
}
|
||||
|
||||
belongs_to :unit
|
||||
has_many :multi_media_descriptions
|
||||
belongs_to :sub_category
|
||||
@@ -97,4 +104,25 @@ class Item < ActiveRecord::Base
|
||||
return full_report
|
||||
end
|
||||
|
||||
def self.update_prices(path)
|
||||
nonexistent_codes = []
|
||||
|
||||
Item.transaction do
|
||||
CSV.foreach(path) do |row|
|
||||
code = row[CSV_COL[:code]].strip
|
||||
item = Item.find_by_code(code)
|
||||
if item.nil?
|
||||
nonexistent_codes << code
|
||||
else
|
||||
item.current_input_price = row[CSV_COL[:input_price]]
|
||||
item.list_price = row[CSV_COL[:list_price]]
|
||||
item.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
puts "Nonexistent codes: "
|
||||
puts nonexistent_codes.join("\n")
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user