Created
February 27, 2019 21:08
-
-
Save mabsboza/8f8396ebd3663dcb94fc2c86f49ab305 to your computer and use it in GitHub Desktop.
update stock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
old_stock = Inventory::StockByWarehouse.where(master_data_item: master_data_item) | |
.where(' warehouse_id in (?)', warehouses_ids) | |
.select('sum(physical_quantity) as physical_quantity, | |
sum(reserved_quantity) as reserved_quantity') | |
old_total = old_stock[0].physical_quantity.nil? ? 0 : (old_stock[0].physical_quantity * master_data_item.unit_cost) | |
buy = (transaction_cost * quantity) | |
new_cost = 0 | |
if old_stock[0].physical_quantity != 0 | |
new_cost = (buy + old_total) / ( | |
(old_stock[0].physical_quantity.nil? ? 0 : old_stock[0].physical_quantity) + quantity) | |
else | |
new_cost = transaction_cost | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment