wip multi orders
This commit is contained in:
parent
fd769509af
commit
f676497e43
29 changed files with 939 additions and 107 deletions
48
app/models/multi_order.rb
Normal file
48
app/models/multi_order.rb
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
class MultiOrder < ApplicationRecord
|
||||
has_many :orders, dependent: :nullify
|
||||
has_many :order_articles, through: :orders
|
||||
has_many :multi_group_orders, dependent: :destroy
|
||||
has_many :group_orders, through: :multi_group_orders
|
||||
has_many :ordergroups, through: :group_orders
|
||||
#TODO: wenn groupOrderInvoice existiert, dann fehler schmeißen..
|
||||
has_many :ordergroup_invoices, through: :group_orders
|
||||
|
||||
#make sure order has no multi_order_id
|
||||
#make sure orders are not in a multi_order
|
||||
before_create :check_orders
|
||||
|
||||
def name
|
||||
orders.map(&:name).join(', ')
|
||||
end
|
||||
|
||||
def closed?
|
||||
orders.all?(&:closed?)
|
||||
end
|
||||
|
||||
def stockit?
|
||||
orders.all?(&:stockit?)
|
||||
end
|
||||
|
||||
def updated_by
|
||||
orders.map(&:updated_by).compact.first
|
||||
end
|
||||
def updated_at
|
||||
orders.map(&:updated_at).compact.first
|
||||
end
|
||||
def foodcoop_result
|
||||
orders.map(&:foodcoop_result).compact_blank.sum
|
||||
end
|
||||
|
||||
private
|
||||
def check_orders
|
||||
orders.each do |order|
|
||||
errors.add(:base, "Order #{order.name} is already in a multi order") unless order.multi_order_id.nil?
|
||||
#closed==abgerechnet
|
||||
errors.add(:base, "Order #{order.name} not closed") unless order.closed?
|
||||
end
|
||||
if errors.any?
|
||||
errors.add(:base, "Cannot create multi order with unfinished orders")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue