Skip to content

Commit

Permalink
Merge pull request #294 from diegosteiner/develop
Browse files Browse the repository at this point in the history
24.1.1
  • Loading branch information
diegosteiner committed Jan 28, 2024
2 parents 981fb62 + 6333021 commit 9ceddc4
Show file tree
Hide file tree
Showing 48 changed files with 939 additions and 782 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

## Version 24.1.1

Released on 28.01.2023

- Feature: Set default state for new bookings in manager
- Feature: Add designated documents for accepted notification
- Bugfixes

## Version 23.12.2

Released on 28.12.2023
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ gem 'discard'
gem 'factory_bot_rails', '~> 6.2.0', require: false
gem 'faker', require: false
gem 'faraday', require: false
gem 'iban-tools'
gem 'icalendar'
gem 'inline_svg'
gem 'kramdown'
Expand Down
26 changes: 14 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ GEM
rake (>= 10.4, < 14.0)
ast (2.4.2)
aws-eventstream (1.3.0)
aws-partitions (1.877.0)
aws-partitions (1.880.0)
aws-sdk-core (3.190.2)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
Expand All @@ -111,7 +111,7 @@ GEM
bcrypt (3.1.20)
bigdecimal (3.1.5)
blueprinter (0.30.0)
bootsnap (1.17.0)
bootsnap (1.17.1)
msgpack (~> 1.2)
bootstrap_form (5.4.0)
actionpack (>= 6.1)
Expand Down Expand Up @@ -140,7 +140,7 @@ GEM
launchy
chunky_png (1.4.0)
coderay (1.1.3)
concurrent-ruby (1.2.2)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
countries (5.7.1)
unaccent (~> 0.3)
Expand Down Expand Up @@ -185,7 +185,7 @@ GEM
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
faker (3.2.2)
faker (3.2.3)
i18n (>= 1.8.11, < 2)
faraday (2.9.0)
faraday-net_http (>= 2.0, < 3.2)
Expand Down Expand Up @@ -220,6 +220,7 @@ GEM
terminal-table (>= 1.5.1)
i18n-tasks-csv (1.1)
i18n-tasks (~> 0.9)
iban-tools (1.2.1)
icalendar (2.10.1)
ice_cube (~> 0.16)
ice_cube (0.16.4)
Expand Down Expand Up @@ -258,7 +259,7 @@ GEM
actionpack (>= 6.0.0, < 7.2)
method_source (1.0.0)
mini_mime (1.1.5)
minitest (5.20.0)
minitest (5.21.1)
mobility (1.2.9)
i18n (>= 0.6.10, < 2)
request_store (~> 1.0)
Expand All @@ -282,7 +283,7 @@ GEM
orm_adapter (0.5.0)
package_json (0.1.0)
parallel (1.24.0)
parser (3.3.0.2)
parser (3.3.0.4)
ast (~> 2.4.1)
racc
pdf-core (0.9.0)
Expand Down Expand Up @@ -368,7 +369,7 @@ GEM
ffi (~> 1.0)
rdoc (6.6.2)
psych (>= 4.0.0)
react-rails (3.1.1)
react-rails (3.2.0)
babel-transpiler (>= 0.7.0)
connection_pool
execjs
Expand Down Expand Up @@ -408,11 +409,11 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rubocop (1.59.0)
rubocop (1.60.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
Expand All @@ -437,10 +438,10 @@ GEM
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-lsp (0.13.2)
ruby-lsp (0.13.4)
language_server-protocol (~> 3.17.0)
prism (>= 0.19.0, < 0.20)
sorbet-runtime (>= 0.5.5685)
sorbet-runtime (>= 0.5.10782)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
Expand Down Expand Up @@ -478,7 +479,7 @@ GEM
actionpack (>= 3.1)
railties (>= 3.1)
slim (>= 3.0, < 6.0, != 5.0.0)
sorbet-runtime (0.5.11181)
sorbet-runtime (0.5.11193)
squasher (0.7.3)
statesman (12.1.0)
statsd-ruby (1.5.0)
Expand Down Expand Up @@ -541,6 +542,7 @@ DEPENDENCIES
faraday
i18n-tasks
i18n-tasks-csv
iban-tools
icalendar
inline_svg
kramdown
Expand Down
3 changes: 0 additions & 3 deletions Procfile

This file was deleted.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
V23.12.2
V24.1.1
3 changes: 2 additions & 1 deletion app/controllers/manage/bookings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def calendar

def new
@booking = preparation_service.prepare_new(booking_params)
@booking.assign_attributes(organisation: current_organisation, transition_to: :provisional_request)
@booking.assign_attributes(organisation: current_organisation,
transition_to: current_organisation.settings.default_manage_transition_to_state)
@booking.booking_questions = BookingQuestion.applying_to_booking(@booking)

respond_with :manage, @booking
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/manage/designated_documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def destroy

def designated_document_params
params[:designated_document]&.permit(:designation, :file, :locale, :remarks, :name,
:send_with_contract, :send_with_last_infos,
:send_with_accepted, :send_with_contract, :send_with_last_infos,
attaching_conditions_attributes: BookingConditionParams.permitted_keys +
%i[id _destroy])
end
Expand Down
4 changes: 3 additions & 1 deletion app/domain/booking_states/definitive_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def self.to_sym
booking.deadline&.clear
OperatorResponsibility.assign(booking, :home_handover, :home_return)
MailTemplate.use(:manage_definitive_request_notification, booking, to: :administration, &:autodeliver)
MailTemplate.use(:definitive_request_notification, booking, to: :tenant, &:autodeliver)
mail = MailTemplate.use(:definitive_request_notification, booking, to: :tenant)
mail&.attach :accepted_documents if booking.state_transitions.last(2).map(&:to_state) == [OpenRequest.to_s, to_s]
mail&.autodeliver
end

def relevant_time
Expand Down
4 changes: 3 additions & 1 deletion app/domain/booking_states/provisional_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def self.to_sym
booking.tentative!
next if booking.committed_request

MailTemplate.use(:provisional_request_notification, booking, to: :tenant, &:autodeliver)
mail = MailTemplate.use(:provisional_request_notification, booking, to: :tenant)
mail&.attach :accepted_documents if booking.state_transitions.last(2).map(&:to_state) == [OpenRequest.to_s, to_s]
mail&.autodeliver
end

infer_transition(to: :definitive_request) do |booking|
Expand Down
1 change: 1 addition & 0 deletions app/models/designated_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# locale :string
# name :string
# remarks :text
# send_with_accepted :boolean default(FALSE), not null
# send_with_contract :boolean default(FALSE), not null
# send_with_last_infos :boolean default(FALSE)
# created_at :datetime not null
Expand Down
32 changes: 32 additions & 0 deletions app/models/iban.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

class IBAN < IBANTools::IBAN
def to_s
prettify
end

def valid?
self.class.valid?(to_s)
end

def qrr?
valid? && country_code.upcase == 'CH' && (30_000..31_999).include?(numerify[0..4].to_i)
end

class Type < ActiveModel::Type::String
def cast_value(value)
return if value.blank?

case value
when String
IBAN.new(value)
when IBAN
value
end
end

def serialize(value)
super(value&.to_s)
end
end
end
5 changes: 3 additions & 2 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class Notification < ApplicationRecord
validate do
next if booking.nil? || to.blank?
next if booking.roles.keys.include?(to.to_sym)
next if deliver_to.present?

# next if Devise.email_regexp =~ to.to_s
# next if Array.wrap(deliver_to).all? { Devise.email_regexp.match(_1) }

errors.add(:to, :invalid)
end
Expand Down Expand Up @@ -107,7 +108,7 @@ def deliver_bcc
end

def deliver_to
[resolve_to.try(:email).presence || resolve_to.to_s.presence].flatten.compact
[resolve_to.try(:email).presence].flatten.compact
end

def locale
Expand Down
3 changes: 2 additions & 1 deletion app/models/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# mail_from :string
# name :string
# notifications_enabled :boolean default(TRUE)
# qr_iban :string
# ref_template :string default("%<home_ref>s%<year>04d%<month>02d%<day>02d%<same_day_alpha>s")
# representative_address :string
# settings :jsonb
Expand Down Expand Up @@ -77,11 +76,13 @@ class Organisation < ApplicationRecord
errors.add(:settings, :invalid) unless settings.valid?
errors.add(:smtp_settings, :invalid) unless smtp_settings.nil? || smtp_settings.valid?
errors.add(:creditor_address, :invalid) if creditor_address_lines.count > 3
errors.add(:iban, :invalid) if iban.present? && !iban.valid?
end

attribute :booking_flow_type, default: -> { BookingFlows::Default.to_s }
attribute :settings, Settings::Type.new(OrganisationSettings), default: -> { OrganisationSettings.new }
attribute :smtp_settings, Settings::Type.new(SmtpSettings)
attribute :iban, IBAN::Type.new

def booking_flow_class
@booking_flow_class ||= BookingFlows.const_get(booking_flow_type)
Expand Down
7 changes: 5 additions & 2 deletions app/models/organisation_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class OrganisationSettings < Settings
attribute :tentative_occupancy_color, :string, default: '#e8bc56'
attribute :occupied_occupancy_color, :string, default: '#e85f5f' || '#f2a2a2'
attribute :closed_occupancy_color, :string, default: '#929292'
attribute :begins_at_default_time, DurationType.new, default: -> { 8.hours }
attribute :ends_at_default_time, DurationType.new, default: -> { 3.days }
attribute :default_manage_transition_to_state, :string, default: -> { BookingStates::ProvisionalRequest.to_sym }
attribute :default_calendar_view, :string, default: 'months'
attribute :default_begins_at_time, :string, default: -> { '08:00' }
attribute :default_ends_at_time, :string, default: -> { '16:00' }
Expand Down Expand Up @@ -48,4 +47,8 @@ def self.time_hash(value)
time_array = value&.split(':')
{ hour: time_array&.first, minutes: time_array&.second }
end

def manage_transition_to_states(organisation)
organisation.booking_flow_class.successors['initial'].map { BookingStates.all.fetch(_1.to_sym) }.compact_blank
end
end
3 changes: 2 additions & 1 deletion app/models/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class Payment < ApplicationRecord
end

def duplicates
Payment.where(booking:, paid_at:, amount:, camt_instr_id:).where.not(id: [id])
Payment.where(booking:, paid_at:, amount:, camt_instr_id:, invoice_id:)
.where.not(id: [id])
end

def confirm!
Expand Down
6 changes: 3 additions & 3 deletions app/models/payment_infos/qr_bill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def qr_data
qrtype: QRTYPE,
version: VERSION,
coding_type: CODING_TYPE,
cr_account: creditor_account&.delete(' '),
cr_account: creditor_account&.to_s&.delete(' '),
cr_address_type: ADDRESS_TYPE,
cr_name: creditor_address_lines.fetch(0, ''),
cr_address_line_1: creditor_address_lines.fetch(1, ''),
Expand Down Expand Up @@ -71,7 +71,7 @@ def debitor_address_lines
end

def creditor_account
organisation.qr_iban.presence || organisation.iban.presence
organisation.iban.to_s.presence
end

def currency
Expand All @@ -96,7 +96,7 @@ def checksum(ref)
end

def ref_type
organisation.qr_iban.present? ? :QRR : :SCOR
organisation.iban&.qrr? ? :QRR : :SCOR
end

def scor_ref
Expand Down
4 changes: 2 additions & 2 deletions app/params/manage/organisation_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Manage
class OrganisationParams < ApplicationParams
def self.permitted_keys
%i[name address logo location bcc
ref_template iban qr_iban mail_from locale default_payment_info_type creditor_address
ref_template iban mail_from locale default_payment_info_type creditor_address
representative_address contract_signature email notifications_enabled] +
[{ settings: settings_permitted_keys }]
end
Expand All @@ -15,7 +15,7 @@ def self.settings_permitted_keys
last_minute_warning upcoming_soon_window invoice_payment_deadline
deposit_payment_deadline deadline_postponable_for payment_overdue_deadline
occupied_occupancy_color tentative_occupancy_color closed_occupancy_color
begins_at_default_time ends_at_default_time default_calendar_view
default_calendar_view default_manage_transition_to_state
default_begins_at_time default_ends_at_time show_outbox] +
[{ occupied_occupancy_states: [] }]
end
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/manage/cost_estimation_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Manage
class CostEstimationSerializer < ApplicationSerializer
fields :used, :invoiced, :deposited, :per_day, :per_person, :per_person_per_day, :days
fields :used, :invoiced, :invoiced_deposits, :per_day, :per_person, :per_person_per_day, :days
end
end
2 changes: 1 addition & 1 deletion app/serializers/manage/designated_document_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Manage
class DesignatedDocumentSerializer < ApplicationSerializer
fields :designation, :locale, :name, :send_with_contract, :send_with_last_infos
fields :designation, :locale, :name, :send_with_accepted, :send_with_contract, :send_with_last_infos
field :file_url do |designated_document|
url.url_for(designated_document.file)
end
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/manage/organisation_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class OrganisationSerializer < Public::OrganisationSerializer
association :tarifs, blueprint: TarifSerializer
association :booking_questions, blueprint: Public::BookingQuestionSerializer

fields :qr_iban, :esr_beneficiary_account, :iban, :mail_from,
fields :esr_beneficiary_account, :iban, :mail_from,
:booking_flow_type, :invoice_ref_strategy_type, :notifications_enabled, :location

field :designated_documents do |organisation|
Expand Down
3 changes: 2 additions & 1 deletion app/services/attachment_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class AttachmentManager
unsent_offers: ->(booking) { booking.invoices.offers.unsent },
contract: ->(booking) { booking.contract },
last_info_documents: ->(booking) { DesignatedDocument.for_booking(booking).where(send_with_last_infos: true) },
contract_documents: ->(booking) { DesignatedDocument.for_booking(booking).where(send_with_contract: true) }
contract_documents: ->(booking) { DesignatedDocument.for_booking(booking).where(send_with_contract: true) },
accepted_documents: ->(booking) { DesignatedDocument.for_booking(booking).where(send_with_accepted: true) }
}.freeze

def initialize(booking, target:)
Expand Down
8 changes: 6 additions & 2 deletions app/services/cost_estimation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ def invoiced
invoices = Invoices::Invoice.of(booking).kept
return if invoices.blank?

@invoiced ||= deposited + invoices.sum(:amount)
@invoiced ||= invoices.sum(:amount)
end

def deposited
def invoiced_deposits
Invoices::Deposit.of(booking).kept.sum(:amount) || 0
end

def paid
booking.payments.where(write_off: false).sum(:amount)
end

def per_day
return if invoiced.nil?

Expand Down
Loading

0 comments on commit 9ceddc4

Please sign in to comment.