mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Stub base_price and fees on variant serializer. Calculate basePricePercentage on variant.
This commit is contained in:
@@ -7,4 +7,5 @@ Darkswarm.factory 'Variants', ->
|
||||
extend: (variant)->
|
||||
variant.getPrice = ->
|
||||
variant.price * variant.line_item.quantity
|
||||
variant.basePricePercentage = variant.base_price / variant.price * 100
|
||||
variant
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
class Api::VariantSerializer < ActiveModel::Serializer
|
||||
attributes :id, :is_master, :count_on_hand, :name_to_display, :unit_to_display,
|
||||
:on_demand, :price
|
||||
:on_demand, :price, :fees
|
||||
|
||||
def price
|
||||
object.price_with_fees(options[:current_distributor], options[:current_order_cycle])
|
||||
end
|
||||
|
||||
def base_price
|
||||
1.00
|
||||
end
|
||||
|
||||
def fees
|
||||
{admin: 1.23, sales: 4.56, packing: 7.89, transport: 0.12}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# price_without_fees / price
|
||||
|
||||
@@ -5,6 +5,8 @@ describe 'Variants service', ->
|
||||
beforeEach ->
|
||||
variant =
|
||||
id: 1
|
||||
base_price: 80
|
||||
price: 100
|
||||
module 'Darkswarm'
|
||||
inject ($injector)->
|
||||
Variants = $injector.get("Variants")
|
||||
@@ -19,3 +21,5 @@ describe 'Variants service', ->
|
||||
it "will return the same object as passed", ->
|
||||
expect(Variants.register(variant)).toBe variant
|
||||
|
||||
it "initialises base price percentage", ->
|
||||
expect(Variants.register(variant).basePricePercentage).toEqual 80
|
||||
|
||||
Reference in New Issue
Block a user