diff --git a/app/models/mail_template.rb b/app/models/mail_template.rb index 464815034..61d94d194 100644 --- a/app/models/mail_template.rb +++ b/app/models/mail_template.rb @@ -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 diff --git a/app/models/notification.rb b/app/models/notification.rb index 492d61780..36ac4bbc9 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -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? diff --git a/app/services/import/csv/booking_importer.rb b/app/services/import/csv/booking_importer.rb index ff37aea75..66481d112 100644 --- a/app/services/import/csv/booking_importer.rb +++ b/app/services/import/csv/booking_importer.rb @@ -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) @@ -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)