diff --git a/app/jobs/bill_line_items_job.rb b/app/jobs/bill_line_items_job.rb index 9f58b8c..f096955 100644 --- a/app/jobs/bill_line_items_job.rb +++ b/app/jobs/bill_line_items_job.rb @@ -40,8 +40,9 @@ class BillLineItemsJob < ActiveJob::Base private # Creates the QuickBooks estimate with redmine_qbo's estimate writer, which writes every estimate: a first line - # saying where the lines came from, then the unbilled line items. The VIN and mileage are the work order's, - # from redmine_qbo's issue values hook (redmine_qbo_vehicles gives the VIN, the Mileage field the mileage). + # saying where the lines came from, then the unbilled line items. Its QuickBooks custom fields get what other + # plugins give for the work order through redmine_qbo's issue values hook (e.g. redmine_qbo_vehicles: VIN + # and mileage). def create_estimate(issue, unbilled_entries) log "Creating estimate in QBO for #{issue.customer.name} from issue ##{issue.id}" memo = "Added from: #{issue.tracker} ##{issue.id}: #{issue.subject}" @@ -58,10 +59,12 @@ class BillLineItemsJob < ActiveJob::Base } end - values = RedmineQboBilling::IssueValues.values_for([issue]) + # { field_id => { issue_id => value } } -> { field_id => value } for this issue + custom_fields = RedmineQboBilling::IssueValues.values_for([issue]) + .transform_values { |by_issue| by_issue[issue.id.to_s] } + .reject { |_, value| value.blank? } estimate = RedmineQboBilling::EstimateWriter.create_estimate(customer: issue.customer, lines: lines, private_note: memo, - vin: values.dig(:vin, issue.id.to_s), - mileage: values.dig(:mileage, issue.id.to_s)) + custom_fields: custom_fields) log "Created estimate ##{estimate.doc_number}" end