mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 03:39:11 +00:00
refactor: serial and batch bundle for Maintenance Schedule
This commit is contained in:
@@ -7,6 +7,19 @@ frappe.ui.form.on('Maintenance Schedule', {
|
||||
frm.set_query('contact_person', erpnext.queries.contact_query);
|
||||
frm.set_query('customer_address', erpnext.queries.address_query);
|
||||
frm.set_query('customer', erpnext.queries.customer);
|
||||
|
||||
frm.set_query('serial_and_batch_bundle', 'items', (doc, cdt, cdn) => {
|
||||
let item = locals[cdt][cdn];
|
||||
|
||||
return {
|
||||
filters: {
|
||||
'item_code': item.item_code,
|
||||
'voucher_type': 'Maintenance Schedule',
|
||||
'type_of_transaction': 'Maintenance',
|
||||
'company': doc.company,
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
onload: function (frm) {
|
||||
if (!frm.doc.status) {
|
||||
|
||||
@@ -7,7 +7,6 @@ from frappe.utils import add_days, cint, cstr, date_diff, formatdate, getdate
|
||||
|
||||
from erpnext.setup.doctype.employee.employee import get_holiday_list_for_employee
|
||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||
from erpnext.stock.utils import get_valid_serial_nos
|
||||
from erpnext.utilities.transaction_base import TransactionBase, delete_events
|
||||
|
||||
|
||||
@@ -74,10 +73,14 @@ class MaintenanceSchedule(TransactionBase):
|
||||
|
||||
email_map = {}
|
||||
for d in self.get("items"):
|
||||
if d.serial_no:
|
||||
serial_nos = get_valid_serial_nos(d.serial_no)
|
||||
self.validate_serial_no(d.item_code, serial_nos, d.start_date)
|
||||
self.update_amc_date(serial_nos, d.end_date)
|
||||
if d.serial_and_batch_bundle:
|
||||
serial_nos = frappe.get_doc(
|
||||
"Serial and Batch Bundle", d.serial_and_batch_bundle
|
||||
).get_serial_nos()
|
||||
|
||||
if serial_nos:
|
||||
self.validate_serial_no(d.item_code, serial_nos, d.start_date)
|
||||
self.update_amc_date(serial_nos, d.end_date)
|
||||
|
||||
no_email_sp = []
|
||||
if d.sales_person not in email_map:
|
||||
@@ -241,9 +244,27 @@ class MaintenanceSchedule(TransactionBase):
|
||||
self.validate_maintenance_detail()
|
||||
self.validate_dates_with_periodicity()
|
||||
self.validate_sales_order()
|
||||
self.validate_serial_no_bundle()
|
||||
if not self.schedules or self.validate_items_table_change() or self.validate_no_of_visits():
|
||||
self.generate_schedule()
|
||||
|
||||
def validate_serial_no_bundle(self):
|
||||
ids = [d.serial_and_batch_bundle for d in self.items if d.serial_and_batch_bundle]
|
||||
|
||||
if not ids:
|
||||
return
|
||||
|
||||
voucher_nos = frappe.get_all(
|
||||
"Serial and Batch Bundle", fields=["name", "voucher_type"], filters={"name": ("in", ids)}
|
||||
)
|
||||
|
||||
for row in voucher_nos:
|
||||
if row.voucher_type != "Maintenance Schedule":
|
||||
msg = f"""Serial and Batch Bundle {row.name}
|
||||
should have voucher type as 'Maintenance Schedule'"""
|
||||
|
||||
frappe.throw(_(msg))
|
||||
|
||||
def on_update(self):
|
||||
self.db_set("status", "Draft")
|
||||
|
||||
@@ -341,9 +362,14 @@ class MaintenanceSchedule(TransactionBase):
|
||||
|
||||
def on_cancel(self):
|
||||
for d in self.get("items"):
|
||||
if d.serial_no:
|
||||
serial_nos = get_valid_serial_nos(d.serial_no)
|
||||
self.update_amc_date(serial_nos)
|
||||
if d.serial_and_batch_bundle:
|
||||
serial_nos = frappe.get_doc(
|
||||
"Serial and Batch Bundle", d.serial_and_batch_bundle
|
||||
).get_serial_nos()
|
||||
|
||||
if serial_nos:
|
||||
self.update_amc_date(serial_nos)
|
||||
|
||||
self.db_set("status", "Cancelled")
|
||||
delete_events(self.doctype, self.name)
|
||||
|
||||
@@ -397,11 +423,15 @@ def make_maintenance_visit(source_name, target_doc=None, item_name=None, s_id=No
|
||||
target.maintenance_schedule_detail = s_id
|
||||
|
||||
def update_serial(source, target, parent):
|
||||
serial_nos = get_serial_nos(target.serial_no)
|
||||
if len(serial_nos) == 1:
|
||||
target.serial_no = serial_nos[0]
|
||||
else:
|
||||
target.serial_no = ""
|
||||
if source.serial_and_batch_bundle:
|
||||
serial_nos = frappe.get_doc(
|
||||
"Serial and Batch Bundle", source.serial_and_batch_bundle
|
||||
).get_serial_nos()
|
||||
|
||||
if len(serial_nos) == 1:
|
||||
target.serial_no = serial_nos[0]
|
||||
else:
|
||||
target.serial_no = ""
|
||||
|
||||
doclist = get_mapped_doc(
|
||||
"Maintenance Schedule",
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
"sales_person",
|
||||
"reference",
|
||||
"serial_no",
|
||||
"sales_order"
|
||||
"sales_order",
|
||||
"column_break_ugqr",
|
||||
"serial_and_batch_bundle"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -121,7 +123,8 @@
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Serial No",
|
||||
"oldfieldname": "serial_no",
|
||||
"oldfieldtype": "Small Text"
|
||||
"oldfieldtype": "Small Text",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "sales_order",
|
||||
@@ -144,17 +147,31 @@
|
||||
{
|
||||
"fieldname": "column_break_10",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_ugqr",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "serial_and_batch_bundle",
|
||||
"fieldtype": "Link",
|
||||
"label": "Serial and Batch Bundle",
|
||||
"no_copy": 1,
|
||||
"options": "Serial and Batch Bundle",
|
||||
"print_hide": 1
|
||||
}
|
||||
],
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-15 16:09:47.311994",
|
||||
"modified": "2023-03-22 18:44:36.816037",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Maintenance",
|
||||
"name": "Maintenance Schedule Item",
|
||||
"naming_rule": "Random",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC"
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
Reference in New Issue
Block a user