From 8975530b2cdc395ed86dea17e31accc17c6c3b7f Mon Sep 17 00:00:00 2001 From: Diego Steiner Date: Sun, 31 Dec 2023 11:40:26 +0000 Subject: [PATCH] feature: booking without invoice --- .../booking_states/definitive_request.rb | 2 +- app/domain/booking_states/past.rb | 4 ++ app/models/tenant.rb | 46 +++++++++---------- app/params/manage/tenant_params.rb | 2 +- app/params/public/tenant_params.rb | 2 +- app/views/manage/tenants/_form.html.slim | 4 +- config/locales/de.yml | 3 +- config/locales/en.yml | 2 +- config/locales/fr.yml | 2 +- config/locales/it.yml | 2 +- ...dd_bookings_without_invoices_to_tenants.rb | 7 +++ db/schema.rb | 6 +-- spec/factories/tenants.rb | 46 +++++++++---------- spec/models/tenant_spec.rb | 46 +++++++++---------- 14 files changed, 93 insertions(+), 81 deletions(-) create mode 100644 db/migrate/20231231113411_add_bookings_without_invoices_to_tenants.rb diff --git a/app/domain/booking_states/definitive_request.rb b/app/domain/booking_states/definitive_request.rb index 3a8290ed5..cff7d059f 100644 --- a/app/domain/booking_states/definitive_request.rb +++ b/app/domain/booking_states/definitive_request.rb @@ -29,7 +29,7 @@ def self.to_sym end infer_transition(to: :upcoming) do |booking| - booking.contracts.sent.none? && booking.tenant&.allow_bookings_without_contract + booking.contracts.sent.none? && booking.tenant&.bookings_without_contract end infer_transition(to: :awaiting_contract) do |booking| diff --git a/app/domain/booking_states/past.rb b/app/domain/booking_states/past.rb index 706f0248c..6054a8c66 100644 --- a/app/domain/booking_states/past.rb +++ b/app/domain/booking_states/past.rb @@ -23,6 +23,10 @@ def self.to_sym invoices.any?(&:sent?) || (invoices.any? && invoices.none?(&:unsettled?)) end + infer_transition(to: :completed) do |booking| + booking.tenant.bookings_without_invoice + end + def relevant_time booking.ends_at end diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 4863282ba..a69ff2678 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -4,29 +4,29 @@ # # Table name: tenants # -# id :bigint not null, primary key -# address_addon :string -# allow_bookings_without_contract :boolean default(FALSE) -# birth_date :date -# city :string -# country_code :string default("CH") -# email :string -# email_verified :boolean default(FALSE) -# first_name :string -# iban :string -# import_data :jsonb -# last_name :string -# locale :string default("de"), not null -# nickname :string -# phone :text -# remarks :text -# reservations_allowed :boolean default(TRUE) -# search_cache :text not null -# street_address :string -# zipcode :string -# created_at :datetime not null -# updated_at :datetime not null -# organisation_id :bigint not null +# id :bigint not null, primary key +# address_addon :string +# birth_date :date +# bookings_without_contract :boolean default(FALSE) +# bookings_without_invoice :boolean default(FALSE) +# city :string +# country_code :string default("CH") +# email :string +# email_verified :boolean default(FALSE) +# first_name :string +# import_data :jsonb +# last_name :string +# locale :string default("de"), not null +# nickname :string +# phone :text +# remarks :text +# reservations_allowed :boolean default(TRUE) +# search_cache :text not null +# street_address :string +# zipcode :string +# created_at :datetime not null +# updated_at :datetime not null +# organisation_id :bigint not null # # Indexes # diff --git a/app/params/manage/tenant_params.rb b/app/params/manage/tenant_params.rb index bb2da4167..c3bdd2399 100644 --- a/app/params/manage/tenant_params.rb +++ b/app/params/manage/tenant_params.rb @@ -3,7 +3,7 @@ module Manage class TenantParams < Public::TenantParams def self.permitted_keys - super + %i[reservations_allowed remarks allow_bookings_without_contract] + super + %i[reservations_allowed remarks bookings_without_contract bookings_without_invoice] end end end diff --git a/app/params/public/tenant_params.rb b/app/params/public/tenant_params.rb index afea0fab3..dad08b052 100644 --- a/app/params/public/tenant_params.rb +++ b/app/params/public/tenant_params.rb @@ -4,7 +4,7 @@ module Public class TenantParams < ApplicationParams def self.permitted_keys %i[first_name last_name street_address zipcode city email birth_date country_code nickname phone - address_addon iban locale] + address_addon locale] end end end diff --git a/app/views/manage/tenants/_form.html.slim b/app/views/manage/tenants/_form.html.slim index b4f11a86d..e618dec43 100644 --- a/app/views/manage/tenants/_form.html.slim +++ b/app/views/manage/tenants/_form.html.slim @@ -18,10 +18,10 @@ = f.text_field :phone = f.date_select :birth_date, use_two_digit_numbers: true, start_year: Time.zone.today.year - 75, end_year: Time.zone.today.year - 17, include_blank: true - = f.text_field :iban = f.text_area :remarks = f.collection_select :locale, Tenant.locales, :first, :first - = f.check_box :allow_bookings_without_contract + = f.check_box :bookings_without_contract + = f.check_box :bookings_without_invoice .form-actions.pt-4.mt-3 = f.submit diff --git a/config/locales/de.yml b/config/locales/de.yml index 2107cc47a..117683770 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -333,8 +333,9 @@ de: tenant: address: Adresse address_addon: Adresszusatz / Schule / Firma - allow_bookings_without_contract: Buchungen ohne Vertrag erlauben birth_date: Geburtsdatum + bookings_without_contract: Buchungen ohne Vertrag + bookings_without_invoice: Buchungen ohne Rechnung city: Ort country_code: Land email: Email diff --git a/config/locales/en.yml b/config/locales/en.yml index 1cb960858..32d55a438 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -289,8 +289,8 @@ en: tenant: address: Adresse address_addon: Addresszusatz - allow_bookings_without_contract: Buchungen ohne Vertrag erlauben birth_date: Geburtsdatum + bookings_without_contract: Buchungen ohne Vertrag erlauben city: Ort country_code: Land email: Email diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 6afcf7894..4e9cb7946 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -330,8 +330,8 @@ fr: tenant: address: Adresse address_addon: Complément d'adresse / école / entreprise - allow_bookings_without_contract: Autoriser les réservations sans contrat birth_date: Date de naissance + bookings_without_contract: Autoriser les réservations sans contrat city: Lieu country_code: Pays email: Email diff --git a/config/locales/it.yml b/config/locales/it.yml index cbf956a23..2c94ee4f7 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -330,8 +330,8 @@ it: tenant: address: Indirizzo address_addon: Suffisso indirizzo / scuola / azienda - allow_bookings_without_contract: Consentire prenotazioni senza contratto birth_date: Data di nascita + bookings_without_contract: Consentire prenotazioni senza contratto city: Località country_code: Paese email: E-mail diff --git a/db/migrate/20231231113411_add_bookings_without_invoices_to_tenants.rb b/db/migrate/20231231113411_add_bookings_without_invoices_to_tenants.rb new file mode 100644 index 000000000..11177d1ec --- /dev/null +++ b/db/migrate/20231231113411_add_bookings_without_invoices_to_tenants.rb @@ -0,0 +1,7 @@ +class AddBookingsWithoutInvoicesToTenants < ActiveRecord::Migration[7.1] + def change + add_column :tenants, :bookings_without_invoice, :boolean, default: false + rename_column :tenants, :allow_bookings_without_contract, :bookings_without_contract + remove_column :tenants, :iban, :string, null: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 289b4e5d2..84a0b584b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_12_19_120149) do +ActiveRecord::Schema[7.1].define(version: 2023_12_31_113411) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -541,9 +541,9 @@ t.string "country_code", default: "CH" t.string "nickname" t.string "address_addon" - t.boolean "allow_bookings_without_contract", default: false - t.string "iban" + t.boolean "bookings_without_contract", default: false t.string "locale", default: "de", null: false + t.boolean "bookings_without_invoice", default: false t.index ["email", "organisation_id"], name: "index_tenants_on_email_and_organisation_id", unique: true t.index ["email"], name: "index_tenants_on_email" t.index ["organisation_id"], name: "index_tenants_on_organisation_id" diff --git a/spec/factories/tenants.rb b/spec/factories/tenants.rb index 38f4a3ec3..693629ce1 100644 --- a/spec/factories/tenants.rb +++ b/spec/factories/tenants.rb @@ -4,29 +4,29 @@ # # Table name: tenants # -# id :bigint not null, primary key -# address_addon :string -# allow_bookings_without_contract :boolean default(FALSE) -# birth_date :date -# city :string -# country_code :string default("CH") -# email :string -# email_verified :boolean default(FALSE) -# first_name :string -# iban :string -# import_data :jsonb -# last_name :string -# locale :string default("de"), not null -# nickname :string -# phone :text -# remarks :text -# reservations_allowed :boolean default(TRUE) -# search_cache :text not null -# street_address :string -# zipcode :string -# created_at :datetime not null -# updated_at :datetime not null -# organisation_id :bigint not null +# id :bigint not null, primary key +# address_addon :string +# birth_date :date +# bookings_without_contract :boolean default(FALSE) +# bookings_without_invoice :boolean default(FALSE) +# city :string +# country_code :string default("CH") +# email :string +# email_verified :boolean default(FALSE) +# first_name :string +# import_data :jsonb +# last_name :string +# locale :string default("de"), not null +# nickname :string +# phone :text +# remarks :text +# reservations_allowed :boolean default(TRUE) +# search_cache :text not null +# street_address :string +# zipcode :string +# created_at :datetime not null +# updated_at :datetime not null +# organisation_id :bigint not null # # Indexes # diff --git a/spec/models/tenant_spec.rb b/spec/models/tenant_spec.rb index 31102342c..dfb256eb4 100644 --- a/spec/models/tenant_spec.rb +++ b/spec/models/tenant_spec.rb @@ -4,29 +4,29 @@ # # Table name: tenants # -# id :bigint not null, primary key -# address_addon :string -# allow_bookings_without_contract :boolean default(FALSE) -# birth_date :date -# city :string -# country_code :string default("CH") -# email :string -# email_verified :boolean default(FALSE) -# first_name :string -# iban :string -# import_data :jsonb -# last_name :string -# locale :string default("de"), not null -# nickname :string -# phone :text -# remarks :text -# reservations_allowed :boolean default(TRUE) -# search_cache :text not null -# street_address :string -# zipcode :string -# created_at :datetime not null -# updated_at :datetime not null -# organisation_id :bigint not null +# id :bigint not null, primary key +# address_addon :string +# birth_date :date +# bookings_without_contract :boolean default(FALSE) +# bookings_without_invoice :boolean default(FALSE) +# city :string +# country_code :string default("CH") +# email :string +# email_verified :boolean default(FALSE) +# first_name :string +# import_data :jsonb +# last_name :string +# locale :string default("de"), not null +# nickname :string +# phone :text +# remarks :text +# reservations_allowed :boolean default(TRUE) +# search_cache :text not null +# street_address :string +# zipcode :string +# created_at :datetime not null +# updated_at :datetime not null +# organisation_id :bigint not null # # Indexes #