From d0e73ea1fffe37a73f9d516e1614b70d2ef81e98 Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Mon, 8 Feb 2021 01:05:13 +0100 Subject: [PATCH] Improve selecting deliveries/orders when creating an invoice When creating an invoice after balancing an order, it's not possible to the corresponding order. Change the elements in the select box to the latest ended/delivered items (which have not been assigned already) instead. --- app/controllers/finance/invoices_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/finance/invoices_controller.rb b/app/controllers/finance/invoices_controller.rb index cfdfa2db..289684a4 100644 --- a/app/controllers/finance/invoices_controller.rb +++ b/app/controllers/finance/invoices_controller.rb @@ -32,8 +32,8 @@ class Finance::InvoicesController < ApplicationController end def fill_deliveries_and_orders_collection(invoice_id, supplier_id) - @deliveries_collection = Delivery.where('invoice_id = ? OR (invoice_id IS NULL AND supplier_id = ?)', invoice_id, supplier_id).order(:date) - @orders_collection = Order.where('invoice_id = ? OR (invoice_id IS NULL AND supplier_id = ? AND state IN (?))', invoice_id, supplier_id, %w[finished received]).order(:ends) + @deliveries_collection = Delivery.where('invoice_id = ? OR (invoice_id IS NULL AND supplier_id = ?)', invoice_id, supplier_id).order(date: :desc).limit(25) + @orders_collection = Order.where('invoice_id = ? OR (invoice_id IS NULL AND supplier_id = ?)', invoice_id, supplier_id).order(ends: :desc).limit(25) end def create