Skip to content

Commit edb1051

Browse files
committed
Add tax_reverse_charge_mode to Spree::TaxCategory and update related specs
Introduce the `tax_reverse_charge_mode` enum to the `Spree::TaxCategory` model, with values `disabled`, `loose`, and `strict`. The change includes a migration to add the `tax_reverse_charge_mode` column to the `spree_tax_categories` table, with a default value of `0` (disabled). Additionally, the English locale file has been updated to include translations for the new enum values. The `tax_reverse_charge_mode` enum allows for more granular control over tax applicability based on the reverse charge status of an address. This enhancement improves the flexibility and accuracy of tax calculations by enabling different tax handling modes.
1 parent 0f0fca2 commit edb1051

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

core/app/models/spree/tax_category.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ class TaxCategory < Spree::Base
1010
self.tax_rate_tax_categories = []
1111
end
1212

13+
enum :tax_reverse_charge_mode, {
14+
disabled: 0,
15+
loose: 1,
16+
strict: 2
17+
}, prefix: true
18+
1319
validates :name, presence: true
1420
validates_uniqueness_of :name, case_sensitive: true, unless: :deleted_at
1521

core/config/locales/en.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ en:
392392
is_default: Default
393393
name: Name
394394
tax_code: Tax Code
395+
tax_reverse_charge_mode: Tax Reverse Charge Mode
395396
spree/tax_rate:
396397
amount: Rate
397398
expires_at: Expiration Date
@@ -2273,6 +2274,10 @@ en:
22732274
tax_rate_amount_explanation: When using the "Default Tax" calculator, the amount is treated as a decimal amount to aid in calculations. (i.e. If the tax rate is 5% then enter 0.05) If using the "Flat Fee" calculator, the amount is used for the static fee.
22742275
tax_rate_level: Tax Rate Level
22752276
tax_rates: Tax Rates
2277+
tax_reverse_charge_modes:
2278+
disabled: Disabled
2279+
loose: Loose
2280+
strict: Strict
22762281
taxon: Taxon
22772282
taxon_attachment_removal_error: There was an error removing the attachment
22782283
taxon_edit: Edit Taxon
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class AddTaxReverseChargeModeToSpreeTaxCategories < ActiveRecord::Migration[7.0]
4+
def change
5+
add_column :spree_tax_categories, :tax_reverse_charge_mode, :integer, default: 0, null: false,
6+
comment: "Enum values: 0 = disabled, 1 = loose, 2 = strict"
7+
end
8+
end

core/spec/models/spree/tax_category_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,34 @@
4747
end
4848
end
4949
end
50+
51+
describe 'enum tax_reverse_charge_mode' do
52+
it 'defines the expected enum values' do
53+
expect(Spree::TaxCategory.tax_reverse_charge_modes).to eq({
54+
'disabled' => 0,
55+
'loose' => 1,
56+
'strict' => 2
57+
})
58+
end
59+
60+
it 'allows valid values' do
61+
tax_category = build(:tax_category)
62+
# Updates the tax_reverse_charge_mode to "strict"
63+
expect(tax_category).to be_valid
64+
tax_category.tax_reverse_charge_mode_strict!
65+
66+
# Updates the tax_reverse_charge_mode to "loose"
67+
expect(tax_category).to be_valid
68+
tax_category.tax_reverse_charge_mode_loose!
69+
expect(tax_category).to be_valid
70+
71+
# Updates the tax_reverse_charge_mode to "disabled"
72+
tax_category.tax_reverse_charge_mode_disabled!
73+
expect(tax_category).to be_valid
74+
end
75+
76+
it 'raises an error for invalid values' do
77+
expect { Spree::TaxCategory.new(tax_reverse_charge_mode: :invalid_status) }.to raise_error(ArgumentError)
78+
end
79+
end
5080
end

0 commit comments

Comments
 (0)