Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (-> {
- ApplicationRecord.logger.level = 1
- range = Date.new(2018, 2, 28).all_day
- Branch.switch_each do |branch|
- movements =
- Inventory::Movement.
- where(created_at: range).
- preload(:product).
- sort_by { |movement| movement.product.code.downcase }
- next if movements.empty?
- path = Rails.root.join("tmp/#{branch.code}-inventory-movements-2018-02-28.csv").to_s
- count = movements.size
- CSV.open path, 'wb' do |csv|
- csv << ['Code', 'Description', 'Qty', 'Supplier price']
- movements.each.with_index 1 do |movement, i|
- product = movement.product
- supplier_prices = Product::SupplierPricesPresenter.new(product).supplier_prices
- last_price = supplier_prices.find { |supplier_price| supplier_price[:time] <= range.last }.try!(:[], :price)
- csv << [
- product.code,
- product.description,
- movement.inventory_summary_quantity,
- ActiveSupport::NumberHelper.number_to_currency(last_price, unit: 'R')
- ]
- print "\r#{path} (#{i}/#{count})"
- end
- end
- puts
- end
- ApplicationRecord.logger.level = 0
- true
- }).call
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement