Merge pull request #35426 from rohitwaghchaure/fixed-incorrect-actual-qty-bin

fix: incorrect available quantity in BIN
This commit is contained in:
rohitwaghchaure 2023-05-26 22:47:42 +05:30 committed by GitHub
commit 4099330bf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -447,12 +447,11 @@ class update_entries_after(object):
i += 1
self.process_sle(sle)
self.update_bin_data(sle)
if sle.dependant_sle_voucher_detail_no:
entries_to_fix = self.get_dependent_entries_to_fix(entries_to_fix, sle)
self.update_bin()
if self.exceptions:
self.raise_exceptions()
@ -1075,6 +1074,18 @@ class update_entries_after(object):
else:
raise NegativeStockError(message)
def update_bin_data(self, sle):
bin_name = get_or_make_bin(sle.item_code, sle.warehouse)
values_to_update = {
"actual_qty": sle.qty_after_transaction,
"stock_value": sle.stock_value,
}
if sle.valuation_rate is not None:
values_to_update["valuation_rate"] = sle.valuation_rate
frappe.db.set_value("Bin", bin_name, values_to_update)
def update_bin(self):
# update bin for each warehouse
for warehouse, data in self.data.items():

View File

@ -220,7 +220,7 @@ def get_bin(item_code, warehouse):
def get_or_make_bin(item_code: str, warehouse: str) -> str:
bin_record = frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse})
bin_record = frappe.get_cached_value("Bin", {"item_code": item_code, "warehouse": warehouse})
if not bin_record:
bin_obj = _create_bin(item_code, warehouse)