From f82c2af244db56f6bc986d1b671e8bc89b49a22f Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 9 Jun 2022 13:18:00 +0200 Subject: [PATCH] Improve inventory stock saving with comment [SCI-6805] --- app/models/repository_stock_value.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/repository_stock_value.rb b/app/models/repository_stock_value.rb index 9b9c1d59c..05c8ed907 100644 --- a/app/models/repository_stock_value.rb +++ b/app/models/repository_stock_value.rb @@ -4,7 +4,7 @@ class RepositoryStockValue < ApplicationRecord include RepositoryValueWithReminders include ActionView::Helpers::NumberHelper - attr_accessor :comment + attribute :comment, :text belongs_to :repository_stock_unit_item, optional: true belongs_to :created_by, class_name: 'User', optional: true, inverse_of: :created_repository_stock_values @@ -112,12 +112,13 @@ class RepositoryStockValue < ApplicationRecord .find(new_data[:unit_item_id]) self.last_modified_by = user delta = new_data[:amount].to_d - amount.to_d + self.comment = new_data[:comment].presence repository_ledger_records.create!( user: last_modified_by, amount: delta, balance: amount, reference: repository_cell.repository_column.repository, - comment: new_data[:comment].presence + comment: comment ) self.amount = BigDecimal(new_data[:amount].to_s) save!