fix: assign uuid after Invoice.new to avoid mass-assignment restriction
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:
parent
c7fe108ecf
commit
a34b8cd33d
1 changed files with 3 additions and 2 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue