1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-26 20:54:21 +01:00
fab-manager/app/models/product_stock_movement.rb

26 lines
745 B
Ruby
Raw Normal View History

2022-08-05 15:25:51 +02:00
# frozen_string_literal: true
2022-08-23 11:19:07 +02:00
# A ProductStockMovement records a movement of a product's stock.
# Eg. 10 units of item X are added to the stock
2022-08-05 15:25:51 +02:00
class ProductStockMovement < ApplicationRecord
belongs_to :product
ALL_STOCK_TYPES = %w[internal external].freeze
enum stock_type: ALL_STOCK_TYPES.zip(ALL_STOCK_TYPES).to_h
2022-09-08 17:51:48 +02:00
ALL_REASONS = %w[inward_stock returned cancelled inventory_fix sold missing damaged].freeze
2022-08-05 15:25:51 +02:00
enum reason: ALL_REASONS.zip(ALL_REASONS).to_h
validates :stock_type, presence: true
validates :stock_type, inclusion: { in: ALL_STOCK_TYPES }
validates :reason, presence: true
validates :reason, inclusion: { in: ALL_REASONS }
2022-09-08 17:51:48 +02:00
before_create :set_date
def set_date
self.date = DateTime.current
end
2022-08-05 15:25:51 +02:00
end