Skip to content

Commit

Permalink
style: format warehouse js
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed May 23, 2022
1 parent a36174a commit c704ad8
Showing 1 changed file with 64 additions and 47 deletions.
111 changes: 64 additions & 47 deletions erpnext/stock/doctype/warehouse/warehouse.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,105 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt


frappe.ui.form.on("Warehouse", {
onload: function(frm) {
frm.set_query("default_in_transit_warehouse", function() {
onload: function (frm) {
frm.set_query("default_in_transit_warehouse", function () {
return {
filters:{
'warehouse_type' : 'Transit',
'is_group': 0,
'company': frm.doc.company
}
filters: {
warehouse_type: "Transit",
is_group: 0,
company: frm.doc.company,
},
};
});
},

refresh: function(frm) {
frm.toggle_display('warehouse_name', frm.doc.__islocal);
frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal);
refresh: function (frm) {
frm.toggle_display("warehouse_name", 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);

} else {
frappe.contacts.clear_address_and_contact(frm);
}

frm.add_custom_button(__("Stock Balance"), function() {
frappe.set_route("query-report", "Stock Balance", {"warehouse": frm.doc.name});
frm.add_custom_button(__("Stock Balance"), function () {
frappe.set_route("query-report", "Stock Balance", {
warehouse: frm.doc.name,
});
});

if (cint(frm.doc.is_group) == 1) {
frm.add_custom_button(__('Group to Non-Group'),
function() { convert_to_group_or_ledger(frm); }, 'fa fa-retweet', 'btn-default')
frm.add_custom_button(
__("Group to Non-Group"),
function () {
convert_to_group_or_ledger(frm);
},
"fa fa-retweet",
"btn-default"
);
} else if (cint(frm.doc.is_group) == 0) {
if(frm.doc.__onload && frm.doc.__onload.account) {
frm.add_custom_button(__("General Ledger"), function() {
if (frm.doc.__onload && frm.doc.__onload.account) {
frm.add_custom_button(__("General Ledger"), function () {
frappe.route_options = {
"account": frm.doc.__onload.account,
"company": frm.doc.company
}
account: frm.doc.__onload.account,
company: frm.doc.company,
};
frappe.set_route("query-report", "General Ledger");
});
}

frm.add_custom_button(__('Non-Group to Group'),
function() { convert_to_group_or_ledger(frm); }, 'fa fa-retweet', 'btn-default')
frm.add_custom_button(
__("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 {
filters: {
"is_group": 1,
}
}
}
is_group: 1,
},
};
};

frm.fields_dict['account'].get_query = function(doc) {
frm.fields_dict["account"].get_query = function (doc) {
return {
filters: {
"is_group": 0,
"account_type": "Stock",
"company": frm.doc.company
}
}
}
}
is_group: 0,
account_type: "Stock",
company: frm.doc.company,
},
};
};
},
});

function convert_to_group_or_ledger(frm){
function convert_to_group_or_ledger(frm) {
frappe.call({
method:"erpnext.stock.doctype.warehouse.warehouse.convert_to_group_or_ledger",
method: "erpnext.stock.doctype.warehouse.warehouse.convert_to_group_or_ledger",
args: {
docname: frm.doc.name,
is_group: frm.doc.is_group
is_group: frm.doc.is_group,
},
callback: function(){
callback: function () {
frm.refresh();
}

})
},
});
}

0 comments on commit c704ad8

Please sign in to comment.