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.
This commit is contained in:
Patrick Gansterer 2021-02-08 01:05:13 +01:00
parent 8fd484eda5
commit d0e73ea1ff

View file

@ -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