Created
February 24, 2020 17:31
-
-
Save mbutsko/f37c2f3feb1d6d5cdc0266ee86d5a920 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
account_id = '4bae2dcd-fc39-4aad-b5b2-b3dcc562995a' | |
account = Account.find(account_id) | |
policy = PolicyService.current_policy(:account_id => account.id) | |
base_quote = policy.active_term.quote | |
new_profile = ProfileService.update(policy.profile, []).profile | |
profile_rating_data = EndorsementService.endorsement_profile_rating_data( | |
:account_id => account_id, | |
:profile_id => new_profile.id, | |
:base_quote => base_quote | |
) | |
prior_coverage_request = VeriskPriorCoverageRequest.find_by(:account_id => account_id) | |
prior_coverage_request.update(:prior_insurance_class_override => 'A') | |
profile_rating_data.update!( | |
:prior_insurance_class => nil | |
) | |
rating_request = RatingRequests::EndorsementService.create_rating_request!( | |
:profile_rating_data => profile_rating_data, | |
:policy_rating_data => RatingRequest.non_preliminary.for_account(account).last_created.auto_policy_rating_data | |
:base_quote_id => base_quote.id, | |
:version => policy.rate.version | |
) | |
sleep 30 | |
new_quote = rating_request.quotes.last_created | |
raise "Coverage Changes" unless CoverageDiffService.generate_diff( | |
:from_quote => policy.quote, | |
:to_quote => new_quote_to_check | |
).empty? | |
old_premium_in_dollars = policy.quote.premium_in_dollars(:monthly => policy.monthly?) | |
new_quote_premium_in_dollars = new_quote.premium_in_dollars(:monthly => policy.monthly?) | |
raise "Does not save money" unless new_quote_premium_in_dollars < old_premium_in_dollars | |
EndorsementService.change_policy(:quote_id => new_quote.id) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment