fix auto_close_and_send_min_quantity

This commit is contained in:
Patrick Gansterer 2018-06-19 22:12:34 +02:00
parent 4eef0f07d5
commit 4137992032
2 changed files with 9 additions and 1 deletions

View file

@ -278,7 +278,7 @@ class Order < ActiveRecord::Base
send_to_supplier!(created_by) send_to_supplier!(created_by)
elsif auto_close_and_send_min_quantity? elsif auto_close_and_send_min_quantity?
finish!(created_by) finish!(created_by)
send_to_supplier!(created_by) if order.sum >= order.supplier.min_order_quantity send_to_supplier!(created_by) if sum >= supplier.min_order_quantity.to_r
end end
end end

View file

@ -16,6 +16,14 @@ describe Order do
expect(order).to be_finished expect(order).to be_finished
end end
it 'sends mail if min_order_quantity has been reached' do
create :user, groups: [create(:ordergroup)]
create :order, created_by: User.first, starts: Date.yesterday, ends: 1.hour.ago, end_action: :auto_close_and_send_min_quantity
Order.finish_ended!
expect(ActionMailer::Base.deliveries.count).to eq 1
end
it 'needs a supplier' do it 'needs a supplier' do
expect(build(:order, supplier: nil)).to be_invalid expect(build(:order, supplier: nil)).to be_invalid
end end