add specs
This commit is contained in:
parent
e902aa0d5a
commit
45db0575b1
46 changed files with 714 additions and 238 deletions
|
|
@ -39,27 +39,18 @@ class MultiOrdersController < ApplicationController
|
|||
end
|
||||
return
|
||||
end
|
||||
|
||||
begin
|
||||
@multi_order = MultiOrder.new
|
||||
@multi_order.orders = orders
|
||||
@multi_order.ends = orders.map(&:ends).max
|
||||
@multi_order.save!
|
||||
#create multi group orders
|
||||
all_group_orders = orders.flat_map(&:group_orders)
|
||||
|
||||
grouped_by_ordergroup = all_group_orders.group_by(&:ordergroup_id)
|
||||
|
||||
grouped_by_ordergroup.each do |ordergroup_id, group_orders|
|
||||
multi_group_order = MultiGroupOrder.create!(
|
||||
multi_order: @multi_order, group_orders: group_orders
|
||||
)
|
||||
# Now, associate each group_order with the new multi_group_order
|
||||
group_orders.each do |group_order|
|
||||
group_order.update!(multi_group_order: multi_group_order)
|
||||
end
|
||||
suppliers = orders.map(&:supplier).map(&:name).join(', ')
|
||||
msg = "Multi Bestellung für #{suppliers} erstellt"
|
||||
respond_to do |format|
|
||||
flash[:notice] = msg
|
||||
format.js
|
||||
format.html { redirect_to finance_order_index_path }
|
||||
end
|
||||
redirect_to finance_order_index_path
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
flash[:alert] = t('errors.general_msg', msg: e.message)
|
||||
respond_to do |format|
|
||||
|
|
@ -71,9 +62,13 @@ class MultiOrdersController < ApplicationController
|
|||
|
||||
def destroy
|
||||
@multi_order = MultiOrder.find(params[:id])
|
||||
@multi_order.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to finance_order_index_path }
|
||||
if @multi_order.ordergroup_invoices.any?
|
||||
flash[:alert]= "Lösche erst die Rechnungen"
|
||||
redirect_to finance_order_index_path
|
||||
else
|
||||
@multi_order.destroy
|
||||
redirect_to finance_order_index_path
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue