mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Simplify error when tax rate can't be inherited
I changed the text to focus on the resolution: the user needs to choose a tax category or a different calculator. I associated the error to the model to prevent the attribute name from being included in the error message. Alternatively, we could have changed the name of the attribute to match the UI. But this error affects the combination of two attributes, none of them is invalid on its own. I'm using Rails' default lazy lookup for error messages which results in shorter code and a standard structure. I also added a simple spec.
This commit is contained in:
committed by
Mohamed ABDELLANI
parent
89eb3a1967
commit
25b7f1749c
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user