fix: cancelled document check

(cherry picked from commit 67d8a7ba86)
This commit is contained in:
Rohan Bansal
2022-03-02 15:25:06 +05:30
committed by Ankush Menat
parent 1a2a03ed98
commit c8ca92e406
2 changed files with 11 additions and 11 deletions

View File

@@ -104,7 +104,13 @@ class BOM(WebsiteGenerator):
) )
def autoname(self): def autoname(self):
existing_boms = frappe.get_all("BOM", filters={"item": self.item}, pluck="name") # ignore amended documents while calculating current index
existing_boms = frappe.get_all(
"BOM",
filters={"item": self.item, "amended_from": ["is", "not set"]},
pluck="name"
)
if existing_boms: if existing_boms:
index = self.get_next_version_index(existing_boms) index = self.get_next_version_index(existing_boms)
else: else:
@@ -144,15 +150,12 @@ class BOM(WebsiteGenerator):
pattern = "|".join(map(re.escape, delimiters)) pattern = "|".join(map(re.escape, delimiters))
bom_parts = [re.split(pattern, bom_name) for bom_name in existing_boms] bom_parts = [re.split(pattern, bom_name) for bom_name in existing_boms]
# filter out BOMs that do not follow the following formats: # filter out BOMs that do not follow the following formats: BOM/ITEM/001, BOM-ITEM-001
# - BOM/ITEM/001
# - BOM/ITEM/001-1
# - BOM-ITEM-001
# - BOM-ITEM-001-1
valid_bom_parts = list(filter(lambda x: len(x) > 1 and x[-1], bom_parts)) valid_bom_parts = list(filter(lambda x: len(x) > 1 and x[-1], bom_parts))
# extract the current index from the BOM parts # extract the current index from the BOM parts
if valid_bom_parts: if valid_bom_parts:
# handle cancelled and submitted documents
indexes = [cint(part[-1]) for part in valid_bom_parts] indexes = [cint(part[-1]) for part in valid_bom_parts]
index = max(indexes) + 1 index = max(indexes) + 1
else: else:

View File

@@ -402,12 +402,9 @@ class TestBOM(ERPNextTestCase):
(1, []), (1, []),
(1, ["BOM#XYZ"]), (1, ["BOM#XYZ"]),
(2, ["BOM/ITEM/001"]), (2, ["BOM/ITEM/001"]),
(2, ["BOM/ITEM/001", "BOM/ITEM/001-1"]), (2, ["BOM-ITEM-001"]),
(2, ["BOM-ITEM-001",]), (3, ["BOM-ITEM-001", "BOM-ITEM-002"]),
(2, ["BOM-ITEM-001", "BOM-ITEM-001-1"]),
(3, ["BOM-ITEM-001", "BOM-ITEM-002", "BOM-ITEM-001-1"]),
(4, ["BOM-ITEM-001", "BOM-ITEM-002", "BOM-ITEM-003"]), (4, ["BOM-ITEM-001", "BOM-ITEM-002", "BOM-ITEM-003"]),
(2, ["BOM-ITEM-001", "BOM-ITEM-001-1", "BOM-ITEM-001-2"]),
] ]
for expected_index, existing_boms in version_index_test_cases: for expected_index, existing_boms in version_index_test_cases: