diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index 9acfc31134..598035abed 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -60,9 +60,7 @@ class EnterpriseFee < ApplicationRecord end if inherits_tax_category? && PER_ORDER_CALCULATORS.include?(calculator_type) - errors.add(:inherits_tax_category, - I18n.t("activerecord.errors.models." \ - "enterpise_fee.cannot_inherit_from_product_when_per_order_calculator_selected")) + errors.add(:base, :inherit_tax_requires_per_item_calculator) throw :abort end diff --git a/config/locales/en.yml b/config/locales/en.yml index e991f46884..aaea8d1f1b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -92,6 +92,8 @@ en: preferred_per_unit: "Calculator Per Unit:" errors: models: + enterprise_fee: + inherit_tax_requires_per_item_calculator: "Inheriting the tax categeory requires a per-item calculator." spree/user: attributes: email: @@ -113,8 +115,6 @@ en: using_producer_stock_settings_but_count_on_hand_set: "must be blank because using producer stock settings" on_demand_but_count_on_hand_set: "must be blank if on demand" limited_stock_but_no_count_on_hand: "must be specified because forcing limited stock" - enterpise_fee: - cannot_inherit_from_product_when_per_order_calculator_selected: "You cannot select 'Inherit From Product' when a per order calculator is selected" # Used by active_storage_validations errors: messages: diff --git a/spec/models/enterprise_fee_spec.rb b/spec/models/enterprise_fee_spec.rb index 2eeb2ae027..6d579a42dd 100644 --- a/spec/models/enterprise_fee_spec.rb +++ b/spec/models/enterprise_fee_spec.rb @@ -9,6 +9,19 @@ describe EnterpriseFee do describe "validations" do it { is_expected.to validate_presence_of(:name) } + + it "requires a per-item calculator to inherit tax" do + subject = build( + :enterprise_fee, + inherits_tax_category: true, + calculator: Calculator::FlatRate.new + ) + + expect(subject.save).to eq false + expect(subject.errors.full_messages.first).to eq( + "Inheriting the tax categeory requires a per-item calculator." + ) + end end describe "callbacks" do