Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/enable multiple isins #31

Merged
merged 4 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/admin/companies.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ActiveAdmin.register Company do
menu priority: 0, parent: 'TPI'

decorate_with CompanyDecorator

config.sort_order = 'name_asc'

publishable_scopes
Expand Down Expand Up @@ -34,7 +37,7 @@
row :name
row :slug
row :sector
row :isin
row :isin, &:isin_as_tags
row :geography
row :headquarters_geography
row :ca100
Expand Down Expand Up @@ -119,7 +122,7 @@
column :name do |company|
link_to company.name, admin_company_path(company)
end
column :isin
column :isin, &:isin_as_tags
column :size do |company|
company.size.humanize
end
Expand All @@ -136,7 +139,7 @@
f.inputs do
columns do
column { f.input :name }
column { f.input :isin }
column { f.input :isin, as: :tags }
end

columns do
Expand Down
7 changes: 7 additions & 0 deletions app/decorators/company_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CompanyDecorator < Draper::Decorator
delegate_all

def isin_as_tags
isin.split(',')
end
end
11 changes: 9 additions & 2 deletions app/services/import/companies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ def call

def import
import_each_with_logging(csv, FILEPATH) do |row|
company = Company.find_or_initialize_by(isin: row[:isin])
company = Company.find_or_initialize_by(name: row[:company_name])

company.isin = if company.isin.present?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't this be moved to company_attributes method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably so. I kept it here, but it doesn't make so much sense now. I'll move it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, actually, I would need to pass the current isin to that method if I were to manage this there. Currently the company_attributes is not aware of the record being updated. So not sure if that's worth it.

(company.isin.split(',') + [row[:isin]]).uniq.join(',')
else
row[:isin]
end

company.update!(company_attributes(row))

create_mq_assessment!(row, company)
Expand All @@ -28,6 +35,7 @@ def import
def cleanup
MQ::Assessment.destroy_all
CP::Assessment.destroy_all
Company.destroy_all
end

def csv
Expand Down Expand Up @@ -67,7 +75,6 @@ def company_attributes(row)
geography = Import::GeographyUtils.find_by_iso(fix_iso(row[:country_code]))

{
name: row[:company_name],
ca100: row[:ca100_company?] == 'Yes',
geography: geography,
headquarters_geography: geography,
Expand Down