From 9e5e2de5d50c7b8eebbb73ac348d4990d9eab767 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 25 May 2023 23:41:56 +0530 Subject: [PATCH 1/2] fix: incorrect available quantity in BIN --- erpnext/stock/stock_ledger.py | 15 +++++++++++++-- erpnext/stock/utils.py | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 6106809273..9f81a8cd3f 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -443,12 +443,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() @@ -1065,6 +1064,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) + frappe.db.set_value( + "Bin", + bin_name, + { + "actual_qty": sle.qty_after_transaction, + "valuation_rate": sle.valuation_rate, + "stock_value": sle.stock_value, + }, + ) + def update_bin(self): # update bin for each warehouse for warehouse, data in self.data.items(): diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 10654ddc21..ba36983150 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -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) From 718ad3f24048b5acb32655a31a4965866cb429b0 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 26 May 2023 11:29:22 +0530 Subject: [PATCH 2/2] fix: travis --- erpnext/stock/stock_ledger.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 9f81a8cd3f..2f64eddb30 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -1066,15 +1066,15 @@ class update_entries_after(object): def update_bin_data(self, sle): bin_name = get_or_make_bin(sle.item_code, sle.warehouse) - frappe.db.set_value( - "Bin", - bin_name, - { - "actual_qty": sle.qty_after_transaction, - "valuation_rate": sle.valuation_rate, - "stock_value": sle.stock_value, - }, - ) + 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