diff --git a/app/jobs/bill_line_items_job.rb b/app/jobs/bill_line_items_job.rb index 7aad48f..f1ec780 100644 --- a/app/jobs/bill_line_items_job.rb +++ b/app/jobs/bill_line_items_job.rb @@ -40,7 +40,8 @@ class BillLineItemsJob < ActiveJob::Base private # Creates the QuickBooks estimate with redmine_qbo_billing, which writes every estimate: a first line - # saying where the lines came from, then the unbilled line items. The VIN comes from the issue's vehicle. + # saying where the lines came from, then the unbilled line items. The VIN and mileage are the work order's, + # from redmine_qbo_billing's issue values hook (redmine_qbo_vehicles gives the VIN, the Mileage field the 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}" @@ -57,9 +58,10 @@ class BillLineItemsJob < ActiveJob::Base } end - vin = issue.respond_to?(:vehicle) ? issue.vehicle&.vin : nil - estimate = RedmineQboBilling::EstimateWriter.create_estimate(customer: issue.customer, lines: lines, - private_note: memo, vin: vin) + values = RedmineQboBilling::IssueValues.values_for([issue]) + 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)) log "Created estimate ##{estimate.doc_number}" end