From 604ec38991b6334492b4f3d98766a41e8d672a3d Mon Sep 17 00:00:00 2001 From: Diego Steiner Date: Mon, 8 Jan 2024 08:57:42 +0000 Subject: [PATCH 1/5] fix: regression error --- app/models/data_digest_templates/booking.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/data_digest_templates/booking.rb b/app/models/data_digest_templates/booking.rb index 1e4f7fa4..c39bcd4c 100644 --- a/app/models/data_digest_templates/booking.rb +++ b/app/models/data_digest_templates/booking.rb @@ -90,7 +90,7 @@ class Booking < ::DataDigestTemplate column_type :usage do body do |booking, template_context_cache| tarif = ::Tarif.find_by(id: @config[:tarif_id]) - context = template_context_cache[cache_key(booking, :usage, tarif.id)] ||= + context = template_context_cache[cache_key(booking, :usage, tarif&.id)] ||= TemplateContext.new(usage: booking.usages.of_tarif(tarif).take).to_h @templates[:body]&.render!(context) end From e76ef47b2cf8ca47ce5a4258fd8a391ac1cec813 Mon Sep 17 00:00:00 2001 From: Diego Steiner Date: Tue, 9 Jan 2024 09:17:42 +0000 Subject: [PATCH 2/5] feature: add admin notification when cancelllation is pending --- app/domain/booking_states/cancelation_pending.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/domain/booking_states/cancelation_pending.rb b/app/domain/booking_states/cancelation_pending.rb index 15d9e2e2..b3821b17 100644 --- a/app/domain/booking_states/cancelation_pending.rb +++ b/app/domain/booking_states/cancelation_pending.rb @@ -3,6 +3,7 @@ module BookingStates class CancelationPending < Base templates << MailTemplate.define(:operator_cancelation_pending_notification, context: %i[booking], optional: true) + templates << MailTemplate.define(:manage_cancelation_pending_notification, context: %i[booking], optional: true) def checklist [] end @@ -25,6 +26,7 @@ def self.successors booking.update!(editable: false) MailTemplate.use(:operator_cancelation_pending_notification, booking, to: :home_handover, &:autodeliver) MailTemplate.use(:operator_cancelation_pending_notification, booking, to: :home_return, &:autodeliver) + MailTemplate.use(:manage_cancelation_pending_notification, booking, to: :administration, &:autodeliver) end infer_transition(to: :cancelled) do |booking| From a35e0687d33c0a93efafe02c4d80c2465d483f79 Mon Sep 17 00:00:00 2001 From: Diego Steiner Date: Wed, 10 Jan 2024 13:17:35 +0000 Subject: [PATCH 3/5] fix: operator responsibilities default without conditions --- app/models/operator_responsibility.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/operator_responsibility.rb b/app/models/operator_responsibility.rb index 21891bc7..52674869 100644 --- a/app/models/operator_responsibility.rb +++ b/app/models/operator_responsibility.rb @@ -63,7 +63,7 @@ def update_booking_conditions end def assign_to_booking?(booking) - assigning_conditions.any? && BookingCondition.fullfills_all?(booking, assigning_conditions) + assigning_conditions.none? || BookingCondition.fullfills_all?(booking, assigning_conditions) end def self.assign(booking, *responsibilities) From 9f842059a6234bcc9d83ab7b0164d1c7e1217cb1 Mon Sep 17 00:00:00 2001 From: Diego Steiner Date: Wed, 10 Jan 2024 13:23:32 +0000 Subject: [PATCH 4/5] fix: prefill for price should equal the price per unit --- app/models/contract/factory.rb | 2 +- app/models/tarif.rb | 41 +++++++++++++++++++++++++++++----- app/models/tarifs/price.rb | 4 ++++ app/models/usage.rb | 26 +-------------------- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/app/models/contract/factory.rb b/app/models/contract/factory.rb index 67b7d3c3..0d9dde2b 100644 --- a/app/models/contract/factory.rb +++ b/app/models/contract/factory.rb @@ -29,7 +29,7 @@ def template_context(contract) booking = contract.booking TemplateContext.new( booking:, organisation: booking.organisation, contract:, - cost_estimation: CostEstimation.new(booking), + costs: CostEstimation.new(booking), tarifs_table_placeholder: Export::Pdf::ContractPdf::TARIFS_TABLE_PLACEHOLDER ) end diff --git a/app/models/tarif.rb b/app/models/tarif.rb index 1dcb969f..da1fb469 100644 --- a/app/models/tarif.rb +++ b/app/models/tarif.rb @@ -42,6 +42,14 @@ class Tarif < ApplicationRecord ASSOCIATED_TYPES = { deposit: Invoices::Deposit, invoice: Invoices::Invoice, late_notice: Invoices::LateNotice, offer: Invoices::Offer, contract: ::Contract }.freeze + PREFILL_METHODS = { + flat: -> { 1 }, + days: -> { booking.nights + 1 }, + nights: -> { booking.nights }, + headcount_nights: -> { booking.nights * (booking.approximate_headcount || 0) }, + headcount: -> { booking.approximate_headcount || 0 } + }.with_indifferent_access.freeze + include ActiveSupport::NumberHelper extend TemplateRenderable @@ -61,7 +69,7 @@ class Tarif < ApplicationRecord has_many :enabling_conditions, -> { qualifiable_group(:enabling) }, as: :qualifiable, dependent: :destroy, class_name: :BookingCondition, inverse_of: false - enum prefill_usage_method: Usage::PREFILL_METHODS.keys.index_with(&:to_s) + enum prefill_usage_method: Tarif::PREFILL_METHODS.keys.index_with(&:to_s) scope :ordered, -> { order(:ordinal) } scope :pinned, -> { where(pin: true) } @@ -92,6 +100,32 @@ def before_usage_validation(_usage); end def before_usage_save(_usage); end + def prefill_usage_booking_questions + booking_question_types = %w[BookingQuestions::Integer] + organisation.booking_questions.ordered.where(type: booking_question_types) + end + + def presumed_units_question_factor(usage) + booking_question = prefill_usage_booking_question + return nil if booking_question.blank? || usage&.booking&.blank? + + usage.booking.booking_question_responses.find_by(booking_question:)&.value.presence || 0 + end + + def presumed_units_prefill_factor(usage) + prefill_proc = PREFILL_METHODS[prefill_usage_method] + return if prefill_proc.blank? + + usage.instance_exec(&prefill_proc).presence || 0 + end + + def presumed_units(usage) + return nil if presumed_units_prefill_factor(usage).blank? && + presumed_units_question_factor(usage).blank? + + (presumed_units_prefill_factor(usage).presence || 1) * (presumed_units_question_factor(usage).presence || 1) + end + def breakdown(usage) key ||= :flat if is_a?(Tarifs::Flat) key ||= :default @@ -115,11 +149,6 @@ def update_booking_conditions selecting_conditions.each { |condition| condition.assign_attributes(qualifiable: self, group: :selecting) } end - def prefill_usage_booking_questions - booking_question_types = %w[BookingQuestions::Integer] - organisation.booking_questions.ordered.where(type: booking_question_types) - end - private def breakdown_options(usage) diff --git a/app/models/tarifs/price.rb b/app/models/tarifs/price.rb index 092b3b05..c6d337bd 100644 --- a/app/models/tarifs/price.rb +++ b/app/models/tarifs/price.rb @@ -53,6 +53,10 @@ def breakdown(usage) number_to_currency(usage.used_units, unit: organisation.currency) end + def presumed_units(usage) + self[:price_per_unit].presence + end + def price_per_unit nil end diff --git a/app/models/usage.rb b/app/models/usage.rb index 54b1c6e1..6a7397fc 100644 --- a/app/models/usage.rb +++ b/app/models/usage.rb @@ -27,14 +27,6 @@ # class Usage < ApplicationRecord - PREFILL_METHODS = { - flat: -> { 1 }, - days: -> { booking.nights + 1 }, - nights: -> { booking.nights }, - headcount_nights: -> { booking.nights * (booking.approximate_headcount || 0) }, - headcount: -> { booking.approximate_headcount || 0 } - }.with_indifferent_access.freeze - belongs_to :tarif, -> { include_conditions }, inverse_of: :usages belongs_to :booking, inverse_of: :usages, touch: true has_many :invoice_parts, dependent: :nullify @@ -60,24 +52,8 @@ def price (price * 20.0).floor / 20.0 end - def presumed_units_prefill_factor - prefill_proc = PREFILL_METHODS[tarif.prefill_usage_method] - return if prefill_proc.blank? - - instance_exec(&prefill_proc).presence || 0 - end - - def presumed_units_question_factor - booking_question = tarif.prefill_usage_booking_question - return nil if booking_question.blank? || booking.blank? - - booking.booking_question_responses.find_by(booking_question:)&.value.presence || 0 - end - def presumed_units - return nil if presumed_units_prefill_factor.blank? && presumed_units_question_factor.blank? - - (presumed_units_prefill_factor.presence || 1) * (presumed_units_question_factor.presence || 1) + tarif&.presumed_units(self) end def pin_price_per_unit From a5d5c0a804cf3ae510bf0e54537ac28f177b9944 Mon Sep 17 00:00:00 2001 From: Diego Steiner Date: Wed, 10 Jan 2024 13:23:43 +0000 Subject: [PATCH 5/5] chore: update dependencies --- Gemfile.lock | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8836dafa..d74e109d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,7 @@ GEM remote: https://rubygems.org/ specs: + abbrev (0.1.2) actioncable (7.1.2) actionpack (= 7.1.2) activesupport (= 7.1.2) @@ -85,12 +86,12 @@ GEM ast (2.4.2) aws-eventstream (1.3.0) aws-partitions (1.877.0) - aws-sdk-core (3.190.1) + aws-sdk-core (3.190.2) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) jmespath (~> 1, >= 1.6.1) - aws-sdk-kms (1.75.0) + aws-sdk-kms (1.76.0) aws-sdk-core (~> 3, >= 3.188.0) aws-sigv4 (~> 1.1) aws-sdk-s3 (1.142.0) @@ -186,11 +187,10 @@ GEM railties (>= 5.0.0) faker (3.2.2) i18n (>= 1.8.11, < 2) - faraday (2.8.1) - base64 - faraday-net_http (>= 2.0, < 3.1) - ruby2_keywords (>= 0.0.4) - faraday-net_http (3.0.2) + faraday (2.9.0) + faraday-net_http (>= 2.0, < 3.2) + faraday-net_http (3.1.0) + net-http ffi (1.16.3) forwardable (1.3.3) fugit (1.9.0) @@ -204,7 +204,8 @@ GEM text (>= 1.3.0) globalid (1.2.1) activesupport (>= 6.1) - highline (2.1.0) + highline (3.0.0) + abbrev i18n (1.14.1) concurrent-ruby (~> 1.0) i18n-tasks (0.9.37) @@ -227,9 +228,9 @@ GEM nokogiri (>= 1.6) interception (0.5) io-console (0.7.1) - irb (1.11.0) + irb (1.11.1) rdoc - reline (>= 0.3.8) + reline (>= 0.4.2) jmespath (1.6.2) json (2.7.1) kramdown (2.4.0) @@ -264,6 +265,8 @@ GEM msgpack (1.7.2) multi_json (1.15.0) mutex_m (0.2.0) + net-http (0.4.1) + uri net-imap (0.4.9.1) date net-protocol @@ -279,7 +282,7 @@ GEM orm_adapter (0.5.0) package_json (0.1.0) parallel (1.24.0) - parser (3.2.2.4) + parser (3.3.0.2) ast (~> 2.4.1) racc pdf-core (0.9.0) @@ -302,13 +305,13 @@ GEM method_source (~> 1.0) pry-rails (0.3.9) pry (>= 0.10.4) - pry-rescue (1.5.2) + pry-rescue (1.6.0) interception (>= 0.5) pry (>= 0.12.0) psych (5.1.2) stringio public_suffix (5.0.4) - puma (6.4.1) + puma (6.4.2) nio4r (~> 2.0) raabro (1.4.0) racc (1.7.3) @@ -375,8 +378,8 @@ GEM redis-client (>= 0.17.0) redis-client (0.19.1) connection_pool - regexp_parser (2.8.3) - reline (0.4.1) + regexp_parser (2.9.0) + reline (0.4.2) io-console (~> 0.5) request_store (1.5.1) rack (>= 1.4) @@ -420,9 +423,9 @@ GEM parser (>= 3.2.1.0) rubocop-capybara (2.20.0) rubocop (~> 1.41) - rubocop-factory_bot (2.25.0) - rubocop (~> 1.33) - rubocop-performance (1.20.1) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) + rubocop-performance (1.20.2) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.30.0, < 2.0) rubocop-rails (2.23.1) @@ -430,7 +433,7 @@ GEM rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) rubocop-ast (>= 1.30.0, < 2.0) - rubocop-rspec (2.26.0) + rubocop-rspec (2.26.1) rubocop (~> 1.40) rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) @@ -475,9 +478,9 @@ GEM actionpack (>= 3.1) railties (>= 3.1) slim (>= 3.0, < 6.0, != 5.0.0) - sorbet-runtime (0.5.11178) + sorbet-runtime (0.5.11181) squasher (0.7.3) - statesman (12.0.0) + statesman (12.1.0) statsd-ruby (1.5.0) stringio (3.1.0) temple (0.10.3) @@ -494,6 +497,7 @@ GEM concurrent-ruby (~> 1.0) unaccent (0.4.0) unicode-display_width (2.5.0) + uri (0.13.0) warden (1.2.9) rack (>= 2.0.9) webrick (1.8.1)