blob: 61e613bdecb26fd44598fe6ca9e528ae7fa0f35c [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2// License: GNU General Public License v3. See license.txt
Anand Doshibdee6e02013-07-09 13:03:39 +05303wn.provide("erpnext");
Anand Doshie65e6212012-11-19 15:43:18 +05304
Anand Doshibdee6e02013-07-09 13:03:39 +05305$.extend(erpnext, {
6 get_currency: function(company) {
7 if(!company && cur_frm)
8 company = cur_frm.doc.company;
9 if(company)
Nabin Hait48a0bd32013-07-23 15:31:39 +053010 return wn.model.get_doc(":Company", company).default_currency || wn.boot.sysdefaults.currency;
Anand Doshibdee6e02013-07-09 13:03:39 +053011 else
12 return wn.boot.sysdefaults.currency;
13 },
14
15 hide_naming_series: function() {
16 if(cur_frm.fields_dict.naming_series) {
17 cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal?true:false);
18 }
19 },
20
21 hide_company: function() {
22 if(cur_frm.fields_dict.company) {
23 var companies = Object.keys(locals[":Company"]);
24 if(companies.length === 1) {
25 if(!cur_frm.doc.company) cur_frm.set_value("company", companies[0]);
26 cur_frm.toggle_display("company", false);
27 }
28 }
Anand Doshi1ffc5b52013-07-15 18:09:43 +053029 },
30
31 add_for_territory: function() {
32 if(cur_frm.doc.__islocal &&
33 wn.model.get_doclist(cur_frm.doc.doctype, cur_frm.doc.name).length === 1) {
34 var territory = wn.model.add_child(cur_frm.doc, "For Territory",
35 "valid_for_territories");
36 territory.territory = wn.defaults.get_default("territory");
37 }
38 },
Rushabh Mehta62030e02013-08-14 18:37:28 +053039
40 setup_serial_no: function(grid_row) {
Anand Doshif83cf582013-08-20 15:36:10 +053041 if(!grid_row.fields_dict.serial_no ||
42 grid_row.fields_dict.serial_no.get_status()!=="Write") return;
Rushabh Mehta62030e02013-08-14 18:37:28 +053043
44 var $btn = $('<button class="btn btn-sm btn-default">Add Serial No</button>')
45 .appendTo($("<div>")
Rushabh Mehta3423a732013-08-16 13:03:34 +053046 .css({"margin-bottom": "10px", "margin-top": "-10px"})
Rushabh Mehta62030e02013-08-14 18:37:28 +053047 .appendTo(grid_row.fields_dict.serial_no.$wrapper));
48
49 $btn.on("click", function() {
50 var d = new wn.ui.Dialog({
51 title: "Add Serial No",
52 fields: [
53 {
54 "fieldtype": "Link",
55 "options": "Serial No",
56 "label": "Serial No",
57 "get_query": {
58 item_code: grid_row.doc.item_code,
59 warehouse: grid_row.doc.warehouse
60 }
61 },
62 {
63 "fieldtype": "Button",
64 "label": "Add"
65 }
66 ]
67 });
68
69 d.get_input("add").on("click", function() {
70 var serial_no = d.get_value("serial_no");
71 if(serial_no) {
72 var val = (grid_row.doc.serial_no || "").split("\n").concat([serial_no]).join("\n");
73 grid_row.fields_dict.serial_no.set_model_value(val.trim());
74 }
75 d.hide();
76 return false;
77 });
78
79 d.show();
80 });
81 }
Anand Doshibdee6e02013-07-09 13:03:39 +053082});