mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-07 23:31:20 +00:00
fix: stock reco with incorrect serial numbers (#42865)
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _, bold, msgprint
|
from frappe import _, bold, msgprint
|
||||||
from frappe.query_builder.functions import CombineDatetime, Sum
|
from frappe.query_builder.functions import CombineDatetime, Sum
|
||||||
from frappe.utils import add_to_date, cint, cstr, flt
|
from frappe.utils import add_to_date, cint, cstr, flt, get_link_to_form
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.accounts.utils import get_company_default
|
from erpnext.accounts.utils import get_company_default
|
||||||
@@ -357,7 +357,6 @@ class StockReconciliation(StockController):
|
|||||||
|
|
||||||
sl_entries.append(args)
|
sl_entries.append(args)
|
||||||
|
|
||||||
qty_after_transaction = 0
|
|
||||||
for serial_no in serial_nos:
|
for serial_no in serial_nos:
|
||||||
args = self.get_sle_for_items(row, [serial_no])
|
args = self.get_sle_for_items(row, [serial_no])
|
||||||
|
|
||||||
@@ -373,27 +372,16 @@ class StockReconciliation(StockController):
|
|||||||
if previous_sle and row.warehouse != previous_sle.get("warehouse"):
|
if previous_sle and row.warehouse != previous_sle.get("warehouse"):
|
||||||
# If serial no exists in different warehouse
|
# If serial no exists in different warehouse
|
||||||
|
|
||||||
warehouse = previous_sle.get("warehouse", "") or row.warehouse
|
frappe.throw(
|
||||||
|
_(
|
||||||
if not qty_after_transaction:
|
"The Serial No {0} already exists in the warehouse {1}. It cannot be transferred to the warehouse {2}"
|
||||||
qty_after_transaction = get_stock_balance(
|
).format(
|
||||||
row.item_code, warehouse, self.posting_date, self.posting_time
|
get_link_to_form("Serial No", serial_no),
|
||||||
|
bold(previous_sle.get("warehouse")),
|
||||||
|
row.warehouse,
|
||||||
)
|
)
|
||||||
|
|
||||||
qty_after_transaction -= 1
|
|
||||||
|
|
||||||
new_args = args.copy()
|
|
||||||
new_args.update(
|
|
||||||
{
|
|
||||||
"actual_qty": -1,
|
|
||||||
"qty_after_transaction": qty_after_transaction,
|
|
||||||
"warehouse": warehouse,
|
|
||||||
"valuation_rate": previous_sle.get("valuation_rate"),
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
sl_entries.append(new_args)
|
|
||||||
|
|
||||||
if row.qty:
|
if row.qty:
|
||||||
args = self.get_sle_for_items(row)
|
args = self.get_sle_for_items(row)
|
||||||
|
|
||||||
|
|||||||
@@ -1119,6 +1119,33 @@ class TestStockReconciliation(FrappeTestCase, StockTestMixin):
|
|||||||
active_serial_no = frappe.get_all("Serial No", filters={"status": "Active", "item_code": item_code})
|
active_serial_no = frappe.get_all("Serial No", filters={"status": "Active", "item_code": item_code})
|
||||||
self.assertEqual(len(active_serial_no), 5)
|
self.assertEqual(len(active_serial_no), 5)
|
||||||
|
|
||||||
|
def test_stock_reco_for_serialized_item_with_different_warehouse(self):
|
||||||
|
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
||||||
|
|
||||||
|
# Add new serial nos
|
||||||
|
serial_item_code = "Stock-Reco-Serial-Item-11"
|
||||||
|
warehouse = "_Test Warehouse - _TC"
|
||||||
|
serial_warehouse = "_Test Warehouse for Stock Reco1 - _TC"
|
||||||
|
|
||||||
|
self.make_item(
|
||||||
|
serial_item_code, {"is_stock_item": 1, "has_serial_no": 1, "serial_no_series": "SNT-SRS11.####"}
|
||||||
|
)
|
||||||
|
|
||||||
|
make_stock_entry(item_code=serial_item_code, target=warehouse, qty=10, basic_rate=100)
|
||||||
|
stock_entry = make_stock_entry(
|
||||||
|
item_code=serial_item_code, target=serial_warehouse, qty=10, basic_rate=200
|
||||||
|
)
|
||||||
|
|
||||||
|
sr = create_stock_reconciliation(
|
||||||
|
item_code=serial_item_code, warehouse=warehouse, qty=11, rate=200, do_not_submit=True
|
||||||
|
)
|
||||||
|
|
||||||
|
serial_nos = get_serial_nos(stock_entry.items[0].serial_no)
|
||||||
|
|
||||||
|
sr.items[0].serial_no += f"\n{serial_nos[0]}"
|
||||||
|
sr.save()
|
||||||
|
self.assertRaises(frappe.ValidationError, sr.submit)
|
||||||
|
|
||||||
|
|
||||||
def create_batch_item_with_batch(item_name, batch_id):
|
def create_batch_item_with_batch(item_name, batch_id):
|
||||||
batch_item_doc = create_item(item_name, is_stock_item=1)
|
batch_item_doc = create_item(item_name, is_stock_item=1)
|
||||||
|
|||||||
Reference in New Issue
Block a user