fix: BOM name issue (#44586) (cherry picked from commitd871e21a40) Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com> (cherry picked from commita5cc307417) # Conflicts: # erpnext/manufacturing/doctype/bom/bom.py
This commit is contained in:
@@ -250,6 +250,13 @@ frappe.ui.form.on("BOM", {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fields.push({
|
||||||
|
fieldtype: "Check",
|
||||||
|
label: __("Use Multi-Level BOM"),
|
||||||
|
fieldname: "use_multi_level_bom",
|
||||||
|
default: 1,
|
||||||
|
});
|
||||||
|
|
||||||
if (!skip_qty_field) {
|
if (!skip_qty_field) {
|
||||||
fields.push({
|
fields.push({
|
||||||
fieldtype: "Float",
|
fieldtype: "Float",
|
||||||
|
|||||||
@@ -179,10 +179,14 @@ class BOM(WebsiteGenerator):
|
|||||||
"BOM", filters={"name": ("like", search_key), "amended_from": ["is", "not set"]}, pluck="name"
|
"BOM", filters={"name": ("like", search_key), "amended_from": ["is", "not set"]}, pluck="name"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
if existing_boms:
|
if existing_boms:
|
||||||
index = self.get_next_version_index(existing_boms)
|
index = self.get_next_version_index(existing_boms)
|
||||||
else:
|
else:
|
||||||
index = 1
|
index = 1
|
||||||
|
=======
|
||||||
|
index = self.get_index_for_bom(existing_boms)
|
||||||
|
>>>>>>> a5cc307417 (fix: BOM name issue (backport #44586) (#44589))
|
||||||
|
|
||||||
prefix = self.doctype
|
prefix = self.doctype
|
||||||
suffix = "%.3i" % index # convert index to string (1 -> "001")
|
suffix = "%.3i" % index # convert index to string (1 -> "001")
|
||||||
@@ -200,21 +204,23 @@ class BOM(WebsiteGenerator):
|
|||||||
name = f"{prefix}-{truncated_item_name}-{suffix}"
|
name = f"{prefix}-{truncated_item_name}-{suffix}"
|
||||||
|
|
||||||
if frappe.db.exists("BOM", name):
|
if frappe.db.exists("BOM", name):
|
||||||
conflicting_bom = frappe.get_doc("BOM", name)
|
existing_boms = frappe.get_all(
|
||||||
|
"BOM", filters={"name": ("like", search_key), "amended_from": ["is", "not set"]}, pluck="name"
|
||||||
|
)
|
||||||
|
|
||||||
if conflicting_bom.item != self.item:
|
index = self.get_index_for_bom(existing_boms)
|
||||||
msg = _("A BOM with name {0} already exists for item {1}.").format(
|
suffix = "%.3i" % index
|
||||||
frappe.bold(name), frappe.bold(conflicting_bom.item)
|
name = f"{prefix}-{self.item}-{suffix}"
|
||||||
)
|
|
||||||
|
|
||||||
frappe.throw(
|
|
||||||
_("{0}{1} Did you rename the item? Please contact Administrator / Tech support").format(
|
|
||||||
msg, "<br>"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
def get_index_for_bom(self, existing_boms):
|
||||||
|
index = 1
|
||||||
|
if existing_boms:
|
||||||
|
index = self.get_next_version_index(existing_boms)
|
||||||
|
|
||||||
|
return index
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_next_version_index(existing_boms: list[str]) -> int:
|
def get_next_version_index(existing_boms: list[str]) -> int:
|
||||||
# split by "/" and "-"
|
# split by "/" and "-"
|
||||||
|
|||||||
Reference in New Issue
Block a user