diff --git a/app/domain/invoices/abacus/membership_invoice_generator.rb b/app/domain/invoices/abacus/membership_invoice_generator.rb index 4c8b84a48..7e537aef4 100644 --- a/app/domain/invoices/abacus/membership_invoice_generator.rb +++ b/app/domain/invoices/abacus/membership_invoice_generator.rb @@ -59,7 +59,7 @@ def memberships elsif @invoice.link.layer_group == member.new_entry_role&.layer_group [member.membership_from_role(member.new_entry_role, main: true)] elsif (member.new_additional_section_membership_roles + member.additional_membership_roles).map(&:layer_group).include?(@invoice.link.layer_group) - + else [] end @@ -68,7 +68,7 @@ def memberships def member @member ||= Invoices::SacMemberships::Member.new(person, context) end - + def context @context ||= Invoices::SacMemberships::Context.new(@date) end @@ -81,8 +81,8 @@ def handle_invoice_generation_error(message) category: "rechnungen", subject: @invoice ) - return false + false end end end -end \ No newline at end of file +end diff --git a/app/jobs/create_membership_invoice_job.rb b/app/jobs/create_membership_invoice_job.rb index 082078785..c212c81d6 100644 --- a/app/jobs/create_membership_invoice_job.rb +++ b/app/jobs/create_membership_invoice_job.rb @@ -7,20 +7,18 @@ def initialize(invoice, date, new_entry = false, discount = nil) end def perform - begin - precondition_checker = Invoices::Abacus::MembershipInvoiceGenerator.new(person, @date, @invoice, @new_entry, @discount) + precondition_checker = Invoices::Abacus::MembershipInvoiceGenerator.new(person, @date, @invoice, @new_entry, @discount) - if precondition_checker.invoice_possible? - membership_invoice = precondition_checker.generate_membership_invoice - - subject_interface.transmit(subject) - @invoice.update!(total: membership_invoice.total) - sales_order_interface.create(sales_order(membership_invoice)) - end - rescue => e - handle_invoice_generation_error(e.message) - raise e + if precondition_checker.invoice_possible? + membership_invoice = precondition_checker.generate_membership_invoice + + subject_interface.transmit(subject) + @invoice.update!(total: membership_invoice.total) + sales_order_interface.create(sales_order(membership_invoice)) end + rescue => e + handle_invoice_generation_error(e.message) + raise e end def error(_job, exception, payload = parameters) diff --git a/spec/domain/invoices/abacus/membership_invoice_generator_spec.rb b/spec/domain/invoices/abacus/membership_invoice_generator_spec.rb index de86b723b..499b5ea9f 100644 --- a/spec/domain/invoices/abacus/membership_invoice_generator_spec.rb +++ b/spec/domain/invoices/abacus/membership_invoice_generator_spec.rb @@ -11,7 +11,6 @@ let(:date) { Date.new(2023, 1, 1) } let(:person) { Person.with_membership_years("people.*", date).find_by(id: people(:mitglied).id) } - before do SacMembershipConfig.update_all(valid_from: 2020) SacSectionMembershipConfig.update_all(valid_from: 2020) @@ -20,13 +19,12 @@ end context "invoice precontions" do - subject { described_class.new(person, date, external_invoices(:external_invoice_draft), false, 0) } it "invoice isnt possible if person has no role on invoice link section" do allow_any_instance_of(Invoices::Abacus::MembershipInvoice).to receive(:invoice?).and_return(true) external_invoices(:external_invoice_draft).update!(link: groups(:matterhorn_mitglieder)) - + subject.invoice_possible? expect(external_invoices(:external_invoice_draft).state).to eq("error") @@ -36,7 +34,7 @@ it "invoice isnt possible if membership invoice? returns false" do allow_any_instance_of(Invoices::Abacus::MembershipInvoice).to receive(:invoice?).and_return(false) - + subject.invoice_possible? expect(external_invoices(:external_invoice_draft).state).to eq("error") @@ -46,7 +44,7 @@ it "invoice is possible if all condition are met" do allow_any_instance_of(Invoices::Abacus::MembershipInvoice).to receive(:invoice?).and_return(true) - + subject.invoice_possible? end end diff --git a/spec/jobs/create_membership_invoice_job_spec.rb b/spec/jobs/create_membership_invoice_job_spec.rb index 77d0683c1..c2dcb4257 100644 --- a/spec/jobs/create_membership_invoice_job_spec.rb +++ b/spec/jobs/create_membership_invoice_job_spec.rb @@ -92,11 +92,11 @@ expect(abacus_client).to receive(:create).with(:sales_order, data).and_return({sales_order_id: 19}) expect(abacus_client).to receive(:endpoint).with(:sales_order, Hash) expect(abacus_client).to receive(:request).with(:post, String, Hash) - + job.perform - + expect(person.reload.abacus_subject_key).to eq(7) - + invoice = ExternalInvoice.last expect(invoice.abacus_sales_order_key).to eq(19) expect(invoice.issued_at).to eq(date) @@ -119,11 +119,11 @@ expect(abacus_client).to receive(:create).with(:communication, Hash) expect(abacus_client).to receive(:create).with(:customer, Hash) expect(abacus_client).to receive(:create).with(:sales_order, Hash).and_raise(ex) - + expect { job.perform }.to raise_error(RestClient::Exception) - + expect(person.reload.abacus_subject_key).to eq(7) - + invoice = ExternalInvoice.last expect(invoice.abacus_sales_order_key).to eq(nil) expect(invoice.state).to eq("error") @@ -140,11 +140,11 @@ expect(abacus_client).to receive(:create).with(:communication, Hash) expect(abacus_client).to receive(:create).with(:customer, Hash) expect(abacus_client).to receive(:create).with(:sales_order, Hash).and_raise(ex) - + expect { job.perform }.to raise_error(RestClient::Exception) - + expect(person.reload.abacus_subject_key).to eq(7) - + invoice = ExternalInvoice.last expect(invoice.abacus_sales_order_key).to eq(nil) expect(invoice.state).to eq("error") @@ -155,7 +155,7 @@ it "handles people without membership in job again" do allow_any_instance_of(Invoices::Abacus::MembershipInvoice).to receive(:invoice?).and_return(true) external_invoices(:external_invoice_draft).update!(link: groups(:matterhorn_mitglieder)) - + job.perform expect(external_invoices(:external_invoice_draft).state).to eq("error") @@ -391,12 +391,4 @@ expect(invoice.person).to eq(person) end end - - context "neuanmeldung" do - - end - - context "zusatzsektionen" - - -end \ No newline at end of file +end