Sha256: 5092f2adc50df702302fd1bbbd809f172b8dc3b9770a2a44c8fa6c23520a90c8
Contents?: true
Size: 1.52 KB
Versions: 6
Compression:
Stored size: 1.52 KB
Contents
module Comee module Core class MasterPrice < ApplicationRecord enum :status, {old: 0, current: 1, future: 2} belongs_to :supplier belongs_to :product belongs_to :previous_price, class_name: "Comee::Core::MasterPrice", optional: true validates :purchase_price, :status, :selling_price, :pp_valid_from, :pp_valid_to, :sp_valid_from, :sp_valid_to, presence: true validates :margin, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100} validates :product_id, uniqueness: {scope: %i[supplier_id previous_price_id]} validate :validate_primary_price, :validate_purchase_price_validity_dates, :validate_selling_price_validity_dates def validate_primary_price return unless product && primary count = MasterPrice.where(product: product, primary: true, active: true).count errors.add(:base, "There is already a primary supplier for item '#{product.code}'") if count.positive? end def validate_purchase_price_validity_dates return unless pp_valid_from && pp_valid_to period = Period.new(pp_valid_from, pp_valid_to) errors.add(:base, "Purchase price validity date range is not correct.") unless period.valid? end def validate_selling_price_validity_dates return unless sp_valid_from && sp_valid_to period = Period.new(sp_valid_from, sp_valid_to) errors.add(:base, "Selling price validity date range is not correct.") unless period.valid? end end end end
Version data entries
6 entries across 6 versions & 1 rubygems