Sha256: 0cf3c1a1bb3039949996ddca8c53b15444393c33b2d90025833a1879ed76c373
Contents?: true
Size: 873 Bytes
Versions: 109
Compression:
Stored size: 873 Bytes
Contents
module Comee module Core class SupplierPayment < ApplicationRecord belongs_to :payment_order belongs_to :supplier_invoice validates :amount, presence: true, numericality: {greater_than: 0} validate :validate_amount def self.ransackable_attributes(_auth_object = nil) %w[id created_at updated_at] end def self.ransackable_associations(_auth_object = nil) %w[payment_order supplier_invoice] end def validate_amount return unless amount && payment_order running_total = payment_order.supplier_payments.sum(:amount) running_total -= amount_was if id remaining = payment_order.amount - running_total error = "Amount exceeded. The maximum amount you can set is #{remaining}" errors.add(:base, error) if amount > remaining end end end end
Version data entries
109 entries across 109 versions & 1 rubygems