-
Notifications
You must be signed in to change notification settings - Fork 0
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 #93 from javierav/feature/taxes
Add taxes calculators
- Loading branch information
Showing
4 changed files
with
118 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Taxes | ||
class Electricity | ||
def self.for(time_or_date) | ||
new(time_or_date).for | ||
end | ||
|
||
def initialize(time_or_date) | ||
@date = time_or_date.respond_to?(:to_date) ? time_or_date.to_date : time_or_date | ||
end | ||
|
||
def for | ||
case @date | ||
when Date.new(2023, 1, 1)..Date.new(2023, 12, 31) | ||
0.005 | ||
when Date.new(2024, 1, 1)..Date.new(2024, 3, 31) | ||
0.025 | ||
when Date.new(2024, 4, 1)..Date.new(2024, 6, 30) | ||
0.038 | ||
else | ||
0.0 | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Taxes | ||
class ValueAdd | ||
def self.for(time_or_date) | ||
new(time_or_date).for | ||
end | ||
|
||
def initialize(time_or_date) | ||
@date = time_or_date.respond_to?(:to_date) ? time_or_date.to_date : time_or_date | ||
end | ||
|
||
def for | ||
case Region.current.key.to_sym | ||
when :pen, :bal | ||
for_pb | ||
when :can | ||
for_can | ||
when :ceu, :mel | ||
for_cm | ||
end | ||
end | ||
|
||
private | ||
|
||
def for_pb | ||
case @date | ||
when Date.new(2023, 1, 1)..Date.new(2023, 12, 31) | ||
0.05 | ||
else | ||
0.1 | ||
end | ||
end | ||
|
||
def for_can | ||
0.0 | ||
end | ||
|
||
def for_cm | ||
0.01 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require "test_helper" | ||
|
||
module Taxes | ||
class ElectricityTest < ActiveSupport::TestCase | ||
test "from 2023-01-01 to 2023-12-31" do | ||
assert_in_delta 0.005, Electricity.for(Date.new(2023, 1, 1)) | ||
assert_in_delta 0.005, Electricity.for(Date.new(2023, 12, 31)) | ||
end | ||
|
||
test "from 2024-01-01 to 2024-03-31" do | ||
assert_in_delta 0.025, Electricity.for(Date.new(2024, 1, 1)) | ||
assert_in_delta 0.025, Electricity.for(Date.new(2024, 3, 31)) | ||
end | ||
|
||
test "from 2024-04-01 to 2024-06-30" do | ||
assert_in_delta 0.038, Electricity.for(Date.new(2024, 4, 1)) | ||
assert_in_delta 0.038, Electricity.for(Date.new(2024, 6, 30)) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "test_helper" | ||
|
||
module Taxes | ||
class ValueAddTest < ActiveSupport::TestCase | ||
test "when region is pen or bal" do | ||
%w[1 3].each do |region| | ||
Region.stub(:current, Region.new(region)) do | ||
assert_in_delta 0.05, ValueAdd.for(Date.new(2023, 1, 1)) | ||
assert_in_delta 0.05, ValueAdd.for(Date.new(2023, 12, 31)) | ||
assert_in_delta 0.1, ValueAdd.for(Date.new(2024, 1, 1)) | ||
end | ||
end | ||
end | ||
|
||
test "when region is can" do | ||
Region.stub(:current, Region.new("2")) do | ||
assert_in_delta 0.0, ValueAdd.for(Date.new(2023, 1, 1)) | ||
assert_in_delta 0.0, ValueAdd.for(Date.new(2023, 12, 31)) | ||
assert_in_delta 0.0, ValueAdd.for(Date.new(2024, 1, 1)) | ||
end | ||
end | ||
|
||
test "when region is ceu or mel" do | ||
%w[4 5].each do |region| | ||
Region.stub(:current, Region.new(region)) do | ||
assert_in_delta 0.01, ValueAdd.for(Date.new(2023, 1, 1)) | ||
assert_in_delta 0.01, ValueAdd.for(Date.new(2023, 12, 31)) | ||
assert_in_delta 0.01, ValueAdd.for(Date.new(2024, 1, 1)) | ||
end | ||
end | ||
end | ||
end | ||
end |