diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cdad32ffb..c2c88ac61 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,6 +22,10 @@ def set_locale @pagy_locale = I18n.locale.to_s end + def store_location + session[:return_to] = request.referer.split('?').first + end + # If needed, add updated_by to the params hash. Updated by takes format of "123 - User Surname" # When no current user is set, return back the hash as is. def merge_updated_by(update_params) diff --git a/app/controllers/billing_profiles_controller.rb b/app/controllers/billing_profiles_controller.rb index 3109eaa3f..db27a29fe 100644 --- a/app/controllers/billing_profiles_controller.rb +++ b/app/controllers/billing_profiles_controller.rb @@ -2,6 +2,7 @@ class BillingProfilesController < ApplicationController before_action :authenticate_user! before_action :set_billing_profile, only: %i[show edit update destroy] before_action :authorize_billing_profile_for_user, except: %i[new index create] + before_action :store_location, only: :new # GET /billing_profiles def index @@ -21,7 +22,8 @@ def create respond_to do |format| if create_predicate - format.html { redirect_to billing_profile_path(@billing_profile.uuid), notice: t(:created) } + redirect_uri = "#{session[:return_to]}?billing_profile_id=#{@billing_profile.id}" || billing_profile_path(@billing_profile.uuid) + format.html { redirect_to redirect_uri, notice: t('.created') } format.json { render :show, status: :created, location: @billing_profile } else format.html { render :new } @@ -40,7 +42,7 @@ def edit; end def update respond_to do |format| if update_predicate - format.html { redirect_to billing_profile_path(@billing_profile.uuid), notice: t(:updated) } + format.html { redirect_to billing_profile_path(@billing_profile.uuid), notice: t('.updated') } format.json { render :show, status: :ok, location: @billing_profile } else format.html { render :edit } @@ -53,7 +55,7 @@ def update def destroy if @billing_profile.deletable? @billing_profile.destroy! - redirect_to billing_profiles_path, notice: t(:deleted) + redirect_to billing_profiles_path, notice: t('.deleted') else redirect_to billing_profiles_path, notice: @billing_profile.errors[:base].to_sentence end diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 085d74d25..92fe73b00 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -263,6 +263,11 @@ def update_billing_info billing_profile.attributes.keys.each do |attribute| self[attribute] = billing_profile[attribute] if billing_fields.include? attribute end + + self.billing_name = billing_profile.name + self.billing_address = address + self.billing_vat_code = vat_code + self.billing_alpha_two_country_code = billing_profile.alpha_two_country_code end def self.with_billing_profile(billing_profile_id:) diff --git a/app/views/common/pdf.html.erb b/app/views/common/pdf.html.erb index 32d08332b..3d8eb1489 100644 --- a/app/views/common/pdf.html.erb +++ b/app/views/common/pdf.html.erb @@ -218,17 +218,18 @@ <%= t('billing_profiles.name') %>