Skip to content

Commit

Permalink
Rewrote ProductNatureVariant#current_outgoing_stock_ordered_not_deliv…
Browse files Browse the repository at this point in the history
…ered to match both sale items and parcel items not related to sales
  • Loading branch information
Zank94 committed Aug 17, 2017
1 parent db74a1c commit 2682e7b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/models/product_nature_variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,10 @@ 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 = Sale.where(state: %w[order invoice])
sale_items = SaleItem.where(variant_id: id, sale_id: sales.pluck(:id)).includes(:parcel_items).where(parcel_items: { sale_item_id: nil })
sale_items.map(&:quantity).compact.sum.to_f
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
end

def picture_path(style = :original)
Expand Down

0 comments on commit 2682e7b

Please sign in to comment.