* refactor: repost error handling (cherry picked from commitafc5a55a23) * test: dependent GL entry reposting (cherry picked from commita2af2daca7) # Conflicts: # erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py * fix: dependent GLE reposting (cherry picked from commitecdb49314f) # Conflicts: # erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json # erpnext/stock/stock_ledger.py * test: repost queue progress (cherry picked from commit8f519545b0) * test: use disposable item codes in tests dependency causes flake (cherry picked from commitd2882ea436) * fix: correct sorting while updating bin (cherry picked from commitb24920c0e9) # Conflicts: # erpnext/stock/doctype/bin/bin.py * fix: sort stock vouchers before reposting GLE (cherry picked from commit700e864d90) * test: discard local future SLE cache between tests (cherry picked from commit9734329094) * chore: conflicts Co-authored-by: Ankush Menat <ankush@frappe.io>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
from json import loads
|
||||
from typing import List, Tuple
|
||||
|
||||
import frappe
|
||||
import frappe.defaults
|
||||
@@ -1123,6 +1124,9 @@ def update_gl_entries_after(
|
||||
def repost_gle_for_stock_vouchers(
|
||||
stock_vouchers, posting_date, company=None, warehouse_account=None
|
||||
):
|
||||
if not stock_vouchers:
|
||||
return
|
||||
|
||||
def _delete_gl_entries(voucher_type, voucher_no):
|
||||
frappe.db.sql(
|
||||
"""delete from `tabGL Entry`
|
||||
@@ -1130,6 +1134,8 @@ def repost_gle_for_stock_vouchers(
|
||||
(voucher_type, voucher_no),
|
||||
)
|
||||
|
||||
stock_vouchers = sort_stock_vouchers_by_posting_date(stock_vouchers)
|
||||
|
||||
if not warehouse_account:
|
||||
warehouse_account = get_warehouse_account_map(company)
|
||||
|
||||
@@ -1150,6 +1156,27 @@ def repost_gle_for_stock_vouchers(
|
||||
_delete_gl_entries(voucher_type, voucher_no)
|
||||
|
||||
|
||||
def sort_stock_vouchers_by_posting_date(
|
||||
stock_vouchers: List[Tuple[str, str]]
|
||||
) -> List[Tuple[str, str]]:
|
||||
sle = frappe.qb.DocType("Stock Ledger Entry")
|
||||
voucher_nos = [v[1] for v in stock_vouchers]
|
||||
|
||||
sles = (
|
||||
frappe.qb.from_(sle)
|
||||
.select(sle.voucher_type, sle.voucher_no, sle.posting_date, sle.posting_time, sle.creation)
|
||||
.where((sle.is_cancelled == 0) & (sle.voucher_no.isin(voucher_nos)))
|
||||
.groupby(sle.voucher_type, sle.voucher_no)
|
||||
).run(as_dict=True)
|
||||
sorted_vouchers = [(sle.voucher_type, sle.voucher_no) for sle in sles]
|
||||
|
||||
unknown_vouchers = set(stock_vouchers) - set(sorted_vouchers)
|
||||
if unknown_vouchers:
|
||||
sorted_vouchers.extend(unknown_vouchers)
|
||||
|
||||
return sorted_vouchers
|
||||
|
||||
|
||||
def get_future_stock_vouchers(
|
||||
posting_date, posting_time, for_warehouses=None, for_items=None, company=None
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user