Sha256: 7e4dd99171798eaa6fc5151b306e253016cd02dff3269085c989def07f2c3543

Contents?: true

Size: 692 Bytes

Versions: 2

Compression:

Stored size: 692 Bytes

Contents

Spree::LineItem.class_eval do
  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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_mollie_gateway-3.2.1 app/models/spree/line_item_decorator.rb
spree_mollie_gateway-3.2.0 app/models/spree/line_item_decorator.rb