Sha256: fe715ff39b1d6e47c7a080082b5befe03f7a1f234671ca4c0b92cb84bfa1892b

Contents?: true

Size: 773 Bytes

Versions: 2

Compression:

Stored size: 773 Bytes

Contents

module Spree::LineItemDecorator
  extend Spree::DisplayMoney
  money_methods :discount_amount, :vat_amount

  def discount_amount
    adjustments.eligible.non_tax.sum(:amount).abs
  end

  def vat_amount
    adjustments.eligible.tax.sum(:amount).abs
  end

  def mollie_identifier
    "#{id}-#{variant.sku}"
  end

  def vat_rate
    if adjustments.tax.any?
      # Spree allows line items to have multiple TaxRate adjustments.
      # Mollie does not support this. Raise an error if there > 1 TaxRate adjustment.
      if adjustments.tax.count > 1
        raise 'Mollie does not support multiple TaxRate adjustments per line item'
      end

      adjustments.tax.first.source.amount
    else
      0.00
    end
  end
end

Spree::LineItem.prepend(Spree::LineItemDecorator)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_mollie_gateway-4.0.1 app/models/spree/line_item_decorator.rb
spree_mollie_gateway-4.0.0 app/models/spree/line_item_decorator.rb