mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
This keeps the `OrderBalance` abstraction but removes the old code now that the feature is enabled for all users in all instances and there are no bugs reported. It's become dead code.
65 lines
1.5 KiB
Ruby
65 lines
1.5 KiB
Ruby
module Api
|
|
class OrderSerializer < ActiveModel::Serializer
|
|
attributes :number, :completed_at, :total, :state, :shipment_state, :payment_state,
|
|
:outstanding_balance, :payments, :path, :cancel_path,
|
|
:changes_allowed, :changes_allowed_until, :item_count,
|
|
:shop_id
|
|
|
|
has_many :payments, serializer: Api::PaymentSerializer
|
|
|
|
# This method relies on `balance_value` as a computed DB column. See `CompleteOrdersWithBalance`
|
|
# for reference.
|
|
def outstanding_balance
|
|
-object.balance_value
|
|
end
|
|
|
|
def payments
|
|
object.payments.joins(:payment_method).where('state IN (?)', %w(completed pending))
|
|
end
|
|
|
|
def shop_id
|
|
object.distributor_id
|
|
end
|
|
|
|
def item_count
|
|
object.line_items.sum(:quantity)
|
|
end
|
|
|
|
def completed_at
|
|
object.completed_at.blank? ? "" : I18n.l(object.completed_at, format: "%b %d, %Y %H:%M")
|
|
end
|
|
|
|
def changes_allowed_until
|
|
return I18n.t(:not_allowed) unless object.changes_allowed?
|
|
|
|
I18n.l(object.order_cycle.andand.orders_close_at, format: "%b %d, %Y %H:%M")
|
|
end
|
|
|
|
def shipment_state
|
|
object.shipment_state || nil
|
|
end
|
|
|
|
def payment_state
|
|
object.payment_state || nil
|
|
end
|
|
|
|
def state
|
|
object.state || nil
|
|
end
|
|
|
|
def path
|
|
order_path(object)
|
|
end
|
|
|
|
def cancel_path
|
|
return nil unless object.changes_allowed?
|
|
|
|
cancel_order_path(object)
|
|
end
|
|
|
|
def changes_allowed
|
|
object.changes_allowed?
|
|
end
|
|
end
|
|
end
|