2014-01-08 11:52:39 +01:00
|
|
|
require_relative '../spec_helper'
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
feature 'receiving an order', js: true do
|
2021-03-01 15:27:26 +01:00
|
|
|
let(:admin) { create :user, groups: [create(:workgroup, role_orders: true)] }
|
2014-01-08 11:52:39 +01:00
|
|
|
let(:supplier) { create :supplier }
|
|
|
|
let(:article) { create :article, supplier: supplier, unit_quantity: 3 }
|
|
|
|
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 }
|
|
|
|
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
|
|
|
let(:goa1) { create :group_order_article, group_order: go1, order_article: oa }
|
|
|
|
let(:goa2) { create :group_order_article, group_order: go2, order_article: oa }
|
|
|
|
|
|
|
|
# set quantities of group_order_articles
|
|
|
|
def set_quantities(q1, q2)
|
|
|
|
goa1.update_quantities(*q1)
|
|
|
|
goa2.update_quantities(*q2)
|
|
|
|
oa.update_results!
|
|
|
|
order.finish!(admin)
|
|
|
|
reload_articles
|
|
|
|
end
|
|
|
|
|
|
|
|
# reload all group_order_articles
|
|
|
|
def reload_articles
|
2014-03-18 17:29:40 +01:00
|
|
|
goa1.reload unless goa1.destroyed?
|
|
|
|
goa2.reload unless goa2.destroyed?
|
2014-01-08 11:52:39 +01:00
|
|
|
oa.reload
|
|
|
|
end
|
|
|
|
|
2014-01-08 13:07:11 +01:00
|
|
|
def check_quantities(units, q1, q2)
|
|
|
|
reload_articles
|
|
|
|
expect(oa.units).to eq units
|
2014-03-18 17:29:40 +01:00
|
|
|
expect(goa1.destroyed? ? 0 : goa1.result).to be_within(1e-3).of q1
|
|
|
|
expect(goa2.destroyed? ? 0 : goa2.result).to be_within(1e-3).of q2
|
2014-01-08 13:07:11 +01:00
|
|
|
end
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
before { login admin }
|
2014-01-08 13:07:11 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'has product ordered visible' do
|
2021-03-01 15:27:26 +01:00
|
|
|
set_quantities [3, 0], [0, 0]
|
2015-04-24 15:19:57 +02:00
|
|
|
visit receive_order_path(id: order.id)
|
|
|
|
expect(page).to have_content(article.name)
|
|
|
|
expect(page).to have_selector("#order_article_#{oa.id}")
|
|
|
|
end
|
2014-01-08 11:52:39 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'has product not ordered invisible' do
|
2021-03-01 15:27:26 +01:00
|
|
|
set_quantities [0, 0], [0, 0]
|
2015-04-24 15:19:57 +02:00
|
|
|
visit receive_order_path(id: order.id)
|
|
|
|
expect(page).to_not have_selector("#order_article_#{oa.id}")
|
|
|
|
end
|
2014-01-08 11:52:39 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'is not received by default' do
|
2021-03-01 15:27:26 +01:00
|
|
|
set_quantities [3, 0], [0, 0]
|
2015-04-24 15:19:57 +02:00
|
|
|
visit receive_order_path(id: order.id)
|
|
|
|
expect(find("#order_articles_#{oa.id}_units_received").value).to be_blank
|
|
|
|
end
|
2014-01-08 11:52:39 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'does not change anything when received is ordered' do
|
2021-03-01 15:27:26 +01:00
|
|
|
set_quantities [2, 0], [3, 2]
|
2015-04-24 15:19:57 +02:00
|
|
|
visit receive_order_path(id: order.id)
|
|
|
|
fill_in "order_articles_#{oa.id}_units_received", :with => oa.units_to_order
|
|
|
|
find('input[type="submit"]').click
|
|
|
|
expect(page).to have_selector('body')
|
2021-03-01 15:27:26 +01:00
|
|
|
check_quantities 2, 2, 4
|
2015-04-24 15:19:57 +02:00
|
|
|
end
|
2014-01-08 11:52:39 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'redistributes properly when received is more' do
|
2021-03-01 15:27:26 +01:00
|
|
|
set_quantities [2, 0], [3, 2]
|
2015-04-24 15:19:57 +02:00
|
|
|
visit receive_order_path(id: order.id)
|
|
|
|
fill_in "order_articles_#{oa.id}_units_received", :with => 3
|
|
|
|
find('input[type="submit"]').click
|
|
|
|
expect(page).to have_selector('body')
|
2021-03-01 15:27:26 +01:00
|
|
|
check_quantities 3, 2, 5
|
2015-04-24 15:19:57 +02:00
|
|
|
end
|
2014-01-08 11:52:39 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'redistributes properly when received is less' do
|
2021-03-01 15:27:26 +01:00
|
|
|
set_quantities [2, 0], [3, 2]
|
2015-04-24 15:19:57 +02:00
|
|
|
visit receive_order_path(id: order.id)
|
|
|
|
fill_in "order_articles_#{oa.id}_units_received", :with => 1
|
|
|
|
find('input[type="submit"]').click
|
|
|
|
expect(page).to have_selector('body')
|
2021-03-01 15:27:26 +01:00
|
|
|
check_quantities 1, 2, 1
|
2015-04-24 15:19:57 +02:00
|
|
|
end
|
2014-01-08 13:07:11 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'has a locked field when edited elsewhere' do
|
2021-03-01 15:27:26 +01:00
|
|
|
set_quantities [2, 0], [3, 2]
|
2015-04-24 15:19:57 +02:00
|
|
|
goa1.result = goa1.result + 1
|
|
|
|
goa1.save!
|
|
|
|
visit receive_order_path(id: order.id)
|
|
|
|
expect(find("#order_articles_#{oa.id}_units_received")).to be_disabled
|
2014-01-08 11:52:39 +01:00
|
|
|
end
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'leaves locked rows alone when submitted' do
|
2021-03-01 15:27:26 +01:00
|
|
|
set_quantities [2, 0], [3, 2]
|
2015-04-24 15:19:57 +02:00
|
|
|
goa1.result = goa1.result + 1
|
|
|
|
goa1.save!
|
|
|
|
visit receive_order_path(id: order.id)
|
|
|
|
find('input[type="submit"]').click
|
|
|
|
expect(page).to have_selector('body')
|
2021-03-01 15:27:26 +01:00
|
|
|
check_quantities 2, 3, 4
|
2015-04-24 15:19:57 +02:00
|
|
|
end
|
2014-01-08 11:52:39 +01:00
|
|
|
end
|