Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
diegosteiner committed Jan 10, 2024
2 parents 74db1d8 + a5d5c0a commit 981fb62
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 55 deletions.
46 changes: 25 additions & 21 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -420,17 +423,17 @@ 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)
activesupport (>= 4.2.0)
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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions app/domain/booking_states/cancelation_pending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion app/models/contract/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/data_digest_templates/booking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/operator_responsibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 35 additions & 6 deletions app/models/tarif.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions app/models/tarifs/price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 1 addition & 25 deletions app/models/usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 981fb62

Please sign in to comment.