Skip to content

Commit 2b1a7e8

Browse files
authored
Utilize update instead of increment/decrement to trigger paper_trail (#2477)
1 parent 9d3e1f4 commit 2b1a7e8

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

app/models/storage_location.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ def increase_inventory(itemizable_array)
129129
# Locate the storage box for the item, or create a new storage box for it
130130
inventory_item = inventory_items.find_or_create_by!(item_id: item_hash[:item_id])
131131
# Increase the quantity-on-record for that item
132-
inventory_item.increment!(:quantity, item_hash[:quantity].to_i)
132+
new_quantity = inventory_item.quantity + item_hash[:quantity].to_i
133+
inventory_item.update!(quantity: new_quantity)
133134
# Record in the log that this has occurred
134135
log[item_hash[:item_id]] = "+#{item_hash[:quantity]}"
135136
end
@@ -181,7 +182,8 @@ def decrease_inventory(itemizable_array)
181182
# captured by the previous block.
182183
inventory_item = inventory_items.find_by(item_id: item_hash[:item_id])
183184
# Reduce the inventory box quantity
184-
inventory_item.decrement!(:quantity, item_hash[:quantity])
185+
new_quantity = inventory_item.quantity - item_hash[:quantity]
186+
inventory_item.update(quantity: new_quantity)
185187
# Record in the log that this has occurred
186188
log[item_hash[:item_id]] = "-#{item_hash[:quantity]}"
187189
end

0 commit comments

Comments
 (0)