fix: asset movement ux fixes (#19637)

This commit is contained in:
Saqib 2019-11-22 16:35:15 +05:30 committed by Nabin Hait
parent 1919af2ff1
commit c9203a1bee
5 changed files with 38 additions and 92 deletions

View File

@ -42,6 +42,24 @@ frappe.ui.form.on('Asset', {
}, },
setup: function(frm) { setup: function(frm) {
frm.make_methods = {
'Asset Movement': () => {
frappe.call({
method: "erpnext.assets.doctype.asset.asset.make_asset_movement",
freeze: true,
args:{
"assets": [{ name: cur_frm.doc.name }]
},
callback: function (r) {
if (r.message) {
var doc = frappe.model.sync(r.message)[0];
frappe.set_route("Form", doc.doctype, doc.name);
}
}
});
},
}
frm.set_query("purchase_receipt", (doc) => { frm.set_query("purchase_receipt", (doc) => {
return { return {
query: "erpnext.controllers.queries.get_purchase_receipts", query: "erpnext.controllers.queries.get_purchase_receipts",
@ -487,92 +505,19 @@ erpnext.asset.restore_asset = function(frm) {
}) })
}; };
erpnext.asset.transfer_asset = function(frm) { erpnext.asset.transfer_asset = function() {
var dialog = new frappe.ui.Dialog({ frappe.call({
title: __("Transfer Asset"), method: "erpnext.assets.doctype.asset.asset.make_asset_movement",
fields: [ freeze: true,
{ args:{
"label": __("Target Location"), "assets": [{ name: cur_frm.doc.name }],
"fieldname": "target_location", "purpose": "Transfer"
"fieldtype": "Link", },
"options": "Location", callback: function (r) {
"get_query": function () { if (r.message) {
return { var doc = frappe.model.sync(r.message)[0];
filters: [ frappe.set_route("Form", doc.doctype, doc.name);
["Location", "is_group", "=", 0]
]
}
},
"reqd": 1
},
{
"label": __("Select Serial No"),
"fieldname": "serial_nos",
"fieldtype": "Link",
"options": "Serial No",
"get_query": function () {
return {
filters: {
'asset': frm.doc.name
}
}
},
"onchange": function() {
let val = this.get_value();
if (val) {
let serial_nos = dialog.get_value("serial_no") || val;
if (serial_nos) {
serial_nos = serial_nos.split('\n');
serial_nos.push(val);
const unique_sn = serial_nos.filter(function(elem, index, self) {
return index === self.indexOf(elem);
});
dialog.set_value("serial_no", unique_sn.join('\n'));
dialog.set_value("serial_nos", "");
}
}
}
},
{
"label": __("Serial No"),
"fieldname": "serial_no",
"read_only": 1,
"fieldtype": "Small Text"
},
{
"label": __("Date"),
"fieldname": "transfer_date",
"fieldtype": "Datetime",
"reqd": 1,
"default": frappe.datetime.now_datetime()
} }
] }
}); });
dialog.set_primary_action(__("Transfer"), function() {
var args = dialog.get_values();
if(!args) return;
dialog.hide();
return frappe.call({
type: "GET",
method: "erpnext.assets.doctype.asset.asset.transfer_asset",
args: {
args: {
"asset": frm.doc.name,
"transaction_date": args.transfer_date,
"source_location": frm.doc.location,
"target_location": args.target_location,
"serial_no": args.serial_no,
"company": frm.doc.company
}
},
freeze: true,
callback: function(r) {
cur_frm.reload_doc();
}
})
});
dialog.show();
}; };

View File

@ -647,7 +647,7 @@ def make_journal_entry(asset_name):
return je return je
@frappe.whitelist() @frappe.whitelist()
def make_asset_movement(assets): def make_asset_movement(assets, purpose=None):
import json import json
from six import string_types from six import string_types
@ -658,7 +658,7 @@ def make_asset_movement(assets):
frappe.throw(_('Atleast one asset has to be selected.')) frappe.throw(_('Atleast one asset has to be selected.'))
asset_movement = frappe.new_doc("Asset Movement") asset_movement = frappe.new_doc("Asset Movement")
asset_movement.quantity = len(assets) asset_movement.purpose = purpose
prev_reference_docname = '' prev_reference_docname = ''
for asset in assets: for asset in assets:

View File

@ -37,6 +37,7 @@ frappe.listview_settings['Asset'] = {
const assets = me.get_checked_items(); const assets = me.get_checked_items();
frappe.call({ frappe.call({
method: "erpnext.assets.doctype.asset.asset.make_asset_movement", method: "erpnext.assets.doctype.asset.asset.make_asset_movement",
freeze: true,
args:{ args:{
"assets": assets "assets": assets
}, },

View File

@ -132,7 +132,7 @@ frappe.ui.form.on('Asset Movement Item', {
if(asset_doc.location) frappe.model.set_value(cdt, cdn, 'source_location', asset_doc.location); if(asset_doc.location) frappe.model.set_value(cdt, cdn, 'source_location', asset_doc.location);
if(asset_doc.custodian) frappe.model.set_value(cdt, cdn, 'from_employee', asset_doc.custodian); if(asset_doc.custodian) frappe.model.set_value(cdt, cdn, 'from_employee', asset_doc.custodian);
}).catch((err) => { }).catch((err) => {
console.log(err); console.log(err); // eslint-disable-line
}); });
} }
} }

View File

@ -54,7 +54,7 @@
{ {
"fieldname": "reference_doctype", "fieldname": "reference_doctype",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Reference DocType", "label": "Reference Document",
"no_copy": 1, "no_copy": 1,
"options": "DocType", "options": "DocType",
"reqd": 1 "reqd": 1
@ -62,7 +62,7 @@
{ {
"fieldname": "reference_name", "fieldname": "reference_name",
"fieldtype": "Dynamic Link", "fieldtype": "Dynamic Link",
"label": "Reference Name", "label": "Reference Document Name",
"no_copy": 1, "no_copy": 1,
"options": "reference_doctype", "options": "reference_doctype",
"reqd": 1 "reqd": 1
@ -93,7 +93,7 @@
} }
], ],
"is_submittable": 1, "is_submittable": 1,
"modified": "2019-11-13 15:37:48.870147", "modified": "2019-11-21 14:35:51.880332",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Assets", "module": "Assets",
"name": "Asset Movement", "name": "Asset Movement",