Skip to content

Commit

Permalink
Add various abo fees as mounted attrs (#1590)
Browse files Browse the repository at this point in the history
  • Loading branch information
njaeggi committed Feb 4, 2025
1 parent 87dc1ac commit 036c105
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 53 deletions.
6 changes: 1 addition & 5 deletions app/domain/invoices/sac_memberships/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module SacMemberships
class Member
attr_reader :person, :context, :sac_membership

delegate :id, :to_s, :language, :sac_family_main_person?, to: :person
delegate :id, :to_s, :language, :sac_family_main_person?, :living_abroad?, to: :person
delegate :date, :sac_magazine_mailing_list, to: :context
delegate :zusatzsektion_roles,
:neuanmeldung_nv_stammsektion_roles, :neuanmeldung_nv_zusatzsektion_roles,
Expand Down Expand Up @@ -68,10 +68,6 @@ def sac_ehrenmitglied?
@sac_ehrenmitglied = sac_membership.sac_ehrenmitglied?
end

def living_abroad?
!(person.swiss? || person.country.downcase == "li")
end

def sac_magazine?
return @sac_magazine if defined?(@sac_magazine)

Expand Down
11 changes: 0 additions & 11 deletions app/domain/sac_cas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,6 @@ module SacCas
.select { |c| c.to_s =~ /MAILING_LIST_.*INTERNAL_KEY/ }
.map { |c| const_get(c) }

AboCost = Data.define(:amount, :country)
ABO_COSTS = {
magazin: [
AboCost.new(amount: 60, country: :switzerland),
AboCost.new(amount: 76, country: :international)
],
tourenportal: [
AboCost.new(amount: 45, country: nil)
]
}

MEMBERSHIP_OPERATIONS_GROUP_TYPES = [::Group::Sektion.sti_name, ::Group::Ortsgruppe.sti_name].freeze
MEMBERSHIP_OPERATIONS_EXCLUDED_IDS = [
2900, 3700, 2249, 2330, 2601, 3030, 3251,
Expand Down
9 changes: 3 additions & 6 deletions app/mailers/signup/abo_magazin_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ def confirmation(person, group, newsletter_subscribed)
private

def placeholder_costs
cost = if @person.country == "CH"
SacCas::ABO_COSTS[:magazin].find { |cost| cost.country == :switzerland }
else
SacCas::ABO_COSTS[:magazin].find { |cost| cost.country == :international }
end
formatted_value = number_with_precision(cost.amount,
cost = Group.root.abo_alpen_fee
cost += Group.root.abo_alpen_postage_abroad if @person.living_abroad?
formatted_value = number_with_precision(cost,
precision: I18n.t("number.currency.format.precision"),
delimiter: I18n.t("number.currency.format.delimiter"))

Expand Down
5 changes: 5 additions & 0 deletions app/models/group/sac_cas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Group::SacCas < Group
mounted_attr :sac_newsletter_mailing_list_id, :integer
mounted_attr :sac_magazine_mailing_list_id, :integer
mounted_attr :sac_fundraising_mailing_list_id, :integer
mounted_attr :abo_alpen_fee, :decimal, precision: 10, scale: 2
mounted_attr :abo_alpen_postage_abroad, :decimal, precision: 10, scale: 2
mounted_attr :abo_touren_portal_fee, :decimal, precision: 10, scale: 2
mounted_attr :abo_alpen_fee_article_number, :string
mounted_attr :abo_alpen_postage_abroad_article_number, :string

validate :assert_valid_course_admin_email
validate :assert_mounted_mailing_list_attrs
Expand Down
5 changes: 5 additions & 0 deletions app/models/sac_cas/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def youth?(reference_date: Time.zone.today.end_of_year)
SacCas::Beitragskategorie::Calculator.new(self, reference_date: reference_date).youth?
end

# Liechtenstein is counted as not abroad, extra fees should not apply
def living_abroad?
!(swiss? || country.downcase == "li")
end

def picture_profile_default
"profile.svg" # default image for profile variant
end
Expand Down
25 changes: 19 additions & 6 deletions app/models/wizards/signup/abo_magazin_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,36 @@ def member_or_applied?

def redirection_message = I18n.t("groups.self_registration.create.already_subscribed_to_abo")

def costs = SacCas::ABO_COSTS[:magazin]

def requires_policy_acceptance? = false

def calculated_costs
case step("person_fields").country
when "CH"
costs.find { |cost| cost.country == :switzerland }.amount
if person.living_abroad?
annual_fee + abroad_fee
else
annual_fee
end
end

def shipping_country
if person.living_abroad?
I18n.t("groups.self_registration.abo_infos.international")
else
costs.find { |cost| cost.country == :international }.amount
I18n.t("groups.self_registration.abo_infos.switzerland")
end
end

def shipping_abroad? = true

def enqueue_notification_email
Signup::AboMagazinMailer
.confirmation(person, group, newsletter)
.deliver_later
end

private

def annual_fee = Group.root.abo_alpen_fee

def abroad_fee = Group.root.abo_alpen_postage_abroad
end
end
4 changes: 3 additions & 1 deletion app/models/wizards/signup/abo_touren_portal_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def member_or_applied?

def redirection_message = I18n.t("groups.self_registration.create.already_member_of_tourenportal")

def costs = SacCas::ABO_COSTS[:tourenportal]
def calculated_costs = Group.root.abo_touren_portal_fee

def shipping_abroad? = false
end
end
11 changes: 5 additions & 6 deletions app/views/groups/self_registration/_abo_infos.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
%thead
%tr
%th=t('.annual_price_header')
- if costs.first.country
- if wizard.shipping_abroad?
%th=t('.delivery_country_header')
%tbody
- costs.each do |cost|
%tr
%td=t('.price_with_vat', amount: format("%2.f", cost.amount))
- if cost.country
%td=t(".#{cost.country}")
%tr
%td=t('.price_with_vat', amount: format("%2.f", wizard.calculated_costs))
- if wizard.shipping_abroad?
%td=wizard.shipping_country

%b=t('.duration_title')
%p.mb-3=t('.duration_text')
2 changes: 1 addition & 1 deletion app/views/groups/self_registration/_aside_abo.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
-# or at https://github.com/hitobito/hitobito.
= turbo_frame_tag(partial_name, class: 'col-md') do
= render "abo_infos", costs: wizard.costs
= render "abo_infos", wizard: wizard
- unless current_user
= render(SelfRegistration::InfosComponent.new)
5 changes: 5 additions & 0 deletions config/locales/wagon.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ de:
sac_magazine_mailing_list_id: Die Alpen Abo ID
sac_fundraising_mailing_list_id: Spendenaufruf Abo ID
course_admin_email: E-Mail Kursadministration
abo_alpen_fee: Betrag Abonnent Die Alpen
abo_alpen_postage_abroad: Betrag Auslandporto Die Alpen
abo_touren_portal_fee: Betrag Abonnent Tourenportal
abo_alpen_fee_article_number: Artikelnummer Abonnent Die Alpen
abo_alpen_postage_abroad_article_number: Artiklenummer Auslandporto Die Alpen
group/sektion:
foundation_year: Gründungsjahr
section_canton: Kanton
Expand Down
1 change: 1 addition & 0 deletions spec/features/signup/abo_magazin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
before do
group.update!(self_registration_role_type: group.role_types.first)
allow(Settings.groups.self_registration).to receive(:enabled).and_return(true)
Group.root.update!(abo_alpen_fee: 60, abo_alpen_postage_abroad: 16)
end

def expect_active_step(step_name)
Expand Down
1 change: 1 addition & 0 deletions spec/features/signup/abo_touren_portal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
before do
group.update!(self_registration_role_type: group.role_types.first)
allow(Settings.groups.self_registration).to receive(:enabled).and_return(true)
Group.root.update!(abo_touren_portal_fee: 20)
end

def complete_main_person_form
Expand Down
5 changes: 4 additions & 1 deletion spec/mailers/signup/abo_magazin_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
let(:mail) { described_class.confirmation(person, group, false) }
let(:custom_content) { CustomContent.get(Signup::AboMagazinMailer::CONFIRMATION) }

before { person.update(address_care_of: "1A", postbox: "123") }
before do
person.update(address_care_of: "1A", postbox: "123")
Group.root.update!(abo_alpen_fee: 60, abo_alpen_postage_abroad: 16)
end

it "sends confirmation email" do
expect(mail.to).to eq(["[email protected]"])
Expand Down
4 changes: 4 additions & 0 deletions spec/models/wizards/signup/abo_magazin_wizard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ def build(params = required_attrs)
end

describe "#calculate_costs" do
before do
Group.root.update!(abo_alpen_fee: 60, abo_alpen_postage_abroad: 16)
end

it "calculates costs for swiss people" do
expect(wizard.calculated_costs).to eq(60)
end
Expand Down
25 changes: 25 additions & 0 deletions spec/support/graphiti/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,31 @@
"readable": true,
"description": null
},
"abo_alpen_fee": {
"type": "string",
"readable": true,
"description": null
},
"abo_alpen_postage_abroad": {
"type": "string",
"readable": true,
"description": null
},
"abo_touren_portal_fee": {
"type": "string",
"readable": true,
"description": null
},
"abo_alpen_fee_article_number": {
"type": "string",
"readable": true,
"description": null
},
"abo_alpen_postage_abroad_article_number": {
"type": "string",
"readable": true,
"description": null
},
"foundation_year": {
"type": "string",
"readable": true,
Expand Down
63 changes: 47 additions & 16 deletions spec/views/groups/_abo_infos.html.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,60 @@
require "spec_helper"

describe "groups/self_registration/_abo_infos.html.haml" do
let(:costs) do
[OpenStruct.new(amount: 60, country: :switzerland),
OpenStruct.new(amount: 76, country: :international)]
end

let(:dom) do
render
Capybara::Node::Simple.new(@rendered)
end

before { allow(view).to receive(:costs).and_return(costs) }
before do
allow(view).to receive_messages(wizard: wizard)
Group.root.update!(abo_alpen_fee: 60, abo_alpen_postage_abroad: 16, abo_touren_portal_fee: 50)
end

context "abo magazin wizard" do
let(:wizard) { Wizards::Signup::AboMagazinWizard.new(group: groups(:abo_die_alpen)) }

it "renders subscription pricing info" do
expect(dom).to have_text "Preis pro Jahr"
expect(dom).to have_text "CHF 60 inkl. MwSt."
expect(dom).to have_text "Versandsland"
expect(dom).to have_text "Schweiz"
end

it "renders subscription duration info" do
expect(dom).to have_text "Preis pro Jahr"
expect(dom).to have_text "CHF 60 inkl. MwSt."
expect(dom).to have_text "CHF 76 inkl. MwSt."
expect(dom).to have_text "Versandsland"
expect(dom).to have_text "Schweiz"
expect(dom).to have_text "Weltweit"
it "does not count liechtenstein as international shipping" do
wizard.person_fields.country = "LI"
expect(dom).to have_text "Preis pro Jahr"
expect(dom).to have_text "CHF 60 inkl. MwSt."
expect(dom).to have_text "Versandsland"
expect(dom).to have_text "Schweiz"
end

it "renders duration info" do
expect(dom).to have_text "Dauer und Erneuerung des Abonnements"
expect(dom).to have_text "Das Abonnement kann jederzeit zum Ende der laufenden Periode gekündigt werden."
end

context "international" do
before do
wizard.person_fields.country = "DE"
end

it "renders subscription pricing info" do
expect(dom).to have_text "Preis pro Jahr"
expect(dom).to have_text "CHF 76 inkl. MwSt."
expect(dom).to have_text "Versandsland"
expect(dom).to have_text "Weltweit"
end
end
end

it "renders duration info" do
expect(dom).to have_text "Dauer und Erneuerung des Abonnements"
expect(dom).to have_text "Das Abonnement kann jederzeit zum Ende der laufenden Periode gekündigt werden."
context "abo touren portal wizard" do
let(:wizard) { Wizards::Signup::AboTourenPortalWizard.new(group: groups(:abo_die_alpen)) }

it "renders subscription pricing info" do
expect(dom).to have_text "Preis pro Jahr"
expect(dom).to have_text "CHF 50 inkl. MwSt."
expect(dom).not_to have_text "Versandsland"
end
end
end

0 comments on commit 036c105

Please sign in to comment.