brotherton-erpnext/erpnext/public/js/controllers/stock_controller.js

81 lines
2.3 KiB
JavaScript
Raw Normal View History

2013-11-20 07:29:58 +00:00
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
2013-01-11 13:55:46 +00:00
2014-02-14 10:17:51 +00:00
frappe.provide("erpnext.stock");
2013-01-11 13:55:46 +00:00
2014-02-14 10:17:51 +00:00
erpnext.stock.StockController = frappe.ui.form.Controller.extend({
2014-06-24 13:23:04 +00:00
onload: function() {
// warehouse query if company
if (this.frm.fields_dict.company) {
this.setup_warehouse_query();
}
},
setup_warehouse_query: function() {
var me = this;
var _set_warehouse_query = function(doctype, parentfield) {
var warehouse_link_fields = frappe.meta.get_docfields(doctype, me.frm.doc.name,
{"fieldtype": "Link", "options": "Warehouse"});
$.each(warehouse_link_fields, function(i, df) {
me.frm.set_query(df.fieldname, parentfield, function() {
return erpnext.queries.warehouse(me.frm.doc);
})
});
};
_set_warehouse_query(me.frm.doc.doctype);
// warehouse field in tables
var table_fields = frappe.meta.get_docfields(me.frm.doc.doctype, me.frm.doc.name,
{"fieldtype": "Table"});
$.each(table_fields, function(i, df) {
_set_warehouse_query(df.options, df.fieldname);
});
},
2013-01-11 13:55:46 +00:00
show_stock_ledger: function() {
var me = this;
if(this.frm.doc.docstatus===1) {
2014-04-14 10:55:30 +00:00
this.frm.appframe.add_button(__("Stock Ledger"), function() {
2014-02-14 10:17:51 +00:00
frappe.route_options = {
voucher_no: me.frm.doc.name,
from_date: me.frm.doc.posting_date,
to_date: me.frm.doc.posting_date,
company: me.frm.doc.company
};
2014-02-14 10:17:51 +00:00
frappe.set_route("query-report", "Stock Ledger");
}, "icon-bar-chart");
}
2014-06-24 13:23:04 +00:00
},
2013-10-17 11:31:14 +00:00
show_general_ledger: function() {
var me = this;
2014-06-24 13:23:04 +00:00
if(this.frm.doc.docstatus===1 && cint(frappe.defaults.get_default("auto_accounting_for_stock"))) {
2014-04-14 10:55:30 +00:00
cur_frm.appframe.add_button(__('Accounting Ledger'), function() {
2014-02-14 10:17:51 +00:00
frappe.route_options = {
voucher_no: me.frm.doc.name,
from_date: me.frm.doc.posting_date,
to_date: me.frm.doc.posting_date,
2014-01-03 07:00:24 +00:00
company: me.frm.doc.company,
group_by_voucher: false
};
2014-02-14 10:17:51 +00:00
frappe.set_route("query-report", "General Ledger");
2013-11-15 08:25:45 +00:00
}, "icon-table");
}
2013-10-17 11:31:14 +00:00
},
copy_account_in_all_row: function(doc, dt, dn, fieldname) {
var d = locals[dt][dn];
if(d[fieldname]){
2014-03-27 08:47:33 +00:00
var cl = doc[this.frm.cscript.fname] || [];
2013-10-17 11:31:14 +00:00
for(var i = 0; i < cl.length; i++) {
if(!cl[i][fieldname]) cl[i][fieldname] = d[fieldname];
}
}
refresh_field(this.frm.cscript.fname);
2013-01-11 13:55:46 +00:00
}
2014-06-24 13:23:04 +00:00
});