From 51784a589be12af2ca34907a17c537b7c028d80b Mon Sep 17 00:00:00 2001 From: Lucas Sotty Date: Fri, 18 Aug 2017 17:16:56 +0200 Subject: [PATCH] Fixed current_outgoing_stock_ordered_not_delivered method --- app/models/product_nature_variant.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/product_nature_variant.rb b/app/models/product_nature_variant.rb index e9c3a01202..e89edc8ecd 100644 --- a/app/models/product_nature_variant.rb +++ b/app/models/product_nature_variant.rb @@ -434,8 +434,9 @@ 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) }) - SaleItem.where(variant_id: id, sale_id: sales_not_delivered.pluck(:id)).sum(:quantity).to_f + quantity_ordered = self.sale_items.includes(:sale).where(sales: { state: %w[order invoice] }).sum(:quantity) + quantity_delivered = self.parcel_items.includes(:parcel).where(parcels: { state: 'given', nature: 'outgoing' }).sum(:population) + (quantity_ordered - quantity_delivered).to_f end def picture_path(style = :original)