Skip to content

Commit

Permalink
fix: attach for mail_templates
Browse files Browse the repository at this point in the history
  • Loading branch information
diegosteiner committed Dec 18, 2023
1 parent 6e8e615 commit 5401084
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/models/mail_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
#

class MailTemplate < RichTextTemplate
def use(booking, to: nil, **context, &)
def use(booking, to: nil, attach: nil, **context, &)
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.tap(&) if block_given?
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def delivered?
end

def attach(*attachables)
attachables.flatten.compact.map do |attachable|
attachables.flatten.compact_blank.map do |attachable|
next attachable.attach_to(self) if attachable.respond_to?(:attach_to)
next attach(attachable.blob) if attachable.try(:blob).present?

Expand Down
7 changes: 5 additions & 2 deletions app/services/import/csv/booking_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.supported_headers
end

def default_options
super.merge({ datetime_format: ['%FT%T', '%F %T %z', '%FT%H:%M', '%d.%m.%YT%H:%M'] })
super.merge({ datetime_format: ['%FT%T', '%F %T %z', '%FT%H:%M', '%d.%m.%YT%H:%M', '%m/%d/%Y'] })
end

def initialize(home, **options)
Expand All @@ -41,7 +41,10 @@ def persist_record(booking)
booking.transition_to ||= initial_state
booking.assert_tenant!
booking.ref ||= @booking_ref_service.generate(booking)
booking.save
return false unless booking.save

booking.deadline&.clear
true
end

def skip_row?(row, _index)
Expand Down

0 comments on commit 5401084

Please sign in to comment.