perf: reposting for backdated transactions

This commit is contained in:
Rohit Waghchaure
2025-09-25 15:10:57 +05:30
parent 6bd36a137c
commit 1b0fc0541b

View File

@@ -729,32 +729,16 @@ class update_entries_after:
self.distinct_item_warehouses[key] = val
self.new_items_found = True
else:
# Check if the dependent voucher is reposted
# If not, then do not add it to the list
if not self.is_dependent_voucher_reposted(dependant_sle):
return
existing_sle_posting_date = self.distinct_item_warehouses[key].get("sle", {}).get("posting_date")
dependent_voucher_detail_nos = self.get_dependent_voucher_detail_nos(key)
if getdate(dependant_sle.posting_date) < getdate(existing_sle_posting_date):
if dependent_voucher_detail_nos and dependant_sle.voucher_detail_no in set(
dependent_voucher_detail_nos
):
return
val.sle_changed = True
dependent_voucher_detail_nos.append(dependant_sle.voucher_detail_no)
val.dependent_voucher_detail_nos = dependent_voucher_detail_nos
existing_sle = self.distinct_item_warehouses[key].get("sle", {})
if getdate(existing_sle.get("posting_date")) > getdate(dependant_sle.posting_date):
self.distinct_item_warehouses[key] = val
self.new_items_found = True
elif dependant_sle.voucher_detail_no not in set(dependent_voucher_detail_nos):
# Future dependent voucher needs to be repost to get the correct stock value
# If dependent voucher has not reposted, then add it to the list
dependent_voucher_detail_nos.append(dependant_sle.voucher_detail_no)
self.new_items_found = True
val.dependent_voucher_detail_nos = dependent_voucher_detail_nos
elif dependant_sle.voucher_type == "Stock Entry" and is_transfer_stock_entry(
dependant_sle.voucher_no
):
print(dependant_sle.voucher_no)
self.distinct_item_warehouses[key] = val
self.new_items_found = True
def is_dependent_voucher_reposted(self, dependant_sle) -> bool:
# Return False if the dependent voucher is not reposted
@@ -1785,6 +1769,8 @@ def get_sle_by_voucher_detail_no(voucher_detail_no, excluded_sle=None):
"posting_time",
"voucher_detail_no",
"posting_datetime as timestamp",
"voucher_type",
"voucher_no",
],
as_dict=1,
)
@@ -2291,3 +2277,10 @@ def get_stock_value_difference(item_code, warehouse, posting_date, posting_time,
difference_amount = query.run()
return flt(difference_amount[0][0]) if difference_amount else 0
@frappe.request_cache
def is_transfer_stock_entry(voucher_no):
purpose = frappe.get_cached_value("Stock Entry", voucher_no, "purpose")
return purpose in ["Material Transfer", "Material Transfer for Manufacture", "Send to Subcontractor"]