Sha256: 08b878e427e289366f09b32e8c2a17288f69e6960400b2e909254d42582cf952

Contents?: true

Size: 868 Bytes

Versions: 19

Compression:

Stored size: 868 Bytes

Contents

module Comee
  module Core
    class PurchaseRequisitionItem < ApplicationRecord
      before_save :calculate_total_price
      after_save :calculate_requisition_price

      enum processing_status: {unprocessed: 0, partially_processed: 1, fully_processed: 2}

      belongs_to :product
      belongs_to :unit
      belongs_to :supplier
      belongs_to :purchase_requisition
      belongs_to :purchase_order_item, optional: true

      validates :processing_status, :delivery_date, presence: true
      validates :quantity, :price, presence: true, numericality: {greater_than_or_equal_to: 0}

      def calculate_total_price
        self.total_price = price * quantity
      end

      def calculate_requisition_price
        purchase_requisition.total_price = purchase_requisition.calculate_total_price
        purchase_requisition.save!
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
comee_core-0.2.59 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.58 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.57 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.56 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.55 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.54 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.53 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.52 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.51 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.50 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.49 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.48 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.47 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.46 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.45 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.44 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.43 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.42 app/models/comee/core/purchase_requisition_item.rb
comee_core-0.2.41 app/models/comee/core/purchase_requisition_item.rb