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
Generate ChargeBack report by Tenant #7433
Generate ChargeBack report by Tenant #7433
Conversation
@miq-bot add-label wip |
@miq-bot remove-label wip |
@@ -373,6 +373,7 @@ def check_tabs | |||
elsif @edit[:new][:model] == "Chargeback" | |||
unless @edit[:new][:cb_show_typ] && | |||
((@edit[:new][:cb_show_typ] == "owner" && @edit[:new][:cb_owner_id]) || | |||
(@edit[:new][:cb_show_typ] == "tenant" && @edit[:new][:cb_tenant_id]) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aljesusg can you move this huge condition (and if it is possible change it somehow for better readibility) to a method valid_chargeback_fields
then we can get here
elsif @edit[:new][:model] == "Chargeback" && !valid_chargeback_fields
add_flash..
....
what do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok @lpichler It's fine. I am working on it. I have 2 proposal that you can check here https://tree.taiga.io/project/sergioocon-charging-in-manageiq/task/40 but Rubocop throw a complexity errors :(
# Check if chargeback field is valid
VALID_SHOW_TYP_FIELDS = %w(owner tenant tag).freeze
def valid_chargeback_fields
if @edit[:new][:cb_show_typ] && VALID_SHOW_TYP_FIELDS.include?(@edit[:new][:cb_show_typ])
case @edit[:new][:cb_show_typ]
when "owner"
return true if @edit[:new][:cb_owner_id]
when "tenant"
return true if @edit[:new][:cb_tenant_id]
when "tag"
return true if @edit[:new][:cb_tag_cat] && @edit[:new][:cb_tag_value]
end
end
false
end
# Check if chargeback field is valid
VALID_SHOW_TYP_FIELDS = %w(owner tenant tag).freeze
def valid_chargeback_fields
if @edit[:new][:cb_show_typ] && VALID_SHOW_TYP_FIELDS.include?(@edit[:new][:cb_show_typ])
case @edit[:new][:cb_show_typ]
when "owner" then return true if @edit[:new][:cb_owner_id]
when "tenant" then return true if @edit[:new][:cb_tenant_id]
when "tag" then return true if @edit[:new][:cb_tag_cat] && @edit[:new][:cb_tag_value]
end
end
false
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aljesusg yes, much better - I am for 1.,and I am suggesting also something like this:
# Check if chargeback field is valid
def valid_chargeback_fields
is_valid = false
if %w(owner tenant tag).include?(@edit[:new][:cb_show_typ])
is_valid = case @edit[:new][:cb_show_typ]
when "owner" then @edit[:new][:cb_owner_id]
when "tenant" then @edit[:new][:cb_tenant_id]
when "tag" then @edit[:new][:cb_tag_cat] && @edit[:new][:cb_tag_value]
end
is_valid
end
inspired by https://github.com/bbatsov/ruby-style-guide and find on this page When assigning the result of a conditional expression to a variable
maybe this will rubocop accept :)
@aljesusg I was able to save report when "Show costs by tenant" was selected(= 'Tenant') but "Tenant" select box was unselected (= 'choose tenant') |
I was looking into db how it is stored: from MiqReport#db_options:
so there will be
Do you agree ? |
@aljesusg otherwise looks good to me ! It will be also nice to write spec for generating report to ensure if it considers only VMs which belongs to any tenant or basically test method @gtanzillo can you review it also, please ? |
d99f1ae
to
8ba6ca3
Compare
Update editor.rb Improve function valid chargeback fields
8ba6ca3
to
38a1214
Compare
Fixed rubocop
e7a5679
to
53650dd
Compare
Checked commits aljesusg/manageiq@38a1214~...53650dd with ruby 2.2.3, rubocop 0.37.2, and haml-lint 0.16.1 |
Done !!! |
Thanks @lpichler , @gtanzillo & @chessbyte |
After have assignment to tenant #7202 we need make a chargeback report by tenant.
Description
This pull request provides a chargeback report by tenant
Now we can show costs by Tenant
And select the tenant that we wanna get the report
### Working with
@lpichler
More Information
Taiga:
https://tree.taiga.io/project/sergioocon-charging-in-manageiq/task/40