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

[OPAL-529] invoices summary page - Tax not included in final Amount #771

Open
wants to merge 3 commits into
base: 4.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def index
def show
@invoice = MnoEnterprise::Invoice
.with_params(_metadata: { act_as_manager: current_user.id })
.select(:id, :price, :started_at, :ended_at, :created_at, :updated_at, :paid_at, :slug, :tax_pips_applied,
.select(:id, :price, :started_at, :ended_at, :created_at, :updated_at, :paid_at, :slug, :tax_pips_applied, :previous_total_due, :tax_payable,
:organization, { organizations: [:id, :name] },
:bills, bills: [:id, :adjustment, :billing_group, :end_user_price_cents, :currency, :description,
:closed_end_user_price, :closure_exchange_rate])
Expand Down Expand Up @@ -74,10 +74,10 @@ def create_adjustment

bill.save!
# Refetch invoice totals
invoice = MnoEnterprise::Invoice.select(:price, :total_due).find(params[:id]).first
invoice = MnoEnterprise::Invoice.select(:price, :total_due, :tax_payable).find(params[:id]).first

# Render invoice totals
render json: { id: bill.id, invoice: { price: invoice.price, total_due: invoice.total_due } }
render json: { id: bill.id, invoice: { price: invoice.price, total_due: invoice.total_due, tax_payable: invoice.tax_payable } }
end

# NOTE: it would be preferable to use Invoice#price_cents
Expand All @@ -101,10 +101,10 @@ def delete_adjustment
# instead of cancelled.
bill.destroy!
# Refetch invoice totals
invoice = MnoEnterprise::Invoice.select(:price, :total_due).find(params[:id]).first
invoice = MnoEnterprise::Invoice.select(:price, :total_due, :tax_payable).find(params[:id]).first

# Render invoice totals
render json: { invoice: { price: invoice.price, total_due: invoice.total_due } }
render json: { invoice: { price: invoice.price, total_due: invoice.total_due, tax_payable: invoice.tax_payable } }

end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
json.invoice do
json.extract! @invoice, :id, :price, :started_at, :ended_at, :created_at, :updated_at, :paid_at, :slug, :tax_pips_applied
json.extract! @invoice, :id, :price, :started_at, :ended_at, :created_at, :updated_at, :paid_at, :slug, :tax_pips_applied, :previous_total_due, :tax_payable
json.organization @invoice.organization, :id, :name

json.adjustments @invoice.bills.select(&:adjustment) do |bill|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module MnoEnterprise
let(:select_fields) do
{
bills: 'id,adjustment,billing_group,end_user_price_cents,currency,description,closed_end_user_price,closure_exchange_rate',
invoices: 'id,price,started_at,ended_at,created_at,updated_at,paid_at,slug,tax_pips_applied,organization,bills',
invoices: 'id,price,started_at,ended_at,created_at,updated_at,paid_at,slug,tax_pips_applied,previous_total_due,tax_payable,organization,bills',
organizations: 'id,name'
}
end
Expand Down Expand Up @@ -82,12 +82,13 @@ module MnoEnterprise
before { allow(invoice).to receive(:organization).and_return(organization) }
before { stub_api_v2(:get, "/invoices/#{invoice.id}", invoice, %i(organization), expected_params) }
before { stub_api_v2(:post, "/bills", bill) }
before { stub_api_v2(:get, "/invoices/#{invoice.id}", invoice, [], { fields: { invoices: 'price,total_due' } }) }
before { stub_api_v2(:get, "/invoices/#{invoice.id}", invoice, [], { fields: { invoices: 'price,total_due,tax_payable' } }) }
before { subject }

it { expect(data['id']).to eq(bill.id) }
it { expect(data['invoice']['total_due']['fractional']).to eq(invoice.total_due.cents.to_f.to_s) }
it { expect(data['invoice']['price']['fractional']).to eq(invoice.price.cents.to_f.to_s) }
it { expect(data['invoice']['tax_payable']['fractional']).to eq(invoice.tax_payable.cents.to_f.to_s) }
end

describe 'DELETE #delete_adjustment' do
Expand All @@ -106,11 +107,12 @@ module MnoEnterprise
})
end
before { stub_api_v2(:delete, "/bills/#{bill.id}") }
before { stub_api_v2(:get, "/invoices/#{invoice.id}", invoice, [], { fields: { invoices: 'price,total_due' } }) }
before { stub_api_v2(:get, "/invoices/#{invoice.id}", invoice, [], { fields: { invoices: 'price,total_due,tax_payable' } }) }
before { subject }

it { expect(data['invoice']['total_due']['fractional']).to eq(invoice.total_due.cents.to_f.to_s) }
it { expect(data['invoice']['price']['fractional']).to eq(invoice.price.cents.to_f.to_s) }
it { expect(data['invoice']['tax_payable']['fractional']).to eq(invoice.tax_payable.cents.to_f.to_s) }
end

describe 'POST #send_to_customer' do
Expand Down