From e569be1a3d28ccd4da3b1ee6f490e30e152b56a4 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Thu, 25 Jul 2024 12:43:29 +0300 Subject: [PATCH] fixed show auction action issue --- app/controllers/english_offers_controller.rb | 4 ++-- app/models/billing_profile.rb | 18 +++++++++++------- config/locales/billing_profiles.en.yml | 1 + config/locales/billing_profiles.et.yml | 1 + config/routes.rb | 10 +++++----- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/controllers/english_offers_controller.rb b/app/controllers/english_offers_controller.rb index 0e17a2cbf..138a10a29 100644 --- a/app/controllers/english_offers_controller.rb +++ b/app/controllers/english_offers_controller.rb @@ -54,13 +54,13 @@ def show # GET /english_offers/aa450f1a-45e2-4f22-b2c3-f5f46b5f906b/edit def edit @auction = @offer.auction - redirect_to auction_path(@auction.uuid) and return if update_not_allowed(@auction) + redirect_to root_path and return if update_not_allowed(@auction) end # PUT /english_offers/aa450f1a-45e2-4f22-b2c3-f5f46b5f906b def update @auction = Auction.english.with_user_offers(current_user.id).find_by(uuid: @offer.auction.uuid) - redirect_to auction_path(@auction.uuid) and return if update_not_allowed(@auction) + redirect_to root_path and return if update_not_allowed(@auction) inform_invalid_captcha and return unless recaptcha_valid if update_predicate(@auction) diff --git a/app/models/billing_profile.rb b/app/models/billing_profile.rb index ed58c63ae..81f1cbb04 100644 --- a/app/models/billing_profile.rb +++ b/app/models/billing_profile.rb @@ -19,7 +19,7 @@ class BillingProfile < ApplicationRecord has_many :domain_offer_histories has_many :invoices - scope :with_search_scope, ->(origin) { + scope :with_search_scope, lambda { |origin| if origin.present? joins(:user) .includes(:user) @@ -39,10 +39,12 @@ def self.search(params = {}) def vat_code_must_be_registered_in_vies # Vat code validation only for EU countries - vat_rate = Countries.vat_rate_from_alpha2_code(self.country_code) + vat_rate = Countries.vat_rate_from_alpha2_code(country_code) return if vat_code.blank? || vat_rate == BigDecimal(0) - errors.add(:vat_code, I18n.t('billing_profiles.vat_validation_error')) unless Valvat.new(self.vat_code).exists? + errors.add(:vat_code, I18n.t('billing_profiles.vat_validation_error')) unless Valvat.new(vat_code).exists? + rescue Valvat::RateLimitError + errors.add(:vat_code, I18n.t('billing_profiles.vat_validation_rate_limit_error')) end def issued_invoices @@ -67,7 +69,7 @@ def vat_rate # if Time.zone.now.year < 2024 # return BigDecimal(OLD_EST_RATE_VAT) # else - return BigDecimal(Setting.find_by(code: :estonian_vat_rate).retrieve, 2) + return BigDecimal(Setting.find_by(code: :estonian_vat_rate).retrieve, 2) # end end @@ -77,11 +79,11 @@ def vat_rate end def self.create_default_for_user(user_id) - return if find_by(user_id: user_id) + return if find_by(user_id:) user = User.find(user_id) - billing_profile = new(user: user, country_code: user.country_code, name: user.display_name) + billing_profile = new(user:, country_code: user.country_code, name: user.display_name) billing_profile.save! billing_profile @@ -116,11 +118,13 @@ def mirror_address_to_attached_invoices private def update_billing_information_for_invoices + return unless name_changed? || street_changed? || city_changed? || postal_code_changed? || country_code_changed? + issued_invoices.update_all( billing_name: name, billing_address: address, billing_vat_code: vat_code, billing_alpha_two_country_code: alpha_two_country_code - ) if name_changed? || street_changed? || city_changed? || postal_code_changed? || country_code_changed? + ) end end diff --git a/config/locales/billing_profiles.en.yml b/config/locales/billing_profiles.en.yml index abff44dae..3be4b89e6 100644 --- a/config/locales/billing_profiles.en.yml +++ b/config/locales/billing_profiles.en.yml @@ -18,6 +18,7 @@ en: updated: "Billing profile successfully updated!" deleted: "Billing profile successfully deleted!" vat_validation_error: "VAT code is not registered or not valid according to VIES" + vat_validation_rate_limit_error: "VAT code validation rate limit exceeded" vat_code_already_exists: "VAT code is already in use" edit: diff --git a/config/locales/billing_profiles.et.yml b/config/locales/billing_profiles.et.yml index 363fe8a08..518e58bee 100644 --- a/config/locales/billing_profiles.et.yml +++ b/config/locales/billing_profiles.et.yml @@ -18,6 +18,7 @@ et: updated: "Arveldusprofiil edukalt uuendatud!" deleted: "Arveldusprofiil edukalt kustutatud!" vat_validation_error: "Käibemaksukood ei ole registreeritud või ei ole VIESi kohaselt kehtiv." + vat_validation_rate_limit_error: "Käibemaksukoodi valideerimise kiiruse limiit on ületatud." vat_code_already_exists: "Käibemaksukood on juba kasutusel." edit: diff --git a/config/routes.rb b/config/routes.rb index 12b250650..dbe52295b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,11 +45,11 @@ namespace :admin, constraints: Constraints::Administrator.new do resources :auctions, concerns: %i[auditable] do - collection do - post 'bulk_starts_at', to: 'auctions#bulk_starts_at', as: 'bulk_starts_at' - post 'apply_auction_participants', to: 'auctions#apply_auction_participants', as: 'apply_auction_participants' + collection do + post 'bulk_starts_at', to: 'auctions#bulk_starts_at', as: 'bulk_starts_at' + post 'apply_auction_participants', to: 'auctions#apply_auction_participants', as: 'apply_auction_participants' + end end - end resources :bans, except: %i[new show edit update], concerns: %i[auditable] resources :statistics, only: :index @@ -82,7 +82,7 @@ devise_for :users, path: 'sessions', controllers: { confirmations: 'email_confirmations', sessions: 'auth/sessions', passwords: 'passwords' } - resources :auctions, only: %i[index show], param: :uuid do + resources :auctions, only: %i[index], param: :uuid do resources :offers, only: %i[new show create edit update destroy], shallow: true, param: :uuid do get 'delete' end