Record added, changed and removed line items in the issue's history

Line item changes go into the journal of the issue update that made them, shown like
Redmine's own changes (e.g. "Line item Brake pads: 2 × $45.00 added"). They're only
visible to users who may view line items, in the history, emails, PDF, API and webhooks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-03 21:38:02 -05:00
1 parent a34c534bc1
commit 063da99904
6 files changed
+132

No files matched your search

+17
View File
@@ -17,6 +17,23 @@ class LineItem < ApplicationRecord
validates :unit_price, numericality: { greater_than_or_equal_to: 0 }
before_save :total
# The fields whose changes are recorded in the issue's history
JOURNALED_ATTRIBUTES = %w[description quantity unit_price item_id].freeze
# A one-line summary for the issue's history, e.g. "Brake pads: 2 × $45.00".
# With saved: true it describes the line as it is in the database, before any unsaved changes.
def journal_summary(saved: false)
desc, qty, price = %w[description quantity unit_price].map { |a| saved ? attribute_in_database(a) : self[a] }
qty = ActiveSupport::NumberHelper.number_to_rounded(qty.to_d, precision: 4, strip_insignificant_zeros: true)
price = ActiveSupport::NumberHelper.number_to_currency(price.to_d)
"#{desc.to_s.squish}: #{qty} × #{price}"
end
# True when a field shown in the issue's history has an unsaved change
def journaled_changes?
(changed & JOURNALED_ATTRIBUTES).any?
end
private
def total