From 666d4526e12170ec8015ab2a4f4c4cbb4ba4d50c Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 8 Nov 2023 17:08:34 +0000 Subject: [PATCH] feat: only show editable duplicate sets for user and org --- app/models/organisation.rb | 19 ++++++++++++++----- app/models/user.rb | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/models/organisation.rb b/app/models/organisation.rb index e17d0d6eb..23fbec04f 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -133,14 +133,23 @@ class Organisation < ApplicationRecord :active end - def duplicate_lettings_logs_sets - lettings_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } + 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 end - def duplicate_sales_logs_sets - sales_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } + 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 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 7042034b4..a6934672f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -203,12 +203,22 @@ class User < ApplicationRecord super && active? end - def duplicate_lettings_logs_sets - lettings_logs.duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } + 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 end - def duplicate_sales_logs_sets - sales_logs.duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } + 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 end protected