diff --git a/app/controllers/registrar/invoices_controller.rb b/app/controllers/registrar/invoices_controller.rb index 8d0a06831..3d8de5048 100644 --- a/app/controllers/registrar/invoices_controller.rb +++ b/app/controllers/registrar/invoices_controller.rb @@ -22,26 +22,24 @@ class Registrar::InvoicesController < RegistrarController @invoice.billing_email = params[:invoice][:billing_email] if @invoice.forward(render_to_string('pdf', layout: false)) - flash[:notice] = t('invoice_forwared') + flash[:notice] = t(:invoice_forwared) redirect_to([:registrar, @invoice]) else - flash.now[:alert] = t('failed_to_forward_invoice') + flash.now[:alert] = t(:failed_to_forward_invoice) end end def cancel if @invoice.cancel - flash[:notice] = t('record_updated') + flash[:notice] = t(:record_updated) redirect_to([:registrar, @invoice]) else - flash.now[:alert] = t('failed_to_update_record') + flash.now[:alert] = t(:failed_to_update_record) render :show end end def download_pdf - # render 'pdf', layout: false - pdf = @invoice.pdf(render_to_string('pdf', layout: false)) send_data pdf, filename: @invoice.pdf_name end diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 372d67a8c..aa5a8c430 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -34,6 +34,21 @@ class Invoice < ActiveRecord::Base before_save -> { self.sum_cache = sum } + class << self + def cancel_overdue_invoices + logger.info "#{Time.zone.now.utc} - Cancelling overdue invoices\n" + + cr_at = Time.zone.now - Setting.days_to_keep_overdue_invoices_active.days + invoices = Invoice.unbinded.where( + 'due_date < ? AND created_at < ? AND cancelled_at IS NULL', Time.zone.now, cr_at + ) + + count = invoices.update_all(cancelled_at: Time.zone.now) + + logger.info "#{Time.zone.now.utc} - Successfully cancelled #{count} overdue invoices\n" + end + end + def binded? account_activity.present? end @@ -113,19 +128,4 @@ class Invoice < ActiveRecord::Base def sum sum_without_vat + vat end - - class << self - def cancel_overdue_invoices - STDOUT << "#{Time.zone.now.utc} - Cancelling overdue invoices\n" - - cr_at = Time.zone.now - Setting.days_to_keep_overdue_invoices_active.days - invoices = Invoice.unbinded.where( - 'due_date < ? AND created_at < ? AND cancelled_at IS NULL', Time.zone.now, cr_at - ) - - count = invoices.update_all(cancelled_at: Time.zone.now) - - STDOUT << "#{Time.zone.now.utc} - Successfully cancelled #{count} overdue invoices\n" - end - end end diff --git a/app/views/invoice_mailer/invoice_email.text.erb b/app/views/invoice_mailer/invoice_email.text.erb index 2cf1d1197..ae65fd7da 100644 --- a/app/views/invoice_mailer/invoice_email.text.erb +++ b/app/views/invoice_mailer/invoice_email.text.erb @@ -1,5 +1,5 @@ -<%= t('you_have_a_new_invoice') %> +<%= t(:you_have_a_new_invoice) %> -<%= t('sincerely') %>, +<%= t(:sincerely) %>, <%= Setting.eis_invoice_contact %> <%= @invoice.seller_phone %> diff --git a/config/initializers/pdfkit.rb b/config/initializers/pdfkit.rb index 6c9559d98..b38887c6e 100644 --- a/config/initializers/pdfkit.rb +++ b/config/initializers/pdfkit.rb @@ -1,7 +1,8 @@ PDFKit.configure do |config| config.wkhtmltopdf = "#{Rails.root}/vendor/bin/wkhtmltopdf" config.default_options = { - page_size: 'A4' + page_size: 'A4', + quiet: true # :print_media_type => true } end diff --git a/db/schema.rb b/db/schema.rb index 491b5d633..d30dece39 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -297,8 +297,12 @@ ActiveRecord::Schema.define(version: 20150429135339) do t.integer "legacy_id" t.integer "legacy_registrar_id" t.integer "legacy_registrant_id" + t.datetime "outzone_at" + t.datetime "delete_at" end + add_index "domains", ["delete_at"], name: "index_domains_on_delete_at", using: :btree + add_index "domains", ["outzone_at"], name: "index_domains_on_outzone_at", using: :btree add_index "domains", ["registrant_id"], name: "index_domains_on_registrant_id", using: :btree add_index "domains", ["registrar_id"], name: "index_domains_on_registrar_id", using: :btree diff --git a/spec/models/invoice_spec.rb b/spec/models/invoice_spec.rb index 4ec594640..54a640d2d 100644 --- a/spec/models/invoice_spec.rb +++ b/spec/models/invoice_spec.rb @@ -24,9 +24,9 @@ describe Invoice do ]) end - # it 'should not have any versions' do - # @invoice.versions.should == [] - # end + it 'should not have any versions' do + @invoice.versions.should == [] + end end context 'with valid attributes' do @@ -76,14 +76,14 @@ describe Invoice do Invoice.where(cancelled_at: nil).count.should == 1 end - # it 'should have one version' do - # with_versioning do - # @invoice.versions.should == [] - # @invoice.body = 'New body' - # @invoice.save - # @invoice.errors.full_messages.should match_array([]) - # @invoice.versions.size.should == 1 - # end - # end + it 'should have one version' do + with_versioning do + @invoice.versions.should == [] + @invoice.buyer_name = 'New name' + @invoice.save + @invoice.errors.full_messages.should match_array([]) + @invoice.versions.size.should == 1 + end + end end end