mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
Fill the VIN on new estimates and invoices through a hook
New hook qbo_billing_default_vin, { customer:, issues: }: a blank estimate or invoice starts with the VIN
a plugin gives for the customer, and an invoice made from an estimate without a VIN gets the one for the
estimate's work orders. The editor only filled the VIN when the customer was changed or work orders were
imported, so pages opened with the customer already set started blank.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
4 files changed
+21
-1
No files matched your search
@@ -43,6 +43,20 @@ module RedmineQboBilling
|
||||
[]
|
||||
end
|
||||
|
||||
# The VIN a new estimate or invoice starts with, from plugins answering
|
||||
# :qbo_billing_default_vin, { customer:, issues: } => a VIN or nil (e.g. redmine_qbo_vehicles: the work
|
||||
# orders' vehicle when they share one, else the customer's only vehicle)
|
||||
# issues are the work orders behind the document (e.g. the issues linked to the estimate it's made from).
|
||||
def self.default_vin(customer, issues: [])
|
||||
return nil unless customer
|
||||
|
||||
Redmine::Hook.call_hook(:qbo_billing_default_vin, { customer: customer, issues: Array(issues) })
|
||||
.flatten.compact.map { |vin| vin.to_s.strip }.reject(&:empty?).first
|
||||
rescue StandardError => e
|
||||
Rails.logger.warn "[RedmineQboBilling] Default VIN failed: #{e.message}"
|
||||
nil
|
||||
end
|
||||
|
||||
# True when the user may write estimates
|
||||
def self.writer?(user = User.current)
|
||||
user.allowed_to?(:write_estimates, nil, global: true)
|
||||
|
||||
Reference in new issue
Block a user