From 7f526844888a9f2ad62abc752cd1345aae9505cf Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Tue, 9 May 2023 10:27:06 +0100 Subject: [PATCH] add check_calculators_compatibility_with_taxes before running enterprise bulk update --- .rubocop_todo.yml | 1 + app/controllers/admin/enterprise_fees_controller.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dc22595479..1d843fdf10 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -656,6 +656,7 @@ Metrics/BlockNesting: Metrics/ClassLength: Exclude: - 'app/components/products_table_component.rb' + - 'app/controllers/admin/enterprise_fees_controller.rb' - 'app/controllers/admin/enterprises_controller.rb' - 'app/controllers/admin/order_cycles_controller.rb' - 'app/controllers/admin/resource_controller.rb' diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb index 8bd4793c5b..3281b67317 100644 --- a/app/controllers/admin/enterprise_fees_controller.rb +++ b/app/controllers/admin/enterprise_fees_controller.rb @@ -7,6 +7,7 @@ module Admin before_action :load_enterprise_fee_set, only: :index before_action :load_data before_action :check_enterprise_fee_input, only: [:bulk_update] + before_action :check_calculators_compatibility_with_taxes, only: [:bulk_update] def index @include_calculators = params[:include_calculators].present? @@ -119,5 +120,17 @@ module Admin end end end + + def check_calculators_compatibility_with_taxes + enterprise_fee_bulk_params['collection_attributes'].each do |_, enterprise_fee| + next unless enterprise_fee['inherits_tax_category'] == "true" + next unless EnterpriseFee::PER_ORDER_CALCULATORS.include?(enterprise_fee['calculator_type']) + + flash[:error] = I18n.t( + 'activerecord.errors.models.enterprise_fee.inherit_tax_requires_per_item_calculator' + ) + return redirect_to redirect_path + end + end end end