12878: add migration to show new column product column

This commit is contained in:
Ahmed Ejaz
2024-10-12 03:52:00 +05:00
parent b7285e48b3
commit 60e8db9adc

View File

@@ -0,0 +1,39 @@
class UpdateItemNameToProductInODReport < ActiveRecord::Migration[7.0]
# OD: Orders and Distributors
def up
# adding subtype filter just to be safe
options = ReportRenderingOptions.where(report_type: 'orders_and_distributors', report_subtype: nil)
options.find_each do |option|
begin
fields_to_show = option.options[:fields_to_show]
next if fields_to_show&.exclude?('item_name')
fields_to_show.delete('item_name')
fields_to_show << 'product'
option.update(options: option.options)
rescue StandardError => e
puts "Failed to update rendering option with id: #{option.id}"
puts "Error: #{e.message}"
end
end
end
def down
options = ReportRenderingOptions.where(report_type: 'orders_and_distributors', report_subtype: nil)
options.find_each do |option|
begin
fields_to_show = option.options[:fields_to_show]
next if fields_to_show&.exclude?('product')
fields_to_show.delete('product')
fields_to_show << 'item_name'
option.update(options: option.options)
rescue StandardError => e
puts "Failed to revert rendering option with id: #{option.id}"
puts "Error: #{e.message}"
end
end
end
end