Skip to content

Commit

Permalink
Merge pull request #312 from diegosteiner/develop
Browse files Browse the repository at this point in the history
24.5.1
  • Loading branch information
diegosteiner authored May 27, 2024
2 parents 2c64903 + d0f878d commit d5d621f
Show file tree
Hide file tree
Showing 48 changed files with 248 additions and 115 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

## Version 24.5.1

- Feature: Use {{ TARIFS }} placeholder in contract and invoice templates
- Feature: Attach DesignatedDocuments to any MailTemplates
- Fix: Fix 12:00 bug in calendar

## Version 24.4.3

Released on 27.04.2024
Expand Down
36 changes: 16 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ GEM
rake (>= 10.4, < 14.0)
ast (2.4.2)
aws-eventstream (1.3.0)
aws-partitions (1.930.0)
aws-partitions (1.934.0)
aws-sdk-core (3.196.1)
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.81.0)
aws-sdk-kms (1.82.0)
aws-sdk-core (~> 3, >= 3.193.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.151.0)
Expand Down Expand Up @@ -124,7 +124,7 @@ GEM
byebug (11.1.3)
camt_parser (2.16.0)
nokogiri
cancancan (3.5.0)
cancancan (3.6.0)
capybara (3.40.0)
addressable
matrix
Expand All @@ -142,7 +142,7 @@ GEM
coderay (1.1.3)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
countries (6.0.0)
countries (6.0.1)
unaccent (~> 0.3)
country_select (9.0.0)
countries (> 5.0, < 7.0)
Expand Down Expand Up @@ -185,7 +185,7 @@ GEM
concurrent-ruby (~> 1.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-schema (1.13.3)
dry-schema (1.13.4)
concurrent-ruby (~> 1.0)
dry-configurable (~> 1.0, >= 1.0.1)
dry-core (~> 1.0, < 2)
Expand Down Expand Up @@ -285,7 +285,7 @@ GEM
actionpack (>= 6.0.0, < 7.2)
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.23.0)
minitest (5.23.1)
mobility (1.2.9)
i18n (>= 0.6.10, < 2)
request_store (~> 1.0)
Expand Down Expand Up @@ -325,7 +325,7 @@ GEM
prime (0.1.2)
forwardable
singleton
prism (0.27.0)
prism (0.29.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
Expand All @@ -340,7 +340,7 @@ GEM
puma (6.4.2)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.7.3)
racc (1.8.0)
rack (3.0.11)
rack-mini-profiler (3.3.1)
rack (>= 1.2.0)
Expand Down Expand Up @@ -390,9 +390,9 @@ GEM
ranked-model (0.4.9)
activerecord (>= 5.2)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
rb-inotify (0.11.1)
ffi (~> 1.0)
rdoc (6.6.3.1)
rdoc (6.7.0)
psych (>= 4.0.0)
react-rails (3.2.1)
babel-transpiler (>= 0.7.0)
Expand All @@ -402,7 +402,7 @@ GEM
tilt
redis (5.2.0)
redis-client (>= 0.22.0)
redis-client (0.22.1)
redis-client (0.22.2)
connection_pool
regexp_parser (2.9.2)
reline (0.5.7)
Expand Down Expand Up @@ -435,7 +435,7 @@ GEM
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.63.5)
rubocop (1.64.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand Down Expand Up @@ -467,9 +467,9 @@ GEM
rubocop-rspec_rails (~> 2.28)
rubocop-rspec_rails (2.28.3)
rubocop (~> 1.40)
ruby-lsp (0.16.6)
ruby-lsp (0.16.7)
language_server-protocol (~> 3.17.0)
prism (>= 0.23.0, < 0.28)
prism (>= 0.29.0, < 0.30)
sorbet-runtime (>= 0.5.10782)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
Expand All @@ -493,8 +493,7 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
simpleidn (0.2.2)
unf (~> 0.1.4)
simpleidn (0.2.3)
singleton (0.2.0)
slim (5.2.1)
temple (~> 0.10.0)
Expand All @@ -503,7 +502,7 @@ GEM
actionpack (>= 3.1)
railties (>= 3.1)
slim (>= 3.0, < 6.0, != 5.0.0)
sorbet-runtime (0.5.11383)
sorbet-runtime (0.5.11391)
squasher (0.8.0)
statesman (12.1.0)
statsd-ruby (1.5.0)
Expand All @@ -522,9 +521,6 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unaccent (0.4.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.9.1)
unicode-display_width (2.5.0)
uri (0.13.0)
vite_rails (3.0.17)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
V24.4.3
V24.5.1
2 changes: 1 addition & 1 deletion app/controllers/public/calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index

def private_ical_feed
organisation_user = current_organisation_user.present? ||
current_organisation.users.find_by(token: params[:token])
current_organisation.organisation_users.find_by(token: params[:token])

raise CanCan::AccessDenied if organisation_user.blank?

Expand Down
2 changes: 1 addition & 1 deletion app/domain/booking_actions/manage/email_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EmailContract < BookingActions::Base
def invoke!
mail = MailTemplate.use!(:awaiting_contract_notification, booking, to: :tenant, booking:, contract:,
invoices: deposits)
mail.attach :contract, :contract_documents, deposits
mail.attach :contract, deposits
mail.save! && contract.sent! && deposits.each(&:sent!)

Result.success redirect_proc: mail&.autodeliver_with_redirect_proc
Expand Down
1 change: 0 additions & 1 deletion app/domain/booking_states/definitive_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def self.to_sym
OperatorResponsibility.assign(booking, :home_handover, :home_return)
MailTemplate.use(:manage_definitive_request_notification, booking, to: :administration, &: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

Expand Down
1 change: 0 additions & 1 deletion app/domain/booking_states/provisional_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def self.to_sym
next if booking.committed_request

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

Expand Down
2 changes: 1 addition & 1 deletion app/domain/booking_states/upcoming_soon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.to_sym
booking.occupied! if occupied_occupancy_state?(booking)
MailTemplate.use(:operator_upcoming_soon_notification, booking, to: :home_handover, &:autodeliver!)
MailTemplate.use(:operator_upcoming_soon_notification, booking, to: :home_return, &:autodeliver!)
MailTemplate.use(:upcoming_soon_notification, booking, to: :tenant, attach: :last_info_documents, &:autodeliver!)
MailTemplate.use(:upcoming_soon_notification, booking, to: :tenant, &:autodeliver!)
end

infer_transition(to: :active) do |booking|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function splitSlots(date: Date, occupancies: Set<Occupancy>) {
// const beginsBeforeDayStart = isBefore(beginsAt, dayStart);
const beginsBeforeDayMid = isBefore(beginsAt, dayMid);
// const beginsAfterDayStart = isAfter(beginsAt, dayStart);
const beginsAfterDayMid = isAfter(beginsAt, dayMid);
// const beginsAfterDayMid = isAfter(beginsAt, dayMid);

const endsAfterDayStart = isAfter(endsAt, dayStart);
const endsAfterDayMid = isAfter(endsAt, dayMid);
Expand All @@ -85,9 +85,7 @@ function splitSlots(date: Date, occupancies: Set<Occupancy>) {

if (beginsBeforeDayMid && endsAfterDayMid) return slots.allday.add(occupancy);
if (beginsBeforeDayMid && endsAfterDayStart) return slots.forenoon.add(occupancy);
if (beginsAfterDayMid && endsAfterDayMid) return slots.afternoon.add(occupancy);

debugger;
if (!beginsBeforeDayMid && endsAfterDayMid) return slots.afternoon.add(occupancy);
});

return slots;
Expand Down
3 changes: 1 addition & 2 deletions app/models/contract/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def template_context(contract)
booking = contract.booking
TemplateContext.new(
booking:, organisation: booking.organisation, contract:,
costs: CostEstimation.new(booking),
tarifs_table_placeholder: Export::Pdf::ContractPdf::TARIFS_TABLE_PLACEHOLDER
costs: CostEstimation.new(booking)
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/data_digest_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def columns_config=(value)
value = JSON.parse(value) if value.is_a?(String)
value = Array.wrap(value)
value = nil if value == self.class::DEFAULT_COLUMN_CONFIG
super(value)
super
end

def eject_columns_config
Expand Down
2 changes: 2 additions & 0 deletions app/models/designated_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
class DesignatedDocument < ApplicationRecord
belongs_to :organisation, inverse_of: :designated_documents

has_many :mail_template_designated_documents, dependent: :destroy
has_many :mail_templates, through: :mail_template_designated_documents
has_many :attaching_conditions, -> { qualifiable_group(:attaching) }, as: :qualifiable, dependent: :destroy,
class_name: :BookingCondition, inverse_of: false

Expand Down
5 changes: 4 additions & 1 deletion app/models/mail_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
#

class MailTemplate < RichTextTemplate
has_many :mail_template_designated_documents, dependent: :destroy
has_many :designated_documents, through: :mail_template_designated_documents

def use(booking, to: nil, attach: nil, **context, &callback)
return nil unless enabled

booking&.notifications&.build(to:) do |notification|
notification.apply_template(self, context: context.merge(booking:, organisation: booking.organisation))
notification.destroy && return unless notification.deliverable?

notification.attach(attach)
notification.attach(designated_documents.for_booking(booking))
notification.tap(&callback) if callback.present?
end
end
Expand Down
23 changes: 23 additions & 0 deletions app/models/mail_template_designated_document.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: mail_template_designated_documents
#
# designated_document_id :bigint
# mail_template_id :bigint
#
# Indexes
#
# idx_on_designated_document_id_590865e4e7 (designated_document_id)
# index_mail_template_designated_documents_on_mail_template_id (mail_template_id)
#
# Foreign Keys
#
# fk_rails_... (designated_document_id => designated_documents.id)
# fk_rails_... (mail_template_id => rich_text_templates.id)
#
class MailTemplateDesignatedDocument < ApplicationRecord
belongs_to :mail_template
belongs_to :designated_document
end
2 changes: 1 addition & 1 deletion app/models/occupancy_calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OccupancyCalendar
attribute :window_to

def initialize(attributes)
super(attributes)
super
self.window_to ||= organisation.settings.booking_window.from_now
end

Expand Down
8 changes: 8 additions & 0 deletions app/models/rich_text_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,12 @@ def use(**context)

interpolate(context)
end

def replace_in_body(search, replace = '')
body_i18n.transform_values! { _1.gsub(search, replace) }
end

def replace_in_title(search, replace = '')
title_i18n.transform_values! { _1.gsub(search, replace) }
end
end
2 changes: 1 addition & 1 deletion app/params/manage/rich_text_template_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Manage
class RichTextTemplateParams < ApplicationParams
def self.permitted_keys
%i[key enabled autodeliver] +
%i[key enabled autodeliver] + [{ designated_document_ids: [] }] +
I18n.available_locales.map { |locale| ["title_#{locale}", "body_#{locale}"] }.flatten
end

Expand Down
2 changes: 1 addition & 1 deletion app/serializers/manage/tarif_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Manage
class TarifSerializer < ApplicationSerializer
fields :label, :pin, :prefill_usage_method, :price_per_unit, :tarif_group, :type, :unit, :ordinal,
:label_i18n, :unit_i18n, :valid_from, :valid_until
:label_i18n, :unit_i18n, :valid_from, :valid_until, :accountancy_account

field :associated_types do |tarif|
tarif.associated_types.to_a
Expand Down
7 changes: 2 additions & 5 deletions app/services/attachment_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ class AttachmentManager
unsent_invoices: ->(booking) { booking.invoices.invoice.unsent },
unsent_late_notices: ->(booking) { booking.invoices.late_notice.unsent },
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) },
accepted_documents: ->(booking) { DesignatedDocument.for_booking(booking).where(send_with_accepted: true) }
contract: ->(booking) { booking.contract }
}.freeze

def initialize(booking, target:)
Expand All @@ -18,7 +15,7 @@ def initialize(booking, target:)
end

def attach_all(*attachables)
attachables.flatten.map { |it| attach_one(it) }
attachables.flatten.map { attach_one(_1) }
end

def attach_one(attachable)
Expand Down
9 changes: 8 additions & 1 deletion app/services/export/pdf/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ def self.render_queue
end

def render(renderable)
renderable.render_into(document) if renderable.is_a?(Renderable)
case renderable
when Export::Pdf::Renderable
renderable.render_into(document)
when Proc
instance_exec(&renderable)
else
raise ArgumentError
end
end

def render_document
Expand Down
9 changes: 2 additions & 7 deletions app/services/export/pdf/contract_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
module Export
module Pdf
class ContractPdf < Base
TARIFS_TABLE_PLACEHOLDER = '{{ tarifs_table_placeholder }}'

def initialize(contract)
super()
@contract = contract
Expand All @@ -21,11 +19,8 @@ def initialize(contract)
end

to_render do
text_parts = @contract.text&.split(TARIFS_TABLE_PLACEHOLDER) || []
text_parts.each_with_index do |text_part, index|
render Renderables::RichText.new(text_part)
render_tarifs_table unless index == text_parts.size - 1
end
special_tokens = { TARIFS: -> { render_tarifs_table } }
Renderables::RichText.split(@contract.text, special_tokens).each { render _1 }
end

to_render do
Expand Down
Loading

0 comments on commit d5d621f

Please sign in to comment.