Skip to content

Commit

Permalink
Merge pull request #264 from diegosteiner/develop
Browse files Browse the repository at this point in the history
2023.10.2
  • Loading branch information
diegosteiner committed Oct 30, 2023
2 parents 3f70bb0 + 816289c commit f015fde
Show file tree
Hide file tree
Showing 57 changed files with 587 additions and 431 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

## Unreleased

## Version 23.10.2

- Improvement: Recognize payment duplicates more accurately
- Feature: Edit contract and invoice emails before send
- Updates

## Version 23.10.1

- Improvement: Limit year calender scroll to 1 month
- Improvement: Limit year calender scroll to 1 month
- Bugfixes

## Version 23.9.3
Expand Down
39 changes: 19 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ GEM
rake (>= 10.4, < 14.0)
ast (2.4.2)
aws-eventstream (1.2.0)
aws-partitions (1.835.0)
aws-partitions (1.842.0)
aws-sdk-core (3.185.1)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
Expand All @@ -96,7 +96,7 @@ GEM
aws-sdk-core (~> 3, >= 3.181.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.6)
aws-sigv4 (1.6.0)
aws-sigv4 (1.6.1)
aws-eventstream (~> 1, >= 1.0.2)
babel-source (5.8.35)
babel-transpiler (0.7.0)
Expand All @@ -120,7 +120,7 @@ GEM
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
byebug (11.1.3)
camt_parser (2.15.1)
camt_parser (2.16.0)
nokogiri
cancancan (3.5.0)
capybara (3.39.2)
Expand Down Expand Up @@ -191,10 +191,10 @@ GEM
ffi (1.16.3)
foreman (0.87.2)
forwardable (1.3.3)
fugit (1.8.1)
fugit (1.9.0)
et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4)
gettext (3.4.4)
gettext (3.4.9)
erubi
locale (>= 2.0.5)
prime
Expand Down Expand Up @@ -262,7 +262,7 @@ GEM
msgpack (1.7.2)
multi_json (1.15.0)
mutex_m (0.1.2)
net-imap (0.4.1)
net-imap (0.4.2)
date
net-protocol
net-pop (0.1.2)
Expand Down Expand Up @@ -301,7 +301,7 @@ GEM
pry-rescue (1.5.2)
interception (>= 0.5)
pry (>= 0.12.0)
psych (5.1.1)
psych (5.1.1.1)
stringio
public_suffix (5.0.3)
puma (6.4.0)
Expand Down Expand Up @@ -367,9 +367,9 @@ GEM
execjs
railties (>= 3.2)
tilt
redis (5.0.7)
redis-client (>= 0.9.0)
redis-client (0.17.0)
redis (5.0.8)
redis-client (>= 0.17.0)
redis-client (0.18.0)
connection_pool
regexp_parser (2.8.2)
reline (0.3.9)
Expand Down Expand Up @@ -401,8 +401,7 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rubocop (1.57.1)
base64 (~> 0.1.1)
rubocop (1.57.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -413,7 +412,7 @@ GEM
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.19.0)
rubocop (~> 1.41)
Expand All @@ -422,12 +421,12 @@ GEM
rubocop-performance (1.19.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.21.2)
rubocop-rails (2.22.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-rspec (2.24.1)
rubocop (~> 1.33)
rubocop-rspec (2.25.0)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
Expand Down Expand Up @@ -461,7 +460,7 @@ GEM
slim (5.1.1)
temple (~> 0.10.0)
tilt (>= 2.1.0)
slim-rails (3.6.2)
slim-rails (3.6.3)
actionpack (>= 3.1)
railties (>= 3.1)
slim (>= 3.0, < 6.0, != 5.0.0)
Expand All @@ -473,11 +472,11 @@ GEM
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
text (1.3.1)
thor (1.2.2)
thor (1.3.0)
tilt (2.3.0)
timeout (0.4.0)
translation (1.37)
gettext (~> 3.2, >= 3.2.5, <= 3.4.4)
translation (1.38)
gettext (~> 3.2, >= 3.2.5, <= 3.4.9)
ttfunk (1.7.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
V23.10.1
V23.10.2
23 changes: 16 additions & 7 deletions app/controllers/manage/bookings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ def create

def update
@booking.assign_attributes(booking_params)
responses = BookingQuestionResponse.process_nested_attributes(@booking, booking_question_responses_params,
manage: true)
@booking.booking_question_responses = responses unless responses.nil?
process_booking_question_responses
@booking.save(context: :manage_update)
call_booking_action
Booking::Log.log(@booking, trigger: :manager, action: booking_action, user: current_user)
respond_with :manage, @booking
redirect_to = call_booking_action
write_booking_log
respond_with :manage, @booking, location: redirect_to
end

def destroy
Expand All @@ -85,12 +83,23 @@ def preparation_service
@preparation_service ||= BookingPreparationService.new(current_organisation)
end

def write_booking_log
Booking::Log.log(@booking, trigger: :manager, action: booking_action, user: current_user)
end

def set_filter
@filter = Booking::Filter.new(default_booking_filter_params.merge(booking_filter_params))
end

def process_booking_question_responses
responses = BookingQuestionResponse.process_nested_attributes(@booking, booking_question_responses_params,
manage: true)
@booking.booking_question_responses = responses unless responses.nil?
end

def call_booking_action
booking_action&.call(booking: @booking)
result = booking_action&.call(booking: @booking)
instance_eval(&result.redirect_proc) if result&.redirect_proc.present?
rescue BookingActions::Base::NotAllowed
@booking.errors.add(:base, :action_not_allowed)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/manage/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index
@payments = @booking.payments.ordered
else
@payments = @payments.joins(:booking).where(booking: { organisation: current_organisation }).ordered
@payments = @payments.last_year if params[:all].blank?
@payments = @payments.recent if params[:all].blank?
end
respond_with :manage, @payments
end
Expand Down
3 changes: 3 additions & 0 deletions app/domain/booking_actions/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module BookingActions
class Base
class NotAllowed < StandardError; end
Result = Struct.new(:ok, :redirect_proc, keyword_init: true)

include Translatable
extend Translatable
Expand Down Expand Up @@ -34,6 +35,8 @@ def to_s
self.class.action_name
end

def redirect_to; end

def button_options
{
variant: 'primary'
Expand Down
2 changes: 1 addition & 1 deletion app/domain/booking_actions/manage/accept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module BookingActions
module Manage
class Accept < BookingActions::Base
def call!
booking.update(transition_to: transition_to)
Result.new ok: booking.update(transition_to: transition_to)
end

def allowed?
Expand Down
8 changes: 6 additions & 2 deletions app/domain/booking_actions/manage/cancel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ module Manage
class Cancel < BookingActions::Base
def call!
booking.errors.clear
booking.update(transition_to: :declined_request) if booking.can_transition_to?(:declined_request)
booking.update(transition_to: :cancelation_pending) if booking.can_transition_to?(:cancelation_pending)
transition_to = if booking.can_transition_to?(:declined_request)
:declined_request
elsif booking.can_transition_to?(:cancelation_pending)
:cancelation_pending
end
Result.new ok: booking.update(transition_to: transition_to)
end

def allowed?
Expand Down
2 changes: 1 addition & 1 deletion app/domain/booking_actions/manage/commit_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module BookingActions
module Manage
class CommitRequest < BookingActions::Base
def call!
booking.update(committed_request: true)
Result.new ok: booking.update(committed_request: true)
end

def allowed?
Expand Down
14 changes: 12 additions & 2 deletions app/domain/booking_actions/manage/email_contract_and_deposit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class EmailContractAndDeposit < BookingActions::Base

def call!
notification = prepare_notification
notification.save! && contract.sent! && invoices.each(&:sent!) && notification.deliver
notification.dup.tap { _1.to = operator }.deliver if operator&.email.present?
notification.save! && contract.sent! && invoices.each(&:sent!)

Result.new ok: notification.valid?, redirect_proc: redirect_proc(notification)
end

def allowed?
Expand All @@ -21,6 +22,14 @@ def allowed?

private

def redirect_proc(notification)
return unless notification&.persisted?

proc do
edit_manage_notification_path(notification)
end
end

def invoices
@invoices ||= booking.invoices.kept.unsent.where(type: [Invoices::Deposit.to_s, Invoices::Offer.to_s])
end
Expand All @@ -40,6 +49,7 @@ def prepare_attachments
def prepare_notification
booking.notifications.new(template: :awaiting_contract_notification, to: booking.tenant,
template_context: { contract: contract, invoices: invoices }).tap do |notification|
notification.bcc = operator.email if operator&.email.present?
notification.attach(prepare_attachments)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class EmailContractWithoutDeposit < EmailContractAndDeposit
required_by: self)

def call!(contract = booking.contract)
notification = booking.notifications.new(template: :awaiting_contract_notification, to: booking.tenant,
template_context: { contract: contract })
notification.attach(prepare_attachments(booking, contract))
notification.save! && contract.sent! && notification.deliver
notification = prepare_notification
notification.save! && contract.sent!

Result.new ok: notification.valid?, redirect_proc: redirect_proc(notification)
end

def allowed?
Expand All @@ -30,13 +30,28 @@ def button_options

private

def redirect_proc(notification)
return unless notification&.persisted?

proc do
edit_manage_notification_path(notification)
end
end

def prepare_attachments(booking, contract)
[
DesignatedDocument.for_booking(booking).where(send_with_contract: true),
contract.pdf
].flatten.compact
end

def prepare_notification
booking.notifications.new(template: :awaiting_contract_notification, to: booking.tenant,
template_context: { contract: contract }).tap do |notification|
notification.attach(prepare_attachments(booking, contract))
end
end

def booking
context.fetch(:booking)
end
Expand Down
14 changes: 12 additions & 2 deletions app/domain/booking_actions/manage/email_invoices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class EmailInvoices < BookingActions::Base

def call!
notification = prepare_notification
notification.deliver && invoices.each(&:sent!)
notification.dup.tap { _1.to = operator }.deliver if operator&.email.present?
notification.save! && invoices.each(&:sent!)

Result.new ok: notification.valid?, redirect_proc: redirect_proc(notification)
end

def allowed?
Expand All @@ -19,6 +20,14 @@ def allowed?

protected

def redirect_proc(notification)
return unless notification&.persisted?

proc do
edit_manage_notification_path(notification)
end
end

def booking
context.fetch(:booking)
end
Expand All @@ -31,6 +40,7 @@ def invoices
def prepare_notification
booking.notifications.new(template: :payment_due_notification, to: booking.tenant,
template_context: { invoices: invoices }) do |notification|
notification.bcc = operator.email if operator&.email.present?
notification.attach(prepare_attachments)
end
end
Expand Down
12 changes: 11 additions & 1 deletion app/domain/booking_actions/manage/email_offers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class EmailOffers < BookingActions::Base

def call!
notification = prepare_notification
notification.deliver && offers.each(&:sent!)
notification.save! && offers.each(&:sent!)

Result.new ok: notification.valid?, redirect_proc: redirect_proc(notification)
end

def allowed?
Expand All @@ -16,6 +18,14 @@ def allowed?

protected

def redirect_proc(notification)
return unless notification&.persisted?

proc do
edit_manage_notification_path(notification)
end
end

def booking
context.fetch(:booking)
end
Expand Down
Loading

0 comments on commit f015fde

Please sign in to comment.