merge automatic group order invoice generation
see https://github.com/foodcoops/foodsoft/pull/907 for reference and original work by viehlieb Co-authored-by: viehlieb <pf@pragma-shift.net> fix PDF Pdf make explicit deposit in invoices work add ordergroupname to invoice file name mark bold sum for vat exempt foodcoops download multiple group order invoice as zip
This commit is contained in:
parent
6abf998b56
commit
93143c28f2
37 changed files with 988 additions and 69 deletions
7
spec/factories/group_order_invoice.rb
Normal file
7
spec/factories/group_order_invoice.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require 'factory_bot'
|
||||
|
||||
FactoryBot.define do
|
||||
factory :group_order_invoice do
|
||||
group_order { create :group_order }
|
||||
end
|
||||
end
|
||||
72
spec/integration/group_order_invoices_spec.rb
Normal file
72
spec/integration/group_order_invoices_spec.rb
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
feature GroupOrderInvoice, js: true do
|
||||
let(:admin) { create :user, groups: [create(:workgroup, role_finance: true)] }
|
||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||
let(:article) { create :article, unit_quantity: 1 }
|
||||
let(:order) { create :order, supplier: article.supplier, article_ids: [article.id], ends: Time.now } # need to ref article
|
||||
let(:go) { create :group_order, order: order, ordergroup: user.ordergroup}
|
||||
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
||||
let(:ftt) { create :financial_transaction_type }
|
||||
let(:goa) { create :group_order_article, group_order: go, order_article: oa }
|
||||
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
before { login admin }
|
||||
|
||||
after { clear_enqueued_jobs }
|
||||
|
||||
it 'does not enqueue MailerJob when order is settled if tax_number or options not set' do
|
||||
goa.update_quantities 2, 0
|
||||
oa.update_results!
|
||||
visit confirm_finance_order_path(id: order.id)
|
||||
click_link_or_button I18n.t('finance.balancing.confirm.clear')
|
||||
expect(NotifyGroupOrderInvoiceJob).not_to have_been_enqueued
|
||||
end
|
||||
|
||||
it 'enqueues MailerJob when order is settled if tax_number or options are set' do
|
||||
goa.update_quantities 2, 0
|
||||
oa.update_results!
|
||||
order.reload
|
||||
FoodsoftConfig[:group_order_invoices] = { use_automatic_invoices: true }
|
||||
FoodsoftConfig[:contact][:tax_number] = 12_345_678
|
||||
visit confirm_finance_order_path(id: order.id, type: ftt)
|
||||
expect(page).to have_selector(:link_or_button, I18n.t('finance.balancing.confirm.clear'))
|
||||
click_link_or_button I18n.t('finance.balancing.confirm.clear')
|
||||
expect(NotifyGroupOrderInvoiceJob).to have_been_enqueued
|
||||
end
|
||||
|
||||
it 'generates Group Order Invoice when order is closed if tax_number is set' do
|
||||
goa.update_quantities 2, 0
|
||||
oa.update_results!
|
||||
FoodsoftConfig[:contact][:tax_number] = 12_345_678
|
||||
order.update!(state: 'closed')
|
||||
go.reload
|
||||
order.reload
|
||||
visit finance_order_index_path
|
||||
expect(page).to have_selector(:link_or_button, I18n.t('activerecord.attributes.group_order_invoice.links.generate'))
|
||||
click_link_or_button I18n.t('activerecord.attributes.group_order_invoice.links.generate')
|
||||
expect(GroupOrderInvoice.all.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'generates multiple Group Order Invoice for order when order is closed if tax_number is set' do
|
||||
goa.update_quantities 2, 0
|
||||
oa.update_results!
|
||||
FoodsoftConfig[:contact][:tax_number] = 12_345_678
|
||||
order.update!(state: 'closed')
|
||||
order.reload
|
||||
visit finance_order_index_path
|
||||
expect(page).to have_selector(:link_or_button, I18n.t('activerecord.attributes.group_order_invoice.links.generate_with_date'))
|
||||
click_link_or_button I18n.t('activerecord.attributes.group_order_invoice.links.generate_with_date')
|
||||
expect(GroupOrderInvoice.all.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'does not generate Group Order Invoice when order is closed if tax_number not set' do
|
||||
goa.update_quantities 2, 0
|
||||
oa.update_results!
|
||||
order.update!(state: 'closed')
|
||||
order.reload
|
||||
visit finance_order_index_path
|
||||
expect(page).to have_content(I18n.t('activerecord.attributes.group_order_invoice.tax_number_not_set'))
|
||||
end
|
||||
end
|
||||
59
spec/models/group_order_invoice_spec.rb
Normal file
59
spec/models/group_order_invoice_spec.rb
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe GroupOrderInvoice do
|
||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||
let(:supplier) { create :supplier }
|
||||
let(:article) { create :article, supplier: supplier }
|
||||
let(:order) { create :order }
|
||||
let(:group_order) { create :group_order, order: order, ordergroup: user.ordergroup }
|
||||
|
||||
describe 'erroneous group order invoice' do
|
||||
let(:goi) { create :group_order_invoice, group_order_id: group_order.id }
|
||||
it 'does not create group order invoice if tax_number not set' do
|
||||
expect { goi }.to raise_error(ActiveRecord::RecordInvalid, /.*/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'valid group order invoice' do
|
||||
before do
|
||||
FoodsoftConfig[:contact][:tax_number] = 123_457_8
|
||||
end
|
||||
|
||||
invoice_number1 = Time.now.strftime("%Y%m%d") + '0001'
|
||||
invoice_number2 = Time.now.strftime("%Y%m%d") + '0002'
|
||||
|
||||
let(:user2) { create :user, groups: [create(:ordergroup)] }
|
||||
|
||||
let(:goi1) { create :group_order_invoice, group_order_id: group_order.id }
|
||||
let(:goi2) { create :group_order_invoice, group_order_id: group_order.id }
|
||||
|
||||
let(:group_order2) { create :group_order, order: order, ordergroup: user2.ordergroup }
|
||||
|
||||
let(:goi3) { create :group_order_invoice, group_order_id: group_order2.id }
|
||||
let(:goi4) { create :group_order_invoice, group_order_id: group_order2.id, invoice_number: invoice_number1 }
|
||||
|
||||
it 'creates group order invoice if tax_number is set' do
|
||||
expect(goi1).to be_valid
|
||||
end
|
||||
|
||||
it 'sets invoice_number according to date' do
|
||||
number = Time.now.strftime("%Y%m%d") + '0001'
|
||||
expect(goi1.invoice_number).to eq(number.to_i)
|
||||
end
|
||||
|
||||
it 'fails to create if group_order_id is used multiple times for creation' do
|
||||
expect(goi1.group_order.id).to eq(group_order.id)
|
||||
expect { goi2 }.to raise_error(ActiveRecord::RecordNotUnique)
|
||||
end
|
||||
|
||||
it 'creates two different group order invoice with different invoice_numbers' do
|
||||
expect(goi1.invoice_number).to eq(invoice_number1.to_i)
|
||||
expect(goi3.invoice_number).to eq(invoice_number2.to_i)
|
||||
end
|
||||
|
||||
it 'fails to create two different group order invoice with same invoice_numbers' do
|
||||
goi1
|
||||
expect { goi4 }.to raise_error(ActiveRecord::RecordInvalid)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue