* refactor: DB independent quoting and truthy/falsy values
* style: reformat to black spec
* fix: ifnull -> coalesce
* fix: coalesce -> Coalesce
* fix: revert pypika comparison
* refactor: convert queries to QB
* fix: incorrect value types for query
`=` query makes no sense with list of values
* fix: remove warehouse docstatus condition
* fix: keep using base rate as rate
Co-authored-by: Ankush Menat <ankush@frappe.io>
If stock voucher count goes >1000 then fetching all gles and reposting
them all at once requires much more memory and can cause crash.
- This PR ensures that GLE reposting is done in chunks of 100 vouchers.
- This PR also starts keeping track of how many such chunks were
processed so in future progress is resumed in event of timeout.
If you have a huge list of docs to repost then maintaining transaction
throughtout entire GL reposting is not only unnecessary but also creates
performance issues. Periodically commiting the changes prevents lost
progress and reduces memory usage.
In Sales/Purchase invoices credit/debit are flipped and negated while making GLE,
this is unflipped while posting them but if we compare the flipped ones
it will always result in comparison failure and repost it.
- It runs after repost (after commiting), so it has 0 impact on repost itself
- Just that scheduled job log shows up as failed, while actually repost is done and repost document is "Completed"
- The check is inaccurate also, so best to remove this
- Users cant do anything about it anyway. This just piles up phantom failed jobs unneccessarily
* perf: only validate if voucher is journal entry
* perf: optimize merge GLE
- Order fields such that comparison will fail faster
- Break out of loops if not matched
* perf: don't try to match SLE if count mismatch
* refactor: simplify initialize_previous_data
* perf: use cache for fetching valuation_method
These are set only once fields
* refactor: simplify get_future_stock_vouchers
* refactor: simplify get_voucherwise_gl_entries
* perf: fetch only required fields for GL comparison
`select *` fetches all fields, output of this function is only used for
comparing.
* perf: reorder conditions in PL cost center check
* perf: reduce query while validating new gle
* perf: use cache for validating warehouse props
These properties don't change often, no need to query everytime.
* perf: use cached stock settings to validate SLE
* docs: update misleading docstring
Co-authored-by: Marica <maricadsouza221197@gmail.com>