Skip to content

Commit

Permalink
Merge pull request #2170 from ekylibre/performance/outgoing_payment
Browse files Browse the repository at this point in the history
Improve performance of outgoing payment
  • Loading branch information
Aquaj committed Mar 29, 2019
2 parents 54a933d + 94a254e commit 8c6f836
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def create
affairs = PurchaseAffair.where(id: params[:purchase_affairs].compact).uniq

mode_id = params[:outgoing_payment_list][:mode_id] if params[:outgoing_payment_list] && params[:outgoing_payment_list][:mode_id]
outgoing_payment_list = OutgoingPaymentList.build_from_affairs affairs, OutgoingPaymentMode.find_by(id: mode_id), current_user, params[:bank_check_number], true
outgoing_payment_list = OutgoingPaymentList.build_from_affairs(affairs, OutgoingPaymentMode.find_by(id: mode_id), current_user, params[:bank_check_number], true)
outgoing_payment_list.save!

redirect_to action: :show, id: outgoing_payment_list.id
Expand Down
5 changes: 2 additions & 3 deletions app/models/outgoing_payment_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ def self.build_from_purchase_affairs(affairs, mode, responsible, initial_check_n
end

def self.build_from_affairs(affairs, mode, responsible, initial_check_number = nil, ignore_empty_affair = false)
thirds = affairs.map(&:third).uniq
thirds = Entity.where(id: affairs.select(:third_id))
position = 0

purchase_payments = thirds.map do |third|
third_affairs = affairs.select { |a| a.third == third }.sort_by(&:created_at)
third_affairs = affairs.where(third: third).order(:created_at).to_a
first_affair = third_affairs.shift
third_affairs.map { |affair| first_affair.absorb!(affair) }

Expand Down

0 comments on commit 8c6f836

Please sign in to comment.