From fc4bc10365432f2aa91f4b024b28d3436f2e68ea Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 8 Nov 2023 17:10:55 +0000 Subject: [PATCH] feat: simplify and refactor --- app/helpers/duplicate_logs_helper.rb | 8 ++++---- app/models/organisation.rb | 17 +++++------------ app/models/user.rb | 16 ++++------------ 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/app/helpers/duplicate_logs_helper.rb b/app/helpers/duplicate_logs_helper.rb index ec8ac9185..8df911103 100644 --- a/app/helpers/duplicate_logs_helper.rb +++ b/app/helpers/duplicate_logs_helper.rb @@ -33,15 +33,15 @@ module DuplicateLogsHelper def duplicates_for_user(user) { - lettings: user.duplicate_lettings_logs_sets, - sales: user.duplicate_sales_logs_sets, + lettings: user.editable_duplicate_lettings_logs_sets, + sales: user.editable_duplicate_sales_logs_sets, } end def duplicates_for_organisation(organisation) { - lettings: organisation.duplicate_lettings_logs_sets, - sales: organisation.duplicate_sales_logs_sets, + lettings: organisation.editable_duplicate_lettings_logs_sets, + sales: organisation.editable_duplicate_sales_logs_sets, } end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 23fbec04f..4c9d038c7 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -134,22 +134,15 @@ class Organisation < ApplicationRecord end def editable_duplicate_lettings_logs_sets - all_sets = lettings_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } - editable_sets = [] - all_sets.each do |set| - editable_sets << set if LettingsLog.find(set.first).collection_period_open_for_editing? - end - editable_sets + lettings_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } + .select { |set| LettingsLog.find(set.first).collection_period_open_for_editing? } end def editable_duplicate_sales_logs_sets - all_sets = sales_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } - editable_sets = [] - all_sets.each do |set| - editable_sets << set if SalesLog.find(set.first).collection_period_open_for_editing? - end - editable_sets + sales_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } + .select { |set| SalesLog.find(set.first).collection_period_open_for_editing? } end + def recently_absorbed_organisations_grouped_by_merge_date return unless absorbed_organisations.present? && absorbed_organisations.merged_during_open_collection_period.present? diff --git a/app/models/user.rb b/app/models/user.rb index a6934672f..8f47abebb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -204,21 +204,13 @@ class User < ApplicationRecord end def editable_duplicate_lettings_logs_sets - all_sets = lettings_logs.duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } - editable_sets = [] - all_sets.each do |set| - editable_sets << set if LettingsLog.find(set.first).collection_period_open_for_editing? - end - editable_sets + lettings_logs.duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } + .select { |set| LettingsLog.find(set.first).collection_period_open_for_editing? } end def editable_duplicate_sales_logs_sets - all_sets = sales_logs.duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } - editable_sets = [] - all_sets.each do |set| - editable_sets << set if SalesLog.find(set.first).collection_period_open_for_editing? - end - editable_sets + sales_logs.duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } + .select { |set| SalesLog.find(set.first).collection_period_open_for_editing? } end protected