Browse Source

minor amendments from code review.

pull/1776/head
Arthur Campbell 3 years ago committed by Kat
parent
commit
65429da90f
  1. 8
      app/helpers/duplicate_logs_helper.rb
  2. 1
      app/models/log.rb
  3. 12
      app/models/user.rb

8
app/helpers/duplicate_logs_helper.rb

@ -35,10 +35,10 @@ module DuplicateLogsHelper
duplicate_lettings_ids = Set.new
duplicate_sales_ids = Set.new
user.lettings_logs(created_by: true).each do |log|
LettingsLog.created_by(user).visible.each do |log|
next if duplicate_lettings_ids.include? log.id
duplicates = LettingsLog.filter_by_organisation(user.organisation).duplicate_logs(log)
duplicates = user.lettings_logs.duplicate_logs(log)
next if duplicates.none?
duplicate_ids = [log.id, *duplicates.map(&:id)]
@ -47,10 +47,10 @@ module DuplicateLogsHelper
duplicate_lettings_ids << duplicate_ids
end
user.sales_logs(created_by: true).each do |log|
SalesLog.created_by(user).visible.each do |log|
next if duplicate_sales_ids.include? log.id
duplicates = SalesLog.filter_by_organisation(user.organisation).duplicate_logs(log)
duplicates = user.sales_logs.duplicate_logs(log)
next if duplicates.none?
duplicate_ids = [log.id, *duplicates.map(&:id)]

1
app/models/log.rb

@ -29,7 +29,6 @@ class Log < ApplicationRecord
scope :visible, -> { where(status: %w[not_started in_progress completed]) }
scope :exportable, -> { where(status: %w[not_started in_progress completed deleted]) }
scope :created_by, ->(user) { where(created_by: user) }
scope :filter_by_status, ->(status, _user = nil) { where status: }
scope :filter_by_years, lambda { |years, _user = nil|
first_year = years.shift

12
app/models/user.rb

@ -75,20 +75,16 @@ class User < ApplicationRecord
scope :deactivated, -> { where(active: false) }
scope :active_status, -> { where(active: true).where.not(last_sign_in_at: nil) }
def lettings_logs(created_by: false)
if created_by
LettingsLog.created_by(self)
elsif support?
def lettings_logs
if support?
LettingsLog.all
else
LettingsLog.filter_by_organisation(organisation.absorbed_organisations + [organisation])
end
end
def sales_logs(created_by: false)
if created_by
SalesLog.created_by(self)
elsif support?
def sales_logs
if support?
SalesLog.all
else
SalesLog.filter_by_owning_organisation(organisation.absorbed_organisations + [organisation])

Loading…
Cancel
Save