Created
October 14, 2019 10:34
-
-
Save pythonandchips/a9daac0df5b7abfa18d01653fa32275b to your computer and use it in GitHub Desktop.
Fix stock transaction with incorrect values due to FCB error.
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
def fix_fcb_stock(company) | |
bills = company.bills.in_foreign_currency.where.not(stock_item_id: nil) | |
bills.each do |bill| | |
company.stock_mapper.update_stock_entry(bill, force: true) | |
end | |
stock_transactions = StockTransaction | |
.where(stock_item_id: bills.map(&:stock_item_id)) | |
.where("created_at >= ?", bills.map(&:created_at).min) | |
.where(source_item_type: [BankAccountEntry.name, InvoiceItem.name]) | |
stock_transactions.each do |stock_transaction| | |
company.stock_mapper.update_stock_entry(stock_transaction.source_item, force: true) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment