blob: 9d4ea1443f6a161d8e7b509ffd323d54d2aa2010 [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) {
41 if(grid_row.fields_dict.serial_no.get_status()!=="Write") return;
42
43 var $btn = $('<button class="btn btn-sm btn-default">Add Serial No</button>')
44 .appendTo($("<div>")
45 .css({"margin-bottom": "10px"})
46 .appendTo(grid_row.fields_dict.serial_no.$wrapper));
47
48 $btn.on("click", function() {
49 var d = new wn.ui.Dialog({
50 title: "Add Serial No",
51 fields: [
52 {
53 "fieldtype": "Link",
54 "options": "Serial No",
55 "label": "Serial No",
56 "get_query": {
57 item_code: grid_row.doc.item_code,
58 warehouse: grid_row.doc.warehouse
59 }
60 },
61 {
62 "fieldtype": "Button",
63 "label": "Add"
64 }
65 ]
66 });
67
68 d.get_input("add").on("click", function() {
69 var serial_no = d.get_value("serial_no");
70 if(serial_no) {
71 var val = (grid_row.doc.serial_no || "").split("\n").concat([serial_no]).join("\n");
72 grid_row.fields_dict.serial_no.set_model_value(val.trim());
73 }
74 d.hide();
75 return false;
76 });
77
78 d.show();
79 });
80 }
Anand Doshibdee6e02013-07-09 13:03:39 +053081});