From bc719de8df8da76fb20ffb71c13202f9d243dd3e Mon Sep 17 00:00:00 2001 From: Lucas Sotty Date: Thu, 17 Aug 2017 11:25:57 +0200 Subject: [PATCH] Edited method since it only has to take into consideration variants linked to a sale and not left alone parcels --- app/models/product_nature_variant.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/product_nature_variant.rb b/app/models/product_nature_variant.rb index d1437f3738..e9c3a01202 100644 --- a/app/models/product_nature_variant.rb +++ b/app/models/product_nature_variant.rb @@ -435,9 +435,7 @@ def current_stock # Return current quantity of all products link to the variant currently ordered or invoiced but not delivered def current_outgoing_stock_ordered_not_delivered sales_not_delivered = Sale.where(state: %w(order invoice)).includes(:parcels).where(parcels: { state: %w(draft ordered in_preparation prepared) }) - sale_items_not_delivered = SaleItem.where(variant_id: id, sale_id: sales_not_delivered.pluck(:id)).sum(:quantity) - parcel_items_not_delivered = ParcelItem.where(variant_id: id, sale_item_id: nil).includes(:parcel).where(parcels: { state: %w(draft ordered in_preparation prepared) }).sum(:population) - (sale_items_not_delivered + parcel_items_not_delivered).to_f + SaleItem.where(variant_id: id, sale_id: sales_not_delivered.pluck(:id)).sum(:quantity).to_f end def picture_path(style = :original)