1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Add presence validations for required fields (#545)

* Adds basic validations for required fields

Also deletes a few extraneous .keep files

Does not add the family_id required field for user, since that breaks the basic test setup

* Restore keep files to this branch

* Remove Credit model and validate models behind ids

* Restore concerns .keep
This commit is contained in:
Dave Corson-Knowles 2024-03-15 12:21:59 -07:00 committed by GitHub
parent a4c97a9d52
commit e5750d1a13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 12 additions and 0 deletions

View file

@ -1,6 +1,8 @@
class Account < ApplicationRecord
include Syncable
validates :family, presence: true
broadcasts_refreshes
belongs_to :family
has_many :balances, class_name: "AccountBalance"

View file

@ -1,6 +1,8 @@
class AccountBalance < ApplicationRecord
belongs_to :account
validates :account, :date, :balance, presence: true
scope :in_period, ->(period) { period.date_range.nil? ? all : where(date: period.date_range) }
def self.to_series(account, period = Period.all)

View file

@ -1,4 +1,6 @@
class ExchangeRate < ApplicationRecord
validates :base_currency, :converted_currency, presence: true
def self.convert(from, to, amount)
return amount unless EXCHANGE_RATE_ENABLED

View file

@ -2,6 +2,8 @@ class Transaction < ApplicationRecord
belongs_to :account
belongs_to :category, optional: true
validates :name, :date, :amount, :account, presence: true
after_commit :sync_account
def self.ransackable_attributes(auth_object = nil)

View file

@ -2,6 +2,8 @@ class Transaction::Category < ApplicationRecord
has_many :transactions
belongs_to :family
validates :name, :color, :family, presence: true
before_update :clear_internal_category, if: :name_changed?
DEFAULT_CATEGORIES = [

View file

@ -1,6 +1,8 @@
class Valuation < ApplicationRecord
belongs_to :account
validates :account, :date, :value, presence: true
after_commit :sync_account
scope :in_period, ->(period) { period.date_range.nil? ? all : where(date: period.date_range) }