mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Solves Psych::DisallowedClass errors Example: https://github.com/openfoodfoundation/openfoodnetwork/actions/runs/14739687958/job/41374343627?pr=13232 unit_price returns object with amount and unit, as mentioned in https://github.com/openfoodfoundation/openfoodnetwork/pull/6905\#discussion_r578401368
40 lines
1.5 KiB
Ruby
40 lines
1.5 KiB
Ruby
# frozen_string_literal: false
|
|
|
|
class Invoice
|
|
class DataPresenter
|
|
class LineItem < Invoice::DataPresenter::Base
|
|
attributes :id, :added_tax, :currency, :included_tax, :price_with_adjustments, :quantity,
|
|
:variant_id, :unit_price, :unit_presentation,
|
|
:enterprise_fee_additional_tax, :enterprise_fee_included_tax
|
|
attributes_with_presenter :variant
|
|
invoice_generation_attributes :added_tax, :included_tax, :price_with_adjustments,
|
|
:quantity, :variant_id
|
|
|
|
delegate :name_to_display, :options_text, to: :variant
|
|
|
|
def amount_with_adjustments_without_taxes
|
|
fee_tax = enterprise_fee_included_tax || 0.0
|
|
(price_with_adjustments * quantity) - included_tax - fee_tax
|
|
end
|
|
|
|
def amount_with_adjustments_and_with_taxes
|
|
fee_tax = enterprise_fee_additional_tax || 0.0
|
|
( price_with_adjustments * quantity) + added_tax + fee_tax
|
|
end
|
|
|
|
def display_amount_with_adjustments_without_taxes
|
|
Spree::Money.new(amount_with_adjustments_without_taxes, currency:)
|
|
end
|
|
|
|
def display_amount_with_adjustments_and_with_taxes
|
|
Spree::Money.new(amount_with_adjustments_and_with_taxes, currency:)
|
|
end
|
|
|
|
def single_display_amount_with_adjustments
|
|
fee_tax = enterprise_fee_included_tax || 0.0
|
|
Spree::Money.new(price_with_adjustments - ((included_tax + fee_tax) / quantity), currency:)
|
|
end
|
|
end
|
|
end
|
|
end
|