diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index cdad32ffb..d29ebe7cb 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 if request.referer
+ 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/billing_profile.rb b/app/models/billing_profile.rb
index 0bdef2b41..0cc3368e6 100644
--- a/app/models/billing_profile.rb
+++ b/app/models/billing_profile.rb
@@ -87,7 +87,7 @@ def mirror_address_to_attached_invoices
Invoice.with_billing_profile(billing_profile_id: id).find_each do |invoice|
next if invoice.paid?
- invoice.update_billing_address
+ invoice.update_billing_info
invoice.save!
end
end
diff --git a/app/models/invoice.rb b/app/models/invoice.rb
index bdac64f4b..92fe73b00 100644
--- a/app/models/invoice.rb
+++ b/app/models/invoice.rb
@@ -23,7 +23,7 @@ class Invoice < ApplicationRecord
validates :billing_profile, presence: true, on: :create
validate :user_id_must_be_the_same_as_on_billing_profile_or_nil
- before_update :update_billing_address
+ before_update :update_billing_info
before_create :set_invoice_number
@@ -254,7 +254,7 @@ def overdue?
due_date < Time.zone.today && issued?
end
- def update_billing_address
+ def update_billing_info
return if billing_profile.blank?
billing_fields = %w[vat_code street city postal_code alpha_two_country_code]
@@ -263,6 +263,11 @@ def update_billing_address
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/packs/src/global/_forms.scss b/app/packs/src/global/_forms.scss
index 32d531fb7..c65142ace 100644
--- a/app/packs/src/global/_forms.scss
+++ b/app/packs/src/global/_forms.scss
@@ -266,6 +266,9 @@
}
.ui.big.form {
.ui {
+ &.dropdown {
+ height: 45px;
+ }
&.search {
&.selection {
&.dropdown {
diff --git a/app/views/common/pdf.html.erb b/app/views/common/pdf.html.erb
index 13555c31b..3d8eb1489 100644
--- a/app/views/common/pdf.html.erb
+++ b/app/views/common/pdf.html.erb
@@ -218,32 +218,18 @@
<%= t('billing_profiles.name') %>
- <%# if @invoice.billing_profile.present? %>
- <%#= @invoice.billing_profile.name %>
- <%# else %>
- <%= @invoice.billing_name %>
- <%# end %>
+ <%= @invoice.billing_name %>
- <%= t('billing_profiles.vat_code') %>
- <%# if @invoice.billing_profile.present? %>
- <%# tag.dd do %>
- <%#= @invoice.billing_profile.vat_code %>
- <%# end if @invoice.billing_profile.vat_code %>
- <%# else %>
- <% tag.dd do %>
- <%= @invoice.billing_vat_code %>
- <% end if @invoice.billing_vat_code %>
- <%# end %>
+ <% if @invoice.billing_vat_code %>
+ <%= t('billing_profiles.vat_code') %>
+ <%= @invoice.billing_vat_code %>
+ <% end %>
<%= t('billing_profiles.address') %>
- <%# if @invoice.billing_profile.present? %>
- <%#= @invoice.billing_profile.address %>
- <%# else %>
- <%= @invoice.billing_address %>
- <%# end %>
+ <%= @invoice.billing_address %>
diff --git a/app/views/invoices/_form.html.erb b/app/views/invoices/_form.html.erb
index a00f481c4..bc1dacc49 100644
--- a/app/views/invoices/_form.html.erb
+++ b/app/views/invoices/_form.html.erb
@@ -2,9 +2,10 @@
+ <% selected_profile = params[:billing_profile_id].presence || invoice.billing_profile_id %>
<%= f.label :billing_profile, t('invoices.billing_profile') %>
<%= f.select :billing_profile_id,
- BillingProfile.where(user_id: invoice.user_id).collect { |b| [b.name, b.id] },
+ options_for_select(BillingProfile.where(user_id: invoice.user_id).pluck(:name, :id), selected_profile),
{},
class: "ui dropdown" %>
@@ -14,7 +15,7 @@
<%= f.submit t(:submit), class: "ui button primary", data: { turbo: false } %>
- <%= link_to t(:back), :back, class: "ui button secondary" %>
+ <%= link_to t(:back), :back, class: "ui button secondary", data: { turbo: false } %>
<% end %>
diff --git a/app/views/invoices/show.html.erb b/app/views/invoices/show.html.erb
index 9e7cc14fb..e8e4cfd67 100644
--- a/app/views/invoices/show.html.erb
+++ b/app/views/invoices/show.html.erb
@@ -13,7 +13,7 @@
edit_invoice_path(@invoice.uuid), class: 'ui button primary' %>
<% end %>
<%= link_to t('invoices.download'), download_invoice_path(@invoice.uuid),
- { class: 'ui button secondary', download: true } %>
+ class: 'ui button secondary', download: true, data: { turbo: false } %>
@@ -27,16 +27,16 @@
- <%= Setting.find_by(code: 'invoice_issuer').retrieve %>
-
+ <%= Setting.find_by(code: 'invoice_issuer').retrieve %>
+
- <%= @invoice.issue_date %>
-
+ <%= @invoice.issue_date %>
+
- <%= @invoice.due_date %>
-
+ <%= @invoice.due_date %>
+
<% if @invoice.paid? %>
diff --git a/config/locales/billing_profiles.en.yml b/config/locales/billing_profiles.en.yml
index 88935cddd..e162d7ce1 100644
--- a/config/locales/billing_profiles.en.yml
+++ b/config/locales/billing_profiles.en.yml
@@ -14,6 +14,9 @@ en:
errors: "prohibited this billing profile from being saved"
in_use_by_offer_short: "In use by an active offer"
in_use_by_offer: "Billing profile is already being used with an active offer"
+ created: "Billing profile successfully created!"
+ updated: "Billing profile successfully updated!"
+ deleted: "Billing profile successfully deleted!"
edit:
title: "Edit billing profile"
diff --git a/config/locales/billing_profiles.et.yml b/config/locales/billing_profiles.et.yml
index 269c7a5e7..4187d5dca 100644
--- a/config/locales/billing_profiles.et.yml
+++ b/config/locales/billing_profiles.et.yml
@@ -14,6 +14,9 @@ et:
errors: "seda arve aadressi ei saa salvestada"
in_use_by_offer_short: "Seotud mõne aktiivse pakkumisega"
in_use_by_offer: "Antud profiil on juba seotud mõne aktiivse pakkumisega"
+ created: "Arveldusprofiil edukalt loodud!"
+ updated: "Arveldusprofiil edukalt uuendatud!"
+ deleted: "Arveldusprofiil edukalt kustutatud!"
edit:
title: "Muuda arve aadressi"
diff --git a/db/data/20200221083433_populate_billing_fields.rb b/db/data/20200221083433_populate_billing_fields.rb
index d3d56fa00..eae9e9a40 100644
--- a/db/data/20200221083433_populate_billing_fields.rb
+++ b/db/data/20200221083433_populate_billing_fields.rb
@@ -9,7 +9,7 @@ def up
next if invoice.billing_profile.blank?
next unless invoice.recipient.nil?
- if invoice.update_billing_address && invoice.save
+ if invoice.update_billing_info && invoice.save
migrated_invoice_count += 1
else
failed_invoices << invoice.id
diff --git a/test/fixtures/invoices.yml b/test/fixtures/invoices.yml
index e028055f1..cdf7e6cab 100644
--- a/test/fixtures/invoices.yml
+++ b/test/fixtures/invoices.yml
@@ -36,3 +36,6 @@ orphaned:
uuid: "cec1de76-164f-4c9a-922d-dacde5e99f99"
in_directo: false
number: '87654321'
+ billing_name: "Orphan Profile"
+ billing_address: "Baker Street 221B, NW1 6XE London, United Kingdom"
+ billing_alpha_two_country_code: "GB"
diff --git a/test/system/billing_profiles_test.rb b/test/system/billing_profiles_test.rb
index e73a1604f..10641a33c 100644
--- a/test/system/billing_profiles_test.rb
+++ b/test/system/billing_profiles_test.rb
@@ -51,7 +51,7 @@ def test_a_user_can_create_billing_profile_for_a_vat_liable_company
click_link_or_button('Submit')
end
- assert(page.has_css?('div.notice', text: 'Created successfully.'))
+ assert(page.has_css?('div.notice', text: 'Billing profile successfully created!'))
end
# def test_billing_profile_vat_code_needs_to_be_unique_for_user
@@ -81,7 +81,7 @@ def test_a_user_can_create_company_billing_profile_witout_vat_code
.where(name: 'ACME corporation')
.where('vat_code IS NULL'))
- assert(page.has_css?('div.notice', text: 'Created successfully.'))
+ assert(page.has_css?('div.notice', text: 'Billing profile successfully created!'))
end
def test_a_user_can_create_private_billing_profile
@@ -93,7 +93,7 @@ def test_a_user_can_create_private_billing_profile
click_link_or_button('Submit')
end
- assert(page.has_css?('div.notice', text: 'Created successfully.'))
+ assert(page.has_css?('div.notice', text: 'Billing profile successfully created!'))
assert(BillingProfile.find_by(name: @user.display_name))
end
@@ -110,7 +110,7 @@ def test_a_user_can_edit_their_billing_profile
click_link_or_button('Submit')
end
- assert(page.has_css?('div.notice', text: 'Updated successfully.'))
+ assert(page.has_css?('div.notice', text: 'Billing profile successfully updated!'))
assert(BillingProfile.find_by(street: 'New Street 12', name: 'Joe John Participant-New',
country_code: 'PL'))
end
@@ -130,7 +130,7 @@ def test_a_user_can_delete_their_unused_billing_profile
click_link_or_button('Delete')
end
- assert_text('Deleted successfully.')
+ assert_text('Billing profile successfully deleted!')
end
def test_user_cannot_create_billing_profiles_in_the_name_of_other_user