chore: Implement Log clearing interface in BOM Update Log

- Implement Log clearing interface in BOM Update Log
- Add additional info in sidebar: Log clearing only happens for 'Update Cost' type logs
- 'Replace BOM' logs have important info and is used in BOM timeline, so we'll let users decide if they wanna keep or discard it
This commit is contained in:
marination 2022-06-21 14:03:05 +05:30
parent 5ae8f5d4b8
commit 4cf2225a29
2 changed files with 32 additions and 2 deletions

View File

@ -6,6 +6,8 @@ from typing import Any, Dict, List, Optional, Tuple, Union
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.query_builder import DocType, Interval
from frappe.query_builder.functions import Now
from frappe.utils import cint, cstr
from erpnext.manufacturing.doctype.bom_update_log.bom_updation_utils import (
@ -22,6 +24,17 @@ class BOMMissingError(frappe.ValidationError):
class BOMUpdateLog(Document):
@staticmethod
def clear_old_logs(days=None):
days = days or 90
table = DocType("BOM Update Log")
frappe.db.delete(
table,
filters=(
(table.modified < (Now() - Interval(days=days))) & (table.update_type == "Update Cost")
),
)
def validate(self):
if self.update_type == "Replace BOM":
self.validate_boms_are_specified()

View File

@ -1,6 +1,6 @@
frappe.listview_settings['BOM Update Log'] = {
add_fields: ["status"],
get_indicator: function(doc) {
get_indicator: (doc) => {
let status_map = {
"Queued": "orange",
"In Progress": "blue",
@ -9,5 +9,22 @@ frappe.listview_settings['BOM Update Log'] = {
};
return [__(doc.status), status_map[doc.status], "status,=," + doc.status];
}
},
onload: () => {
if (!frappe.model.can_write("Log Settings")) {
return;
}
let sidebar_entry = $(
'<ul class="list-unstyled sidebar-menu log-retention-note"></ul>'
).appendTo(cur_list.page.sidebar);
let message = __("Note: Automatic log deletion only applies to logs of type <i>Update Cost</i>");
$(`<hr><div class='text-muted'>${message}</div>`).appendTo(sidebar_entry);
frappe.require("logtypes.bundle.js", () => {
frappe.utils.logtypes.show_log_retention_message(cur_list.doctype);
});
},
};