style: format warehouse js

This commit is contained in:
barredterra 2022-05-23 15:18:24 +02:00
parent a36174afdf
commit c704ad889d

View File

@ -1,76 +1,94 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
frappe.ui.form.on("Warehouse", { frappe.ui.form.on("Warehouse", {
onload: function (frm) { onload: function (frm) {
frm.set_query("default_in_transit_warehouse", function () { frm.set_query("default_in_transit_warehouse", function () {
return { return {
filters: { filters: {
'warehouse_type' : 'Transit', warehouse_type: "Transit",
'is_group': 0, is_group: 0,
'company': frm.doc.company company: frm.doc.company,
} },
}; };
}); });
}, },
refresh: function (frm) { refresh: function (frm) {
frm.toggle_display('warehouse_name', frm.doc.__islocal); frm.toggle_display("warehouse_name", frm.doc.__islocal);
frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal); frm.toggle_display(
["address_html", "contact_html"],
!frm.doc.__islocal
);
if (!frm.doc.__islocal) { if (!frm.doc.__islocal) {
frappe.contacts.render_address_and_contact(frm); frappe.contacts.render_address_and_contact(frm);
} else { } else {
frappe.contacts.clear_address_and_contact(frm); frappe.contacts.clear_address_and_contact(frm);
} }
frm.add_custom_button(__("Stock Balance"), function () { frm.add_custom_button(__("Stock Balance"), function () {
frappe.set_route("query-report", "Stock Balance", {"warehouse": frm.doc.name}); frappe.set_route("query-report", "Stock Balance", {
warehouse: frm.doc.name,
});
}); });
if (cint(frm.doc.is_group) == 1) { if (cint(frm.doc.is_group) == 1) {
frm.add_custom_button(__('Group to Non-Group'), frm.add_custom_button(
function() { convert_to_group_or_ledger(frm); }, 'fa fa-retweet', 'btn-default') __("Group to Non-Group"),
function () {
convert_to_group_or_ledger(frm);
},
"fa fa-retweet",
"btn-default"
);
} else if (cint(frm.doc.is_group) == 0) { } else if (cint(frm.doc.is_group) == 0) {
if (frm.doc.__onload && frm.doc.__onload.account) { if (frm.doc.__onload && frm.doc.__onload.account) {
frm.add_custom_button(__("General Ledger"), function () { frm.add_custom_button(__("General Ledger"), function () {
frappe.route_options = { frappe.route_options = {
"account": frm.doc.__onload.account, account: frm.doc.__onload.account,
"company": frm.doc.company company: frm.doc.company,
} };
frappe.set_route("query-report", "General Ledger"); frappe.set_route("query-report", "General Ledger");
}); });
} }
frm.add_custom_button(__('Non-Group to Group'), frm.add_custom_button(
function() { convert_to_group_or_ledger(frm); }, 'fa fa-retweet', 'btn-default') __("Non-Group to Group"),
function () {
convert_to_group_or_ledger(frm);
},
"fa fa-retweet",
"btn-default"
);
} }
frm.toggle_enable(['is_group', 'company'], false); frm.toggle_enable(["is_group", "company"], false);
frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Warehouse'}; frappe.dynamic_link = {
doc: frm.doc,
fieldname: "name",
doctype: "Warehouse",
};
frm.fields_dict['parent_warehouse'].get_query = function(doc) { frm.fields_dict["parent_warehouse"].get_query = function (doc) {
return { return {
filters: { filters: {
"is_group": 1, is_group: 1,
} },
} };
} };
frm.fields_dict['account'].get_query = function(doc) { frm.fields_dict["account"].get_query = function (doc) {
return { return {
filters: { filters: {
"is_group": 0, is_group: 0,
"account_type": "Stock", account_type: "Stock",
"company": frm.doc.company company: frm.doc.company,
} },
} };
} };
} },
}); });
function convert_to_group_or_ledger(frm) { function convert_to_group_or_ledger(frm) {
@ -78,11 +96,10 @@ function convert_to_group_or_ledger(frm){
method: "erpnext.stock.doctype.warehouse.warehouse.convert_to_group_or_ledger", method: "erpnext.stock.doctype.warehouse.warehouse.convert_to_group_or_ledger",
args: { args: {
docname: frm.doc.name, docname: frm.doc.name,
is_group: frm.doc.is_group is_group: frm.doc.is_group,
}, },
callback: function () { callback: function () {
frm.refresh(); frm.refresh();
} },
});
})
} }