Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed invoice billing info #1139

Merged
merged 6 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/billing_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions app/packs/src/global/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@
}
.ui.big.form {
.ui {
&.dropdown {
height: 45px;
}
&.search {
&.selection {
&.dropdown {
Expand Down
27 changes: 6 additions & 21 deletions app/views/common/pdf.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -218,32 +218,17 @@
<%= t('billing_profiles.name') %>
</dt>
<dd>
<%# if @invoice.billing_profile.present? %>
<%#= @invoice.billing_profile.name %>
<%# else %>
<%= @invoice.billing_name %>
<%# end %>
<%= @invoice.recipient %>
</dd>

<dt><%= t('billing_profiles.vat_code') %></dt>
<%# 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.vat_code %>
<dt><%= t('billing_profiles.vat_code') %></dt>
<dd><%= @invoice.vat_code %></dd>
<% end %>

<dt><%= t('billing_profiles.address') %></dt>
<dd>
<%# if @invoice.billing_profile.present? %>
<%#= @invoice.billing_profile.address %>
<%# else %>
<%= @invoice.billing_address %>
<%# end %>
<%= @invoice.address %>
</dd>
</dl>
</div>
Expand Down
14 changes: 7 additions & 7 deletions app/views/invoices/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } %>
</div>
<div class="column">
<div class="ui list">
Expand All @@ -27,16 +27,16 @@
<div class="ui list">
<div class="item">
<div class="header"><%= t('invoices.issuer') %></div>
<%= Setting.find_by(code: 'invoice_issuer').retrieve %>
</div>
<%= Setting.find_by(code: 'invoice_issuer').retrieve %>
</div>
<div class="item">
<div class="header"><%= t('invoices.issue_date') %></div>
<%= @invoice.issue_date %>
</div>
<%= @invoice.issue_date %>
</div>
<div class="item">
<div class="header"><%= t('invoices.due_date') %></div>
<%= @invoice.due_date %>
</div>
<%= @invoice.due_date %>
</div>
<% if @invoice.paid? %>
<div class="item">
<div class="header"><%= t('invoices.paid_at') %></div>
Expand Down
2 changes: 1 addition & 1 deletion db/data/20200221083433_populate_billing_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down