From 7cfd3f58cef9ca14b551bb6bace90c76305f336d Mon Sep 17 00:00:00 2001 From: MAhsenArif Date: Fri, 17 Aug 2018 16:49:43 +0500 Subject: [PATCH 1/3] [OPAL-529] Invoice: Expose previous due and tax amount to frontend --- .../mno_enterprise/jpi/v1/admin/invoices_controller.rb | 2 +- .../mno_enterprise/jpi/v1/admin/invoices/show.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb b/api/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb index 2f66ae8a8..3cee9edb7 100644 --- a/api/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb +++ b/api/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb @@ -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]) diff --git a/api/app/views/mno_enterprise/jpi/v1/admin/invoices/show.json.jbuilder b/api/app/views/mno_enterprise/jpi/v1/admin/invoices/show.json.jbuilder index 32398c3b2..26fc33a44 100644 --- a/api/app/views/mno_enterprise/jpi/v1/admin/invoices/show.json.jbuilder +++ b/api/app/views/mno_enterprise/jpi/v1/admin/invoices/show.json.jbuilder @@ -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| From 103b4a1819dd704996a6ca90231ac2a784fd07ad Mon Sep 17 00:00:00 2001 From: Adam Abdelaziz Date: Wed, 22 Aug 2018 16:24:37 -0400 Subject: [PATCH 2/3] Update specs --- .../mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb index 7cbe44505..dfb2ebb7f 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb @@ -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 From f0135b6ed8eb3400a8a68500b4e875325b99adb4 Mon Sep 17 00:00:00 2001 From: MAhsenArif Date: Mon, 27 Aug 2018 16:48:54 +0500 Subject: [PATCH 3/3] [OPAL-529] Allow adjustments to also return updated invoice tax --- .../mno_enterprise/jpi/v1/admin/invoices_controller.rb | 8 ++++---- .../jpi/v1/admin/invoices_controller_spec.rb | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb b/api/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb index 3cee9edb7..77a336c8f 100644 --- a/api/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb +++ b/api/app/controllers/mno_enterprise/jpi/v1/admin/invoices_controller.rb @@ -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 @@ -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 diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb index dfb2ebb7f..ec0514219 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/admin/invoices_controller_spec.rb @@ -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 @@ -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