fix: Updated serial_no filters in maintenance visit.
diff --git a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js
index 45e632c..3c05526 100644
--- a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js
+++ b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js
@@ -65,104 +65,104 @@
}, __("Get Items From"));
} else if (this.frm.doc.docstatus === 1) {
var s = me.frm.doc.schedules;
- let flag = 0
- for(let i in s){
- if (s[i].completion_status == pending){
- flag = 1
+ let flag = 0;
+ for (let i in s) {
+ if (s[i].completion_status == "Pending") {
+ flag = 1;
}
}
- if(count){
- this.frm.add_custom_button(__('Create Maintenance Visit'), function () {
- let items = me.frm.doc.items;
- let s = me.frm.doc.schedules;
- let options = "";
- let dates = "";
- for (let i in items) {
- for(let d in s){
- if (s[d].item_name == items[i].item_name && s[d].completion_status == "Pending") {
- options = options + '\n' + items[i].item_name
- break
+ if (flag) {
+ this.frm.add_custom_button(__('Create Maintenance Visit'), function () {
+ let items = me.frm.doc.items;
+ let s = me.frm.doc.schedules;
+ let options = "";
+ let dates = "";
+ for (let i in items) {
+ for (let d in s) {
+ if (s[d].item_name == items[i].item_name && s[d].completion_status == "Pending") {
+ options = options + '\n' + items[i].item_name;
+ break;
+ }
}
}
- }
- function formatDate(date) {
- var d = new Date(date),
- month = '' + (d.getMonth() + 1),
- day = '' + d.getDate(),
- year = d.getFullYear();
+ function formatDate(date) {
+ var d = new Date(date),
+ month = '' + (d.getMonth() + 1),
+ day = '' + d.getDate(),
+ year = d.getFullYear();
- if (month.length < 2)
- month = '0' + month;
- if (day.length < 2)
- day = '0' + day;
+ if (month.length < 2)
+ month = '0' + month;
+ if (day.length < 2)
+ day = '0' + day;
- return [day, month, year].join('-');
- }
- var schedule_id = ""
- var d = new frappe.ui.Dialog({
- title: __("Enter Visit Details"),
- fields: [{
- fieldtype: "Select",
- fieldname: "item_name",
- label: __("Item Name"),
- options: options,
- reqd: 1,
- onchange: function () {
- let field = d.get_field("scheduled_date");
- dates = ""
- for (let i in s) {
- if (s[i].item_name == this.value && s[i].completion_status == "Pending") {
- dates = dates + '\n' + formatDate(s[i].scheduled_date);
- }
-
- }
- field.df.options = dates;
- field.refresh();
- }
- },
- {
- label: __('Scheduled Date'),
- fieldname: 'scheduled_date',
- fieldtype: 'Select',
- options: dates,
- reqd: 1,
- onchange: function(){
- let field = d.get_field('item_name');
- for(let i in s ){
- if(s[i].item_name == field.value && formatDate(s[i].scheduled_date) == this.value){
- schedule_id = s[i].name;
- }
- }
- }
- },
- ],
- primary_action_label: 'Create Visit',
- primary_action(values) {
- frappe.call({
- method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
- args: {
- item_name: values.item_name,
- s_id: schedule_id,
- source_name: me.frm.doc.name,
-
- },
- callback: function (r) {
- if (!r.exc) {
- frappe.model.sync(r.message);
- frappe.set_route("Form", r.message.doctype, r.message.name);
- }
- }
-
-
- });
- d.hide();
+ return [day, month, year].join('-');
}
- })
- d.show()
+ var schedule_id = "";
+ var d = new frappe.ui.Dialog({
+ title: __("Enter Visit Details"),
+ fields: [{
+ fieldtype: "Select",
+ fieldname: "item_name",
+ label: __("Item Name"),
+ options: options,
+ reqd: 1,
+ onchange: function () {
+ let field = d.get_field("scheduled_date");
+ dates = "";
+ for (let i in s) {
+ if (s[i].item_name == this.value && s[i].completion_status == "Pending") {
+ dates = dates + '\n' + formatDate(s[i].scheduled_date);
+ }
- }, __('Create'));
+ }
+ field.df.options = dates;
+ field.refresh();
+ }
+ },
+ {
+ label: __('Scheduled Date'),
+ fieldname: 'scheduled_date',
+ fieldtype: 'Select',
+ options: dates,
+ reqd: 1,
+ onchange: function () {
+ let field = d.get_field('item_name');
+ for (let i in s) {
+ if (s[i].item_name == field.value && formatDate(s[i].scheduled_date) == this.value) {
+ schedule_id = s[i].name;
+ }
+ }
+ }
+ },
+ ],
+ primary_action_label: 'Create Visit',
+ primary_action(values) {
+ frappe.call({
+ method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
+ args: {
+ item_name: values.item_name,
+ s_id: schedule_id,
+ source_name: me.frm.doc.name,
+
+ },
+ callback: function (r) {
+ if (!r.exc) {
+ frappe.model.sync(r.message);
+ frappe.set_route("Form", r.message.doctype, r.message.name);
+ }
+ }
+
+
+ });
+ d.hide();
+ }
+ });
+ d.show();
+
+ }, __('Create'));
+ }
}
- }
},
start_date: function (doc, cdt, cdn) {
diff --git a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py
index aa582ee..b89d540 100644
--- a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py
+++ b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py
@@ -10,6 +10,7 @@
from erpnext.utilities.transaction_base import TransactionBase, delete_events
from erpnext.stock.utils import get_valid_serial_nos
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
+from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
class MaintenanceSchedule(TransactionBase):
@frappe.whitelist()
@@ -246,17 +247,27 @@
delete_events(self.doctype, self.name)
@frappe.whitelist()
+def update_serial_nos(s_id):
+ serial_nos = frappe.db.get_value('Maintenance Schedule Detail', s_id, 'serial_no')
+ if serial_nos:
+ serial_nos = get_serial_nos(serial_nos)
+ return serial_nos
+ else:
+ return False
+
+@frappe.whitelist()
def make_maintenance_visit(source_name, target_doc=None,item_name=None,s_id=None):
from frappe.model.mapper import get_mapped_doc
def update_status(source, target, parent):
target.maintenance_type = "Scheduled"
-
+
def update_sid(source, target, parent):
target.prevdoc_detail_docname = s_id
sales_person = frappe.db.get_value('Maintenance Schedule Detail', s_id, 'sales_person')
target.service_person = sales_person
-
+ target.serial_no = ''
+
doclist = get_mapped_doc("Maintenance Schedule", source_name, {
"Maintenance Schedule": {
"doctype": "Maintenance Visit",
diff --git a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js
index 4cbb02a..d5e8e51 100644
--- a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js
+++ b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js
@@ -2,39 +2,62 @@
// License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.maintenance");
-
+var serial_nos = [];
frappe.ui.form.on('Maintenance Visit', {
- refresh: function(frm) {
+ refresh: function (frm) {
//filters for serial_no based on item_code
- frm.set_query('serial_no', 'purposes', function(frm, cdt, cdn) {
+ frm.set_query('serial_no', 'purposes', function (frm, cdt, cdn) {
let item = locals[cdt][cdn];
- return {
- filters: {
- 'item_code': item.item_code
- }
- };
+ if (serial_nos) {
+ return {
+ filters: {
+ 'item_code': item.item_code,
+ 'name': ["in", serial_nos]
+ }
+ };
+
+ } else {
+
+ return {
+ filters: {
+ 'item_code': item.item_code
+ }
+ };
+ }
+
});
},
- setup: function(frm) {
+ setup: function (frm) {
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);
},
- onload: function(frm) {
+ onload: function (frm, cdt, cdn) {
+ let item = locals[cdt][cdn];
+ let s_id = item.purposes[0].prevdoc_detail_docname;
+ frappe.call({
+ method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.update_serial_nos",
+ args: {
+ s_id: s_id
+ },
+ callback: function (r) {
+ serial_nos = r.message;
+ }
+ });
if (!frm.doc.status) {
- frm.set_value({status:'Draft'});
+ frm.set_value({ status: 'Draft' });
}
if (frm.doc.__islocal) {
- frm.set_value({mntc_date: frappe.datetime.get_today()});
+ frm.set_value({ mntc_date: frappe.datetime.get_today() });
}
},
- customer: function(frm) {
+ customer: function (frm) {
erpnext.utils.get_party_details(frm);
},
- customer_address: function(frm) {
+ customer_address: function (frm) {
erpnext.utils.get_address_display(frm, 'customer_address', 'address_display');
},
- contact_person: function(frm) {
+ contact_person: function (frm) {
erpnext.utils.get_contact_details(frm);
}
@@ -42,14 +65,14 @@
// TODO commonify this code
erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
- refresh: function() {
- frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
+ refresh: function () {
+ frappe.dynamic_link = { doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer' };
var me = this;
- if (this.frm.doc.docstatus===0) {
+ if (this.frm.doc.docstatus === 0) {
this.frm.add_custom_button(__('Maintenance Schedule'),
- function() {
+ function () {
erpnext.utils.map_current_doc({
method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
source_doctype: "Maintenance Schedule",
@@ -64,7 +87,7 @@
})
}, __("Get Items From"));
this.frm.add_custom_button(__('Warranty Claim'),
- function() {
+ function () {
erpnext.utils.map_current_doc({
method: "erpnext.support.doctype.warranty_claim.warranty_claim.make_maintenance_visit",
source_doctype: "Warranty Claim",
@@ -80,7 +103,7 @@
})
}, __("Get Items From"));
this.frm.add_custom_button(__('Sales Order'),
- function() {
+ function () {
erpnext.utils.map_current_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_visit",
source_doctype: "Sales Order",
@@ -99,4 +122,4 @@
},
});
-$.extend(cur_frm.cscript, new erpnext.maintenance.MaintenanceVisit({frm: cur_frm}));
\ No newline at end of file
+$.extend(cur_frm.cscript, new erpnext.maintenance.MaintenanceVisit({ frm: cur_frm }));
\ No newline at end of file
diff --git a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.py b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.py
index 9505a36..8a3094c 100644
--- a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.py
+++ b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.py
@@ -30,20 +30,21 @@
def validate(self):
self.validate_serial_no()
self.validate_mntc_date()
+
+ def get_schedule_datail_ref(self):
+ if self.maintenance_type == "Scheduled":
+ p = self.purposes
+ for i in p:
+ detail_ref = i.prevdoc_detail_docname
+ return detail_ref
def update_completion_status(self):
- if self.maintenance_type == "Scheduled":
- p = self.purposes
- for i in p:
- detail_ref = i.prevdoc_detail_docname
- frappe.db.set_value('Maintenance Schedule Detail', detail_ref, 'completion_status', self.completion_status)
+ detail_ref = self.get_schedule_datail_ref()
+ frappe.db.set_value('Maintenance Schedule Detail', detail_ref, 'completion_status', self.completion_status)
def update_actual_date(self):
- if self.maintenance_type == "Scheduled":
- p = self.purposes
- for i in p:
- detail_ref = i.prevdoc_detail_docname
- frappe.db.set_value('Maintenance Schedule Detail', detail_ref, 'actual_date', self.mntc_date)
+ detail_ref = self.get_schedule_datail_ref()
+ frappe.db.set_value('Maintenance Schedule Detail', detail_ref, 'actual_date', self.mntc_date)
def update_customer_issue(self, flag):
for d in self.get('purposes'):