mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
[bug] subscription refund generate PDF with wrong dates
This commit is contained in:
parent
d0cbe14327
commit
0b3192c3ab
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)}
|
||||
|
||||
|
@ -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
|
||||
|
||||
##
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user