fix: cancelled document check
This commit is contained in:
parent
6b58d53403
commit
67d8a7ba86
@ -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:
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user