Skip to content

Commit

Permalink
Mark timesheet entries as billed only when invoice is sent succes…
Browse files Browse the repository at this point in the history
…sfully

- Fix #1853
- Couple of weeks back, invoices stuck in `sending` state due to insufficient memory at sidekiq
- And, we found this issue that timesheet entries were `billed`
- These timesheet entries must be marked as `billed` only when invoice
  is in `sent` state
  • Loading branch information
Nishant Samel committed Jun 10, 2024
1 parent b2c2627 commit 2663f8d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 0 additions & 5 deletions app/controllers/internal_api/v1/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class InternalApi::V1::InvoicesController < InternalApi::V1::ApplicationController
before_action :load_client, only: [:create, :update]
after_action :ensure_time_entries_billed, only: [:send_invoice]
after_action :track_event, only: [:create, :update, :destroy, :send_invoice, :download]

def index
Expand Down Expand Up @@ -122,10 +121,6 @@ def invoice_email_params
params.require(:invoice_email).permit(:subject, :message, recipients: [])
end

def ensure_time_entries_billed
invoice.update_timesheet_entry_status!
end

def track_event
Invoices::EventTrackerService.new(params[:action], @invoice || invoice, params).process
end
Expand Down
9 changes: 8 additions & 1 deletion app/mailers/invoice_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class InvoiceMailer < ApplicationMailer
after_action -> { @invoice.sent! if @invoice.draft? || @invoice.viewed? || @invoice.declined? || @invoice.sending? }
after_action :update_status, only: [:invoice]

def invoice
@invoice = Invoice.find(params[:invoice_id])
Expand Down Expand Up @@ -37,4 +37,11 @@ def company_logo
def can_send_invoice?
@invoice.sending? && @invoice.recently_sent_mail?
end

def update_status
if @invoice.draft? || @invoice.viewed? || @invoice.declined? || @invoice.sending?
@invoice.sent!
@invoice.update_timesheet_entry_status!
end
end
end

0 comments on commit 2663f8d

Please sign in to comment.