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 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/admin/companies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
row :name
row :slug
row :sector
row :isin
row :isin, &:isin_string
row :geography
row :headquarters_geography
row :ca100
Expand Down Expand Up @@ -119,7 +119,7 @@
column :name do |company|
link_to company.name, admin_company_path(company)
end
column :isin
column :isin, &:isin_string
column :size do |company|
company.size.humanize
end
Expand All @@ -136,7 +136,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
4 changes: 4 additions & 0 deletions app/models/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ def latest_assessment
def to_s
name
end

def isin_string
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this belongs to CompanyDecorator which needs to be created :)

Copy link
Contributor

Choose a reason for hiding this comment

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

also, this name is a bit confusing - this returns an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right! I've moved the method to a new decorator, and I've renamed it to isin_as_tags. 🙇

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

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