fix: assign uuid after Invoice.new to avoid mass-assignment restriction
All checks were successful
Build and Deploy to Production / build (push) Successful in 47s
Build and Deploy to Production / deploy (push) Successful in 25s

Sequel guards primary keys against mass assignment, so passing uuid: to
Invoice.new raised MassAssignmentRestriction and turned every invoice
creation into a 500. Build the instance with the rest of the fields, then
set uuid as an attribute before returning.
This commit is contained in:
Sergei Poljanski 2026-05-26 18:34:45 +03:00
commit a34b8cd33d
Signed by: asxpi
GPG key ID: 4F8851660FA4121B

View file

@ -49,8 +49,7 @@ class Invoice < Sequel::Model(:invoices)
items = normalize_items(params.fetch(:items)) items = normalize_items(params.fetch(:items))
subtotal = items.sum { |i| BigDecimal(i['qty'].to_s) * BigDecimal(i['unit_price'].to_s) } subtotal = items.sum { |i| BigDecimal(i['qty'].to_s) * BigDecimal(i['unit_price'].to_s) }
Invoice.new( invoice = Invoice.new(
uuid: SecureRandom.uuid,
number: allocate_number, number: allocate_number,
client_name: params.fetch(:client_name).to_s.strip, client_name: params.fetch(:client_name).to_s.strip,
client_email: params.fetch(:client_email).to_s.strip, client_email: params.fetch(:client_email).to_s.strip,
@ -65,6 +64,8 @@ class Invoice < Sequel::Model(:invoices)
pdf_key: '', pdf_key: '',
created_at: Time.now.utc created_at: Time.now.utc
) )
invoice.uuid = SecureRandom.uuid
invoice
end end
private private