mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-17 11:44:27 +00:00
perf: reposting for backdated transactions
(cherry picked from commit1b0fc0541b) (cherry picked from commit3d51c1b363)
This commit is contained in:
committed by
Mergify
parent
825ef415ef
commit
f3da431f1f
@@ -489,32 +489,16 @@ class update_entries_after:
|
|||||||
self.distinct_item_warehouses[key] = val
|
self.distinct_item_warehouses[key] = val
|
||||||
self.new_items_found = True
|
self.new_items_found = True
|
||||||
else:
|
else:
|
||||||
# Check if the dependent voucher is reposted
|
existing_sle = self.distinct_item_warehouses[key].get("sle", {})
|
||||||
# If not, then do not add it to the list
|
if getdate(existing_sle.get("posting_date")) > getdate(dependant_sle.posting_date):
|
||||||
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
|
|
||||||
self.distinct_item_warehouses[key] = val
|
self.distinct_item_warehouses[key] = val
|
||||||
self.new_items_found = True
|
self.new_items_found = True
|
||||||
elif dependant_sle.voucher_detail_no not in set(dependent_voucher_detail_nos):
|
elif dependant_sle.voucher_type == "Stock Entry" and is_transfer_stock_entry(
|
||||||
# Future dependent voucher needs to be repost to get the correct stock value
|
dependant_sle.voucher_no
|
||||||
# If dependent voucher has not reposted, then add it to the list
|
):
|
||||||
dependent_voucher_detail_nos.append(dependant_sle.voucher_detail_no)
|
print(dependant_sle.voucher_no)
|
||||||
self.new_items_found = True
|
|
||||||
val.dependent_voucher_detail_nos = dependent_voucher_detail_nos
|
|
||||||
self.distinct_item_warehouses[key] = val
|
self.distinct_item_warehouses[key] = val
|
||||||
|
self.new_items_found = True
|
||||||
|
|
||||||
def is_dependent_voucher_reposted(self, dependant_sle) -> bool:
|
def is_dependent_voucher_reposted(self, dependant_sle) -> bool:
|
||||||
# Return False if the dependent voucher is not reposted
|
# Return False if the dependent voucher is not reposted
|
||||||
@@ -1403,6 +1387,8 @@ def get_sle_by_voucher_detail_no(voucher_detail_no, excluded_sle=None):
|
|||||||
"posting_time",
|
"posting_time",
|
||||||
"voucher_detail_no",
|
"voucher_detail_no",
|
||||||
"posting_datetime as timestamp",
|
"posting_datetime as timestamp",
|
||||||
|
"voucher_type",
|
||||||
|
"voucher_no",
|
||||||
],
|
],
|
||||||
as_dict=1,
|
as_dict=1,
|
||||||
)
|
)
|
||||||
@@ -1830,3 +1816,10 @@ def get_stock_value_difference(item_code, warehouse, posting_date, posting_time,
|
|||||||
|
|
||||||
difference_amount = query.run()
|
difference_amount = query.run()
|
||||||
return flt(difference_amount[0][0]) if difference_amount else 0
|
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"]
|
||||||
|
|||||||
Reference in New Issue
Block a user