fix: asset movement ux fixes (#19641)
This commit is contained in:
parent
225d38e797
commit
150c44b350
@ -42,6 +42,24 @@ frappe.ui.form.on('Asset', {
|
||||
},
|
||||
|
||||
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) => {
|
||||
return {
|
||||
query: "erpnext.controllers.queries.get_purchase_receipts",
|
||||
@ -487,92 +505,19 @@ erpnext.asset.restore_asset = function(frm) {
|
||||
})
|
||||
};
|
||||
|
||||
erpnext.asset.transfer_asset = function(frm) {
|
||||
var dialog = new frappe.ui.Dialog({
|
||||
title: __("Transfer Asset"),
|
||||
fields: [
|
||||
{
|
||||
"label": __("Target Location"),
|
||||
"fieldname": "target_location",
|
||||
"fieldtype": "Link",
|
||||
"options": "Location",
|
||||
"get_query": function () {
|
||||
return {
|
||||
filters: [
|
||||
["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
|
||||
}
|
||||
},
|
||||
erpnext.asset.transfer_asset = function() {
|
||||
frappe.call({
|
||||
method: "erpnext.assets.doctype.asset.asset.make_asset_movement",
|
||||
freeze: true,
|
||||
args:{
|
||||
"assets": [{ name: cur_frm.doc.name }],
|
||||
"purpose": "Transfer"
|
||||
},
|
||||
callback: function (r) {
|
||||
cur_frm.reload_doc();
|
||||
if (r.message) {
|
||||
var doc = frappe.model.sync(r.message)[0];
|
||||
frappe.set_route("Form", doc.doctype, doc.name);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
dialog.show();
|
||||
};
|
||||
|
@ -646,7 +646,7 @@ def make_journal_entry(asset_name):
|
||||
return je
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_asset_movement(assets):
|
||||
def make_asset_movement(assets, purpose=None):
|
||||
import json
|
||||
from six import string_types
|
||||
|
||||
@ -657,7 +657,7 @@ def make_asset_movement(assets):
|
||||
frappe.throw(_('Atleast one asset has to be selected.'))
|
||||
|
||||
asset_movement = frappe.new_doc("Asset Movement")
|
||||
asset_movement.quantity = len(assets)
|
||||
asset_movement.purpose = purpose
|
||||
prev_reference_docname = ''
|
||||
|
||||
for asset in assets:
|
||||
|
@ -37,6 +37,7 @@ frappe.listview_settings['Asset'] = {
|
||||
const assets = me.get_checked_items();
|
||||
frappe.call({
|
||||
method: "erpnext.assets.doctype.asset.asset.make_asset_movement",
|
||||
freeze: true,
|
||||
args:{
|
||||
"assets": assets
|
||||
},
|
||||
|
@ -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.custodian) frappe.model.set_value(cdt, cdn, 'from_employee', asset_doc.custodian);
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
console.log(err); // eslint-disable-line
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@
|
||||
{
|
||||
"fieldname": "reference_doctype",
|
||||
"fieldtype": "Link",
|
||||
"label": "Reference DocType",
|
||||
"label": "Reference Document",
|
||||
"no_copy": 1,
|
||||
"options": "DocType",
|
||||
"reqd": 1
|
||||
@ -62,7 +62,7 @@
|
||||
{
|
||||
"fieldname": "reference_name",
|
||||
"fieldtype": "Dynamic Link",
|
||||
"label": "Reference Name",
|
||||
"label": "Reference Document Name",
|
||||
"no_copy": 1,
|
||||
"options": "reference_doctype",
|
||||
"reqd": 1
|
||||
@ -93,7 +93,7 @@
|
||||
}
|
||||
],
|
||||
"is_submittable": 1,
|
||||
"modified": "2019-11-13 15:37:48.870147",
|
||||
"modified": "2019-11-21 14:35:51.880332",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset Movement",
|
||||
|
Loading…
x
Reference in New Issue
Block a user