WIP: ProxyOrders don't require an order, calculating total for serialized proxy orders from standing order where order does not exist

This commit is contained in:
Rob Harrington
2016-12-12 11:35:06 +11:00
parent 3d3013a592
commit be8fa1f4e4
2 changed files with 9 additions and 1 deletions

View File

@@ -12,5 +12,9 @@ class StandingLineItem < ActiveRecord::Base
.any?
end
def total_estimate
(price_estimate || 0) * (quantity || 0)
end
default_scope order('id ASC')
end

View File

@@ -2,7 +2,11 @@ class Api::Admin::ProxyOrderSerializer < ActiveModel::Serializer
attributes :id, :state, :edit_path, :number, :completed_at, :order_cycle_id, :total
def total
object.total.to_money.to_s
if object.total.present?
object.total.to_money.to_s
else
object.standing_order.standing_line_items.sum(&:total_estimate)
end
end
def completed_at