Skip to content

Commit

Permalink
Fixed current_outgoing_stock_ordered_not_delivered method
Browse files Browse the repository at this point in the history
  • Loading branch information
Zank94 committed Aug 18, 2017
1 parent 6c2a7ad commit 51784a5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/product_nature_variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 51784a5

Please sign in to comment.