Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #661 from trade-tariff/HOTT-3649-alcohol-calculati…
…ons-spq HOTT-3649: Adds evaluator for SPQ component
- Loading branch information
Showing
21 changed files
with
411 additions
and
80 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# SPQ is a complementary evaluator for the SPQ measurement unit on excise measure components | ||
# It is the only evaluator that needs to reference the other components in the measure condition | ||
# | ||
# It cannot exist in a non-compound (non-multi-component form) | ||
# | ||
# It has two modes of operation: | ||
# 1. LPA-based (where the other components are LPA we will use the LPA answer) | ||
# 2. ASVX-based (where the other components are ASVX we will use the ASVX answer) | ||
module ExpressionEvaluators | ||
class Spq < ExpressionEvaluators::Base | ||
include MeasureUnitPresentable | ||
|
||
def call | ||
{ | ||
calculation: measure_condition.duty_expression, | ||
value:, | ||
formatted_value: number_to_currency(value), | ||
} | ||
end | ||
|
||
private | ||
|
||
def value | ||
@value ||= begin | ||
candidate_value = if measure_condition.lpa_based? | ||
lpa_value | ||
elsif measure_condition.asvx_based? | ||
asvx_value | ||
end | ||
|
||
candidate_value.present? ? candidate_value.to_f.floor(2) : 0.0 | ||
end | ||
end | ||
|
||
def lpa_value | ||
component.duty_amount * lpa_answer * spr_answer | ||
end | ||
|
||
def asvx_value | ||
component.duty_amount * asv_answer * hlt_answer * spr_answer | ||
end | ||
|
||
def asv_answer | ||
coerced_answer_for(applicable_units[Api::BaseComponent::ALCOHOL_UNIT]) | ||
end | ||
|
||
def hlt_answer | ||
coerced_answer_for(applicable_units[Api::BaseComponent::HECTOLITERS_UNIT]) | ||
end | ||
|
||
def spr_answer | ||
coerced_answer_for(applicable_units[Api::BaseComponent::SPR_DISCOUNT_UNIT]) | ||
end | ||
|
||
def lpa_answer | ||
coerced_answer_for(applicable_units[Api::BaseComponent::LITERS_PURE_ALCOHOL_UNIT]) | ||
end | ||
end | ||
end |
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
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
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
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
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
Oops, something went wrong.