mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Ensure Consistent Category Colors (#1722)
* feat: add validation to require consistent category color * feat: reflect color requirement in new category form * refactor: move logic inline over shared component * rubocop * tests: fix breaking and add case for new validation * feat: hide color selector when parent category selected * feat: override color with parent color in model * tests: remove case for unnecessary validation --------- Signed-off-by: Julien Bertazzo Lambert <42924425+JLambertazzo@users.noreply.github.com>
This commit is contained in:
parent
ded42a8c33
commit
ad5b0b8b7d
4 changed files with 19 additions and 4 deletions
|
@ -14,6 +14,8 @@ class Category < ApplicationRecord
|
|||
validate :category_level_limit
|
||||
validate :nested_category_matches_parent_classification
|
||||
|
||||
before_create :inherit_color_from_parent
|
||||
|
||||
scope :alphabetically, -> { order(:name) }
|
||||
scope :roots, -> { where(parent_id: nil) }
|
||||
scope :incomes, -> { where(classification: "income") }
|
||||
|
@ -85,6 +87,12 @@ class Category < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def inherit_color_from_parent
|
||||
if subcategory?
|
||||
self.color = parent.color
|
||||
end
|
||||
end
|
||||
|
||||
def replace_and_destroy!(replacement)
|
||||
transaction do
|
||||
transactions.update_all category_id: replacement&.id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue