Sha256: 58487ac75f5a878dc297322616264f142903f1003317c54218d530fe25b7fa91
Contents?: true
Size: 866 Bytes
Versions: 1
Compression:
Stored size: 866 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_deposit 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
comee_core-0.2.47 | app/models/comee/core/supplier_payment.rb |