Sha256: d60d949e6a0bb1934bd98a0f437e43e71fa659dc41decf7a922e86ce944ec248

Contents?: true

Size: 744 Bytes

Versions: 55

Compression:

Stored size: 744 Bytes

Contents

module Comee
  module Core
    class AdditionalService < ApplicationRecord
      before_save :calculate_total_price
      after_save :update_sales_order

      belongs_to :sales_order

      validates :name, :unit, presence: true
      validates :quantity, :price, presence: true, numericality: {greater_than: 0}

      def calculate_total_price
        self.total_price = (price * quantity).round(2)
      end

      def update_sales_order
        sales_order.calculate_total_price
        sales_order.calculate_vat
      end

      def self.ransackable_attributes(_auth_object = nil)
        %w[id name sales_order_id]
      end

      def self.ransackable_associations(_auth_object = nil)
        %w[sales_order]
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
comee_core-0.3.62 app/models/comee/core/additional_service.rb
comee_core-0.3.61 app/models/comee/core/additional_service.rb
comee_core-0.3.60 app/models/comee/core/additional_service.rb
comee_core-0.3.59 app/models/comee/core/additional_service.rb
comee_core-0.3.58 app/models/comee/core/additional_service.rb
comee_core-0.3.57 app/models/comee/core/additional_service.rb
comee_core-0.3.56 app/models/comee/core/additional_service.rb
comee_core-0.3.55 app/models/comee/core/additional_service.rb
comee_core-0.3.54 app/models/comee/core/additional_service.rb
comee_core-0.3.53 app/models/comee/core/additional_service.rb
comee_core-0.3.51 app/models/comee/core/additional_service.rb
comee_core-0.3.50 app/models/comee/core/additional_service.rb
comee_core-0.3.49 app/models/comee/core/additional_service.rb
comee_core-0.3.48 app/models/comee/core/additional_service.rb
comee_core-0.3.47 app/models/comee/core/additional_service.rb
comee_core-0.3.46 app/models/comee/core/additional_service.rb
comee_core-0.3.45 app/models/comee/core/additional_service.rb
comee_core-0.3.44 app/models/comee/core/additional_service.rb
comee_core-0.3.43 app/models/comee/core/additional_service.rb
comee_core-0.3.42 app/models/comee/core/additional_service.rb