fix: cancelled document check

This commit is contained in:
Rohan Bansal 2022-03-02 15:25:06 +05:30 committed by Ankush Menat
parent 6b58d53403
commit 67d8a7ba86
2 changed files with 11 additions and 11 deletions

View File

@ -104,7 +104,13 @@ class BOM(WebsiteGenerator):
)
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:
index = self.get_next_version_index(existing_boms)
else:
@ -144,15 +150,12 @@ class BOM(WebsiteGenerator):
pattern = "|".join(map(re.escape, delimiters))
bom_parts = [re.split(pattern, bom_name) for bom_name in existing_boms]
# filter out BOMs that do not follow the following formats:
# - BOM/ITEM/001
# - BOM/ITEM/001-1
# - BOM-ITEM-001
# - BOM-ITEM-001-1
# filter out BOMs that do not follow the following formats: BOM/ITEM/001, BOM-ITEM-001
valid_bom_parts = list(filter(lambda x: len(x) > 1 and x[-1], bom_parts))
# extract the current index from the BOM parts
if valid_bom_parts:
# handle cancelled and submitted documents
indexes = [cint(part[-1]) for part in valid_bom_parts]
index = max(indexes) + 1
else:

View File

@ -449,12 +449,9 @@ class TestBOM(FrappeTestCase):
(1, []),
(1, ["BOM#XYZ"]),
(2, ["BOM/ITEM/001"]),
(2, ["BOM/ITEM/001", "BOM/ITEM/001-1"]),
(2, ["BOM-ITEM-001",]),
(2, ["BOM-ITEM-001", "BOM-ITEM-001-1"]),
(3, ["BOM-ITEM-001", "BOM-ITEM-002", "BOM-ITEM-001-1"]),
(2, ["BOM-ITEM-001"]),
(3, ["BOM-ITEM-001", "BOM-ITEM-002"]),
(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: