2013-09-18 12:44:41 +02:00
|
|
|
require_relative '../spec_helper'
|
2013-07-26 18:34:03 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
feature 'settling an order', js: true do
|
2017-03-04 14:15:18 +01:00
|
|
|
let(:ftt) { create :financial_transaction_type }
|
2013-09-18 12:44:41 +02:00
|
|
|
let(:admin) { create :user, groups:[create(:workgroup, role_finance: true)] }
|
2014-01-23 16:17:16 +01:00
|
|
|
let(:user) { create :user, groups:[create(:ordergroup)] }
|
2013-09-18 12:44:41 +02:00
|
|
|
let(:supplier) { create :supplier }
|
|
|
|
let(:article) { create :article, supplier: supplier, unit_quantity: 1 }
|
|
|
|
let(:order) { create :order, supplier: supplier, article_ids: [article.id] } # need to ref article
|
|
|
|
let(:go1) { create :group_order, order: order }
|
|
|
|
let(:go2) { create :group_order, order: order }
|
2013-07-26 18:34:03 +02:00
|
|
|
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
2013-09-18 12:44:41 +02:00
|
|
|
let(:goa1) { create :group_order_article, group_order: go1, order_article: oa }
|
|
|
|
let(:goa2) { create :group_order_article, group_order: go2, order_article: oa }
|
2013-07-26 18:34:03 +02:00
|
|
|
before do
|
|
|
|
goa1.update_quantities(3, 0)
|
|
|
|
goa2.update_quantities(1, 0)
|
|
|
|
oa.update_results!
|
|
|
|
order.finish!(admin)
|
|
|
|
goa1.reload
|
|
|
|
goa2.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has correct order result' do
|
|
|
|
expect(oa.quantity).to eq(4)
|
|
|
|
expect(oa.tolerance).to eq(0)
|
|
|
|
expect(goa1.result).to eq(3)
|
|
|
|
expect(goa2.result).to eq(1)
|
|
|
|
end
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
before { login admin }
|
|
|
|
before { visit new_finance_order_path(order_id: order.id) }
|
2013-07-26 18:34:03 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'has product ordered visible' do
|
|
|
|
expect(page).to have_content(article.name)
|
|
|
|
expect(page).to have_selector("#order_article_#{oa.id}")
|
|
|
|
end
|
2013-07-26 18:34:03 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'shows order result' do
|
|
|
|
click_link article.name
|
|
|
|
expect(page).to have_selector("#group_order_articles_#{oa.id}")
|
|
|
|
within("#group_order_articles_#{oa.id}") do
|
|
|
|
# make sure these ordergroup names are in the list for this product
|
2016-02-25 02:08:04 +01:00
|
|
|
expect(page).to have_content(go1.ordergroup_name)
|
|
|
|
expect(page).to have_content(go2.ordergroup_name)
|
2015-04-24 15:19:57 +02:00
|
|
|
# and that their order results match what we expect
|
|
|
|
expect(page).to have_selector("#r_#{goa1.id}")
|
|
|
|
expect(find("#r_#{goa1.id}").value.to_f).to eq(3)
|
|
|
|
expect(page).to have_selector("#r_#{goa2.id}")
|
|
|
|
expect(find("#r_#{goa2.id}").value.to_f).to eq(1)
|
2013-07-26 18:34:03 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
end
|
2013-07-26 18:34:03 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'keeps ordered quantities when article is deleted from resulting order' do
|
|
|
|
within("#order_article_#{oa.id}") do
|
2019-10-28 09:39:32 +01:00
|
|
|
accept_confirm do
|
|
|
|
click_link I18n.t('ui.delete')
|
|
|
|
end
|
2013-09-13 15:37:30 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(page).to_not have_selector("#order_article_#{oa.id}")
|
|
|
|
expect(OrderArticle.exists?(oa.id)).to be true
|
|
|
|
oa.reload
|
|
|
|
expect(oa.quantity).to eq(4)
|
|
|
|
expect(oa.tolerance).to eq(0)
|
|
|
|
expect(oa.units_to_order).to eq(0)
|
|
|
|
expect(goa1.reload.result).to eq(0)
|
|
|
|
expect(goa2.reload.result).to eq(0)
|
|
|
|
end
|
2013-09-13 15:37:30 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'deletes an OrderArticle with no GroupOrderArticles' do
|
|
|
|
goa1.destroy
|
|
|
|
goa2.destroy
|
|
|
|
within("#order_article_#{oa.id}") do
|
2019-10-28 09:39:32 +01:00
|
|
|
accept_confirm do
|
|
|
|
click_link I18n.t('ui.delete')
|
|
|
|
end
|
2013-09-13 15:37:30 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(page).to_not have_selector("#order_article_#{oa.id}")
|
|
|
|
expect(OrderArticle.exists?(oa.id)).to be false
|
|
|
|
end
|
2013-09-13 15:37:30 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'keeps ordered quantities when GroupOrderArticle is deleted from resulting order' do
|
|
|
|
click_link article.name
|
|
|
|
expect(page).to have_selector("#group_order_article_#{goa1.id}")
|
|
|
|
within("#group_order_article_#{goa1.id}") do
|
|
|
|
click_link I18n.t('ui.delete')
|
2013-09-17 14:19:46 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(page).to_not have_selector("#group_order_article_#{goa1.id}")
|
|
|
|
expect(OrderArticle.exists?(oa.id)).to be true
|
|
|
|
expect(GroupOrderArticle.exists?(goa1.id)).to be true
|
|
|
|
goa1.reload
|
|
|
|
expect(goa1.result).to eq(0)
|
|
|
|
expect(goa1.quantity).to eq(3)
|
|
|
|
expect(goa1.tolerance).to eq(0)
|
|
|
|
end
|
2013-09-17 14:19:46 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'deletes a GroupOrderArticle with no ordered amounts' do
|
|
|
|
goa1.update_attributes({:quantity => 0, :tolerance => 0})
|
|
|
|
click_link article.name
|
|
|
|
expect(page).to have_selector("#group_order_article_#{goa1.id}")
|
|
|
|
within("#group_order_article_#{goa1.id}") do
|
|
|
|
click_link I18n.t('ui.delete')
|
2013-09-17 14:19:46 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(page).to_not have_selector("#group_order_article_#{goa1.id}")
|
|
|
|
expect(OrderArticle.exists?(oa.id)).to be true
|
|
|
|
expect(GroupOrderArticle.exists?(goa1.id)).to be false
|
|
|
|
end
|
2013-09-17 14:19:46 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'keeps product when amount is set to zero' do
|
|
|
|
within("#order_article_#{oa.id}") do
|
|
|
|
click_link I18n.t('ui.edit')
|
2013-10-02 16:32:01 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
within("#edit_order_article_#{oa.id}") do
|
2019-10-28 09:39:32 +01:00
|
|
|
find('#order_article_units_to_order').set(0)
|
|
|
|
sleep 0.2
|
2015-04-24 15:19:57 +02:00
|
|
|
find('input[type="submit"]').click
|
2014-01-23 16:17:16 +01:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(page).to have_selector("#order_article_#{oa.id}")
|
|
|
|
# make sure it still works after reloading
|
|
|
|
visit new_finance_order_path(order_id: order.id)
|
|
|
|
expect(page).to have_selector("#order_article_#{oa.id}")
|
|
|
|
expect(OrderArticle.exists?(oa.id)).to be true
|
|
|
|
oa.reload
|
|
|
|
expect(oa.units_to_order).to eq(0)
|
|
|
|
end
|
2014-01-23 16:17:16 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'can add an ordergroup to an order article' do
|
|
|
|
user # need to reference user before "new article" dialog is loaded
|
|
|
|
click_link article.name
|
|
|
|
within("#group_order_articles_#{oa.id}") do
|
|
|
|
click_link I18n.t('finance.balancing.group_order_articles.add_group')
|
2014-01-23 16:17:16 +01:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(page).to have_selector('form#new_group_order_article')
|
|
|
|
within('#new_group_order_article') do
|
|
|
|
select user.ordergroup.name, :from => 'group_order_article_ordergroup_id'
|
2019-10-28 09:39:32 +01:00
|
|
|
find('#group_order_article_result').set(8)
|
|
|
|
sleep 0.2
|
2015-04-24 15:19:57 +02:00
|
|
|
find('input[type="submit"]').click
|
2014-01-23 16:17:16 +01:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(page).to_not have_selector('form#new_group_order_article')
|
|
|
|
expect(page).to have_content(user.ordergroup.name)
|
|
|
|
goa = GroupOrderArticle.last
|
|
|
|
expect(goa).to_not be_nil
|
|
|
|
expect(goa.result).to eq 8
|
|
|
|
expect(page).to have_selector("#group_order_article_#{goa.id}")
|
|
|
|
expect(find("#r_#{goa.id}").value.to_f).to eq 8
|
|
|
|
end
|
2014-01-23 16:17:16 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'can modify an ordergroup result' do
|
|
|
|
click_link article.name
|
|
|
|
within("#group_order_articles_#{oa.id}") do
|
2019-10-28 09:39:32 +01:00
|
|
|
find("#r_#{goa1.id}").set(5).send_keys(:tab) # tab to blur and let js update
|
2014-02-24 11:37:06 +01:00
|
|
|
end
|
2017-04-01 15:12:05 +02:00
|
|
|
expect(page).to have_selector('#summaryChangedWarning') # becomes visible after request is done
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(goa1.reload.result).to eq 5
|
|
|
|
expect(find("#group_order_articles_#{oa.id} tfoot td:nth-child(3)").text.to_f).to eq 6
|
|
|
|
end
|
2014-02-24 11:37:06 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'can modify an ordergroup result using the + button' do
|
|
|
|
click_link article.name
|
|
|
|
within("#group_order_article_#{goa1.id}") do
|
|
|
|
4.times { find('button[data-increment]').click }
|
|
|
|
end
|
2017-04-01 15:12:05 +02:00
|
|
|
expect(page).to have_selector('#summaryChangedWarning') # becomes visible after request is done
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(goa1.reload.result).to eq 7
|
|
|
|
expect(find("#group_order_articles_#{oa.id} tfoot td:nth-child(3)").text.to_f).to eq 8
|
2013-07-26 18:34:03 +02:00
|
|
|
end
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'can add an article' do
|
|
|
|
new_article = create :article, supplier: supplier
|
|
|
|
expect(page).to_not have_content(new_article.name)
|
|
|
|
click_link I18n.t('finance.balancing.edit_results_by_articles.add_article')
|
|
|
|
expect(page).to have_selector('form#new_order_article')
|
|
|
|
within('#new_order_article') do
|
2019-10-28 09:39:32 +01:00
|
|
|
find('#order_article_article_id').select(new_article.name)
|
|
|
|
sleep 0.1
|
2015-04-24 15:19:57 +02:00
|
|
|
find('input[type="submit"]').click
|
2019-10-28 09:39:32 +01:00
|
|
|
sleep 0.1
|
2015-04-24 15:19:57 +02:00
|
|
|
end
|
|
|
|
expect(page).to_not have_selector('form#new_order_article')
|
|
|
|
expect(page).to have_content(new_article.name)
|
|
|
|
expect(order.order_articles.where(article_id: new_article.id)).to_not be nil
|
|
|
|
end
|
2013-07-26 18:34:03 +02:00
|
|
|
end
|