Sha256: 14212070d33569e178ba9d86089762589e8e99cf71054d06c67bca9419df0bd6

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

module Workarea
  module Avatax
    class TaxRequest::OrderLineItem < TaxRequest::LineItem
      attr_reader :order_item, :adjustment, :shipping

      def initialize(order_item:, adjustment:, adjustment_set:, quantity: nil, shipping: nil)
        @order_item = order_item
        @adjustment = adjustment
        @adjustment_set = adjustment_set
        @quantity = quantity
        @shipping = shipping
      end

      private

        def addresses
          return unless address = shipping&.address

          {
            shipTo: {
              line1:      address.street,
              line2:      address.street_2,
              city:       address.city,
              region:     address.region,
              country:    address.country.alpha2,
              postalCode: address.postal_code
            }
          }
        end

        def quantity
          @quantity || adjustment.quantity
        end

        def amount
          total = @adjustment_set.taxable_share_for adjustment
          if shipping.present? && shipping.partial?
            total *= quantity / order_item.quantity.to_f
          end
          total
        end

        def item_code
          order_item.sku
        end

        def tax_code
          adjustment.data["tax_code"]
        end

        def product
          @product ||= Mongoid::Factory.from_db(
            Catalog::Product,
            order_item.product_attributes
          )
        end

        def description
          return if order_item.product_attributes.empty?
          product.name
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-avatax-4.2.1 lib/workarea/avatax/tax_request/order_line_item.rb
workarea-avatax-4.2.0 lib/workarea/avatax/tax_request/order_line_item.rb