Skip to content

Commit

Permalink
Transmit all abo magazin roles to abacus (#1561) (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
codez authored Jan 23, 2025
1 parent 7491226 commit a3b17cc
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 26 deletions.
4 changes: 2 additions & 2 deletions app/abilities/sac_cas/role_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module SacCas::RoleAbility

def self_terminatable_own_role
return false unless her_own
return false if abonnent?
return false if abonnent_magazin?
return true unless mitglied_role?

!has_termination_by_section_only_role
Expand Down Expand Up @@ -69,5 +69,5 @@ def wizard_managed_role?(role = subject)
SacCas::WIZARD_MANAGED_ROLES.include?(role.class)
end

def abonnent? = subject.is_a?(Group::AboMagazin::Abonnent)
def abonnent_magazin? = SacCas::ABONNENT_MAGAZIN_ROLES.include?(subject.class)
end
6 changes: 4 additions & 2 deletions app/domain/people/sac_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def invoice?
(@person.sac_family_main_person? || individual_membership?)
end

def abonnent?
active_roles_of_type(Group::AboMagazin::Abonnent.sti_name).present?
def abonnent_magazin?
active_roles_of_type(abonnent_magazin_types).present?
end

def family?(consider_neuanmeldung: false)
Expand Down Expand Up @@ -188,6 +188,8 @@ def neuanmeldung_zusatzsektion_types = SacCas::NEUANMELDUNG_ZUSATZSEKTION_ROLES.

def neuanmeldung_nv_zusatzsektion_types = SacCas::NEUANMELDUNG_NV_ZUSATZSEKTION_ROLES.map(&:sti_name)

def abonnent_magazin_types = SacCas::ABONNENT_MAGAZIN_ROLES.map(&:sti_name)

def invoicable_types
mitglied_stammsektion_types +
mitglied_zusatzsektion_types +
Expand Down
7 changes: 6 additions & 1 deletion app/domain/sac_cas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ module SacCas
::Group::SektionsTourenUndKurse::TourenleiterOhneQualifikation
].freeze

ABONNENT_ROLES = [
ABONNENT_MAGAZIN_ROLES = [
::Group::AboMagazin::Abonnent,
::Group::AboMagazin::Gratisabonnent,
::Group::AboMagazin::Neuanmeldung
].freeze

ABONNENT_TOUREN_PORTAL_ROLES = [
::Group::AboTourenPortal::Abonnent
].freeze

Expand Down
2 changes: 1 addition & 1 deletion app/jobs/invoices/abacus/transmit_all_members_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Invoices::Abacus::TransmitAllMembersJob < BaseJob
ROLES_TO_TRANSMIT = [
Group::SektionsMitglieder::Mitglied,
Group::SektionsNeuanmeldungenNv::Neuanmeldung,
Group::AboMagazin::Abonnent
*SacCas::ABONNENT_MAGAZIN_ROLES
].freeze

self.max_run_time = 12.hours
Expand Down
22 changes: 22 additions & 0 deletions app/models/concerns/roles/abacus_transmittable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_sac_cas.

module Roles::AbacusTransmittable
extend ActiveSupport::Concern

included do
after_create_commit :transmit_data_to_abacus
end

private

def transmit_data_to_abacus
Invoices::Abacus::TransmitPersonJob.new(person).enqueue! if
person.abacus_subject_key.blank? &&
person.data_quality != "error"
end
end
16 changes: 6 additions & 10 deletions app/models/group/abo_magazin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@
class Group::AboMagazin < ::Group
### ROLES
class Abonnent < ::Role
include Roles::AbacusTransmittable

self.permissions = []
self.basic_permissions_only = true
self.terminatable = true

after_create_commit :transmit_data_to_abacus

private

def transmit_data_to_abacus
Invoices::Abacus::TransmitPersonJob.new(person).enqueue! if
person.abacus_subject_key.blank? &&
person.data_quality != "error"
end
end

class Neuanmeldung < ::Role
include Roles::AbacusTransmittable

self.permissions = []
self.basic_permissions_only = true
end

class Gratisabonnent < ::Role
include Roles::AbacusTransmittable

self.permissions = []
self.basic_permissions_only = true
end
Expand Down
8 changes: 1 addition & 7 deletions app/models/group/sektions_mitglieder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class Group::SektionsMitglieder < ::Group
### ROLES
class Mitglied < ::Role
include SacCas::Role::MitgliedStammsektion
include Roles::AbacusTransmittable

self.terminatable = true

validates :end_on, presence: true

attr_readonly :family_id

after_create_commit :transmit_data_to_abacus
before_validation :set_family_id, if: -> { beitragskategorie&.family? && family_id.blank? }
after_destroy :destroy_household, if: -> { person.sac_family_main_person }

Expand All @@ -29,12 +29,6 @@ def destroy_household
Household.new(person, maintain_sac_family: false).destroy
end

def transmit_data_to_abacus
Invoices::Abacus::TransmitPersonJob.new(person).enqueue! if
person.abacus_subject_key.blank? &&
person.data_quality != "error"
end

def set_family_id
self.family_id = person.household_key
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/sac_cas/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module SacCas::Person

CORRESPONDENCES = %w[digital print]
DATA_QUALITIES = %w[ok info warning error]
REQUIRED_FIELDS_ROLES = [*SacCas::ABONNENT_ROLES, *SacCas::MITGLIED_STAMMSEKTION_ROLES].map(&:sti_name)
REQUIRED_FIELDS_ROLES = [*SacCas::ABONNENT_MAGAZIN_ROLES, *SacCas::ABONNENT_TOUREN_PORTAL_ROLES, *SacCas::MITGLIED_STAMMSEKTION_ROLES].map(&:sti_name)

prepended do
Person::SEARCHABLE_ATTRS << :id
Expand Down Expand Up @@ -155,7 +155,7 @@ def abacus_attributes_changed?
end

def abacus_transmittable?
abacus_subject_key.present? || sac_membership_invoice? || sac_membership.abonnent?
abacus_subject_key.present? || sac_membership_invoice? || sac_membership.abonnent_magazin?
end

def roles_require_name_and_address?
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/invoices/abacus/transmit_all_members_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Group::SektionsFunktionaere::Administration.create!(person: Fabricate(:person), group: groups(:bluemlisalp_funktionaere)) # other role
Group::SektionsMitglieder::Mitglied.create!(person: Fabricate(:person), group: groups(:bluemlisalp_mitglieder), start_on: 60.years.ago, end_on: 5.years.ago) # old member
Group::AboMagazin::Abonnent.create!(person: Fabricate(:person), group: groups(:abo_die_alpen), start_on: 5.years.ago, end_on: 2.years.ago) # old abonnent
Group::AboMagazin::Neuanmeldung.create!(person: Fabricate(:person), group: groups(:abo_die_alpen))
Group::AboMagazin::Andere.create!(person: Fabricate(:person), group: groups(:abo_die_alpen))
end

def create_mix_of_people
Expand Down

0 comments on commit a3b17cc

Please sign in to comment.