diff --git a/CHANGELOG.md b/CHANGELOG.md index ebab35cd0..fd0d76628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## next release +- Updated Portuguese translations (#91) +- Added Spanish translations (#87) +- Added Central Africa & Cameroon currency symbol (#90) +- Fix nginx configuration to allow initial Let's Encrypt configuration (#92) +- Events: open api and monitor improvement (#79) +- Fix a bug: refund an invoice with a subscription and disabling it a the same time cause the resulting PDF to display the wrong dates - Fixed deploy instructions with docker-compose ## v2.6.0 2017 November 13 diff --git a/app/controllers/api/invoices_controller.rb b/app/controllers/api/invoices_controller.rb index 2a0712d2e..fb473d0c9 100644 --- a/app/controllers/api/invoices_controller.rb +++ b/app/controllers/api/invoices_controller.rb @@ -63,6 +63,11 @@ class API::InvoicesController < API::ApiController invoice = Invoice.only_invoice.find(avoir_params[:invoice_id]) @avoir = invoice.build_avoir(avoir_params) if @avoir.save + # when saved, expire the subscription if needed + if @avoir.subscription_to_expire + @avoir.expire_subscription + end + # then answer the API call render :avoir, status: :created else render json: @avoir.errors, status: :unprocessable_entity diff --git a/app/models/avoir.rb b/app/models/avoir.rb index 212c0627e..3150c33f5 100644 --- a/app/models/avoir.rb +++ b/app/models/avoir.rb @@ -1,6 +1,5 @@ class Avoir < Invoice belongs_to :invoice - after_create :expire_subscription, if: :subscription_to_expire validates :avoir_mode, :inclusion => {:in => %w(stripe cheque transfer none cash wallet)} diff --git a/app/models/invoice.rb b/app/models/invoice.rb index dbd1e2390..5c3a5f263 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -212,7 +212,7 @@ class Invoice < ActiveRecord::Base unless Rails.env.test? puts "Creating an InvoiceWorker job to generate the following invoice: id(#{id}), invoiced_id(#{invoiced_id}), invoiced_type(#{invoiced_type}), user_id(#{user_id})" end - InvoiceWorker.perform_async(id) + InvoiceWorker.perform_async(id, user&.subscription&.expired_at) end ## diff --git a/app/pdfs/pdf/invoice.rb b/app/pdfs/pdf/invoice.rb index 62ed372db..b198e2cc3 100644 --- a/app/pdfs/pdf/invoice.rb +++ b/app/pdfs/pdf/invoice.rb @@ -5,7 +5,7 @@ module PDF include ActionView::Helpers::NumberHelper include ApplicationHelper - def initialize(invoice) + def initialize(invoice, subscription_expiration_date) super(:margin => 70) # fonts @@ -118,8 +118,9 @@ module PDF if invoice.invoiced_type == 'OfferDay' details += I18n.t('invoices.subscription_extended_for_free_from_START_to_END', START:I18n.l(invoice.invoiced.start_at.to_date), END:I18n.l(invoice.invoiced.end_at.to_date)) else - subscription_start_at = subscription.expired_at - subscription.plan.duration - details += I18n.t('invoices.subscription_NAME_from_START_to_END', NAME:item.description, START:I18n.l(subscription_start_at.to_date), END:I18n.l(subscription.expired_at.to_date)) + subscription_end_at = DateTime.parse(subscription_expiration_date) + subscription_start_at = subscription_end_at - subscription.plan.duration + details += I18n.t('invoices.subscription_NAME_from_START_to_END', NAME:item.description, START:I18n.l(subscription_start_at.to_date), END:I18n.l(subscription_expiration_date.to_date)) end diff --git a/app/workers/invoice_worker.rb b/app/workers/invoice_worker.rb index fa8c7ce23..7bf6ac310 100644 --- a/app/workers/invoice_worker.rb +++ b/app/workers/invoice_worker.rb @@ -1,10 +1,10 @@ class InvoiceWorker include Sidekiq::Worker - def perform(invoice_id) + def perform(invoice_id, subscription_expiration_date) # generate a invoice invoice = Invoice.find invoice_id - pdf = ::PDF::Invoice.new(invoice).render + pdf = ::PDF::Invoice.new(invoice, subscription_expiration_date).render # store invoice on drive File.binwrite(invoice.file, pdf)