added order report to back office
This commit is contained in:
@@ -4,7 +4,22 @@ class Cart < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :delivery_destination
|
||||
|
||||
def delivery_cost
|
||||
place = Place.by_code_or_default(delivery_destination.place)
|
||||
if delivery_destination.instant_delivery
|
||||
place.instant_delivery_price
|
||||
else
|
||||
place.delivery_price
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def total
|
||||
sum = item_in_carts.inject (0) { |sum, iic| sum + (iic.price * iic.count) }
|
||||
sum += delivery_cost
|
||||
end
|
||||
|
||||
def confirmed_at
|
||||
delivery_destination.updated_at.in_time_zone('Europe/Sarajevo')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -521,4 +521,13 @@ class Place < ActiveRecord::Base
|
||||
|
||||
return "<nepoznato mjesto>";
|
||||
end
|
||||
|
||||
def self.by_code_or_default(code)
|
||||
# removes garbage and converts whitespace prefixed codes correctly - like " 71000" -> 71000
|
||||
valid_code = code.to_i.to_s
|
||||
place = Place.where(postal_code: valid_code).first
|
||||
place ||= Place.where("postal_code is null or postal_code = ''").first
|
||||
return place
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user