From 4855b2e8e0951f634cff22483eed6dd64337701f Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 27 May 2014 17:58:38 +0200 Subject: [PATCH] Cleanup code --- app/models/list.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/list.rb b/app/models/list.rb index dc6229ab..769f891a 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -295,9 +295,10 @@ class List orders_placed_count = supplier.increment_orders_placed_count! loaded_products = self.class.database.load_document products.keys products.each do |product_id, quantity| - quantity = quantity.to_i product = loaded_products.find{|p| p.id == product_id} # to get the price - ProductOrder.create order: order, product_id: product_id, quantity: quantity, price: product.price, product_name: product.name if quantity > 0 + if quantity.to_i > 0 + ProductOrder.create(order: order, product_id: product_id, quantity: quantity, price: product.price, product_name: product.name) + end end set_price save