Skip to content

Instantly share code, notes, and snippets.

@pythonandchips
Created October 14, 2019 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pythonandchips/a9daac0df5b7abfa18d01653fa32275b to your computer and use it in GitHub Desktop.
Save pythonandchips/a9daac0df5b7abfa18d01653fa32275b to your computer and use it in GitHub Desktop.
Fix stock transaction with incorrect values due to FCB error.
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