Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update time entry status to billed once the invoice is sent to the client #292

Merged

Conversation

murtaza-bagwala
Copy link
Contributor

@murtaza-bagwala murtaza-bagwala commented Apr 19, 2022

Notion card

Summary

https://www.notion.so/saeloun/6afc9500b2cc42af86be55f37894fb09?v=b4528f26f4424af7beaf036262796cb3&p=430921c655ed4421a3187268d6707283

Preview

NA

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Checklist:

  • I have manually tested all workflows
  • I have performed a self-review of my own code
  • I have added automated tests for my code

closes #257

@murtaza-bagwala murtaza-bagwala changed the title update time entry status to billed once the invoice status is sent to the client Update time entry status to billed once the invoice status is sent to the client Apr 19, 2022
@github-actions
Copy link

Current Code Coverage Percent of this PR:

98.17 %

Files having coverage below 100%

Impacted Files Coverage
/app/controllers/clients_controller.rb 38.89 %
/app/controllers/concerns/error_handler.rb 97.73 %
/app/models/project.rb 90.32 %

@murtaza-bagwala murtaza-bagwala changed the title Update time entry status to billed once the invoice status is sent to the client Update time entry status to billed once the invoice is sent to the client Apr 19, 2022
@rohitjoshixyz
Copy link
Contributor

I will review it tomorrow.

Copy link
Contributor

@shivamsinghchahar shivamsinghchahar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@murtaza-bagwala Suggested some changes. We will also need to add unit test for update_timesheet_entry_status!

@@ -47,7 +47,7 @@ def send_invoice
authorize invoice

invoice.send_to_email(subject: invoice_email_params[:subject], recipients: invoice_email_params[:recipients])

invoice.update_timesheet_entry_status
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
invoice.update_timesheet_entry_status
invoice.update_timesheet_entry_status!

@@ -62,4 +62,9 @@ class Invoice < ApplicationRecord
def sub_total
@_sub_total ||= invoice_line_items.sum { |line_item| line_item[:rate] * line_item[:quantity] }
end

def update_timesheet_entry_status
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def update_timesheet_entry_status
def update_timesheet_entry_status!

@@ -62,4 +62,9 @@ class Invoice < ApplicationRecord
def sub_total
@_sub_total ||= invoice_line_items.sum { |line_item| line_item[:rate] * line_item[:quantity] }
end

def update_timesheet_entry_status
timesheet_entry_ids = invoice_line_items.map { |line_item| line_item.timesheet_entry_id }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
timesheet_entry_ids = invoice_line_items.map { |line_item| line_item.timesheet_entry_id }
timesheet_entry_ids = invoice_line_items.pluck(:timesheet_entry_id)


def update_timesheet_entry_status
timesheet_entry_ids = invoice_line_items.map { |line_item| line_item.timesheet_entry_id }
TimesheetEntry.where(id: timesheet_entry_ids).update(bill_status: :billed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TimesheetEntry.where(id: timesheet_entry_ids).update(bill_status: :billed)
TimesheetEntry.where(id: timesheet_entry_ids).each(&:billed!)

Copy link
Contributor

@rohitjoshixyz rohitjoshixyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after addressing changes suggested by Shivam

@shivamsinghchahar shivamsinghchahar merged commit ff3a78a into develop Apr 20, 2022
@shivamsinghchahar shivamsinghchahar deleted the update-time-entry-status-once-the-invoice-is-sent branch April 20, 2022 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the billable status of time tracking entries once they are added to invoice and sent to client
3 participants