mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
add order item id to product stock movement for sold
This commit is contained in:
parent
97ee15cf78
commit
8059512f19
@ -20,7 +20,7 @@ module Payments::PaymentConcern
|
||||
WalletService.debit_user_wallet(order, order.statistic_profile.user)
|
||||
order.update(state: 'in_progress', payment_state: 'paid')
|
||||
order.order_items.each do |item|
|
||||
ProductService.update_stock(item.orderable, 'external', 'sold', -item.quantity)
|
||||
ProductService.update_stock(item.orderable, 'external', 'sold', -item.quantity, item.id)
|
||||
end
|
||||
order.reload
|
||||
end
|
||||
|
@ -23,10 +23,11 @@ class ProductService
|
||||
nil
|
||||
end
|
||||
|
||||
def self.update_stock(product, stock_type, reason, quantity)
|
||||
def self.update_stock(product, stock_type, reason, quantity, order_item_id)
|
||||
remaining_stock = product.stock[stock_type] + quantity
|
||||
product.product_stock_movements.create(stock_type: stock_type, reason: reason, quantity: quantity, remaining_stock: remaining_stock,
|
||||
date: DateTime.current)
|
||||
date: DateTime.current,
|
||||
order_item_id: order_item_id)
|
||||
product.stock[stock_type] = remaining_stock
|
||||
product.save
|
||||
end
|
||||
|
@ -0,0 +1,5 @@
|
||||
class AddOrderItemIdToProductStockMovement < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :product_stock_movements, :order_item_id, :integer
|
||||
end
|
||||
end
|
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_08_26_074619) do
|
||||
ActiveRecord::Schema.define(version: 2022_08_26_085923) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "fuzzystrmatch"
|
||||
@ -632,6 +632,7 @@ ActiveRecord::Schema.define(version: 2022_08_26_074619) do
|
||||
t.datetime "date"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "order_item_id"
|
||||
t.index ["product_id"], name: "index_product_stock_movements_on_product_id"
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user