fix: ignore already fetched serial no

exclude_sr_nos is sent as JSON string of list, so load it before
operating on it.
This commit is contained in:
Ankush Menat 2022-03-22 15:31:40 +05:30 committed by Ankush Menat
parent ec04242d72
commit a18c687844
2 changed files with 13 additions and 3 deletions

View File

@ -3,6 +3,7 @@
import json
from typing import List, Optional, Union
import frappe
from frappe import ValidationError, _
@ -574,14 +575,22 @@ def get_delivery_note_serial_no(item_code, qty, delivery_note):
return serial_nos
@frappe.whitelist()
def auto_fetch_serial_number(qty, item_code, warehouse,
posting_date=None, batch_nos=None, for_doctype=None, exclude_sr_nos=None):
def auto_fetch_serial_number(
qty: float,
item_code: str,
warehouse: str,
posting_date: Optional[str] = None,
batch_nos: Optional[Union[str, List[str]]] = None,
for_doctype: Optional[str] = None,
exclude_sr_nos: Optional[List[str]] = None
) -> List[str]:
filters = frappe._dict({"item_code": item_code, "warehouse": warehouse})
if exclude_sr_nos is None:
exclude_sr_nos = []
else:
exclude_sr_nos = safe_json_loads(exclude_sr_nos)
exclude_sr_nos = get_serial_nos(clean_serial_no_string("\n".join(exclude_sr_nos)))
if batch_nos:

View File

@ -274,7 +274,8 @@ class TestSerialNo(FrappeTestCase):
msg=f"{partial_fetch} should be subset of {first_fetch}")
# exclusion
remaining = auto_fetch_serial_number(3, item_code, warehouse, exclude_sr_nos=partial_fetch)
remaining = auto_fetch_serial_number(3, item_code, warehouse,
exclude_sr_nos=json.dumps(partial_fetch))
self.assertEqual(sorted(remaining + partial_fetch), first_fetch)
# batchwise