blob: 12eb5fb7bab8b8f225148f7ab050191f32c34727 [file] [log] [blame]
Rushabh Mehtaad45e312013-11-20 12:59:58 +05301// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302// License: GNU General Public License v3. See license.txt
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05303frappe.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)
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053010 return frappe.model.get_doc(":Company", company).default_currency || frappe.boot.sysdefaults.currency;
Anand Doshibdee6e02013-07-09 13:03:39 +053011 else
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053012 return frappe.boot.sysdefaults.currency;
Anand Doshibdee6e02013-07-09 13:03:39 +053013 },
14
15 hide_naming_series: function() {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053016 if(cur_frm.fields_dict.naming_series && !frappe.meta.get_docfield(cur_frm.doctype, "naming_series")) {
Anand Doshibdee6e02013-07-09 13:03:39 +053017 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) {
Rushabh Mehta89418412013-10-07 18:22:29 +053023 var companies = Object.keys(locals[":Company"] || {});
Anand Doshibdee6e02013-07-09 13:03:39 +053024 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
Akhilesh Darjeee158cea2013-10-31 19:50:51 +053031 add_applicable_territory: function() {
Anand Doshi1ffc5b52013-07-15 18:09:43 +053032 if(cur_frm.doc.__islocal &&
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053033 frappe.model.get_doclist(cur_frm.doc.doctype, cur_frm.doc.name).length === 1) {
Nabin Hait05b28eb2014-02-19 11:04:32 +053034 var default_territory = frappe.defaults.get_default("territory");
35 if(default_territory) {
36 var territory = frappe.model.add_child(cur_frm.doc, "Applicable Territory",
37 "valid_for_territories");
38 territory.territory = default_territory;
39 }
40
Anand Doshi1ffc5b52013-07-15 18:09:43 +053041 }
42 },
Rushabh Mehta62030e02013-08-14 18:37:28 +053043
44 setup_serial_no: function(grid_row) {
Anand Doshif83cf582013-08-20 15:36:10 +053045 if(!grid_row.fields_dict.serial_no ||
46 grid_row.fields_dict.serial_no.get_status()!=="Write") return;
Rushabh Mehta62030e02013-08-14 18:37:28 +053047
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053048 var $btn = $('<button class="btn btn-sm btn-default">'+frappe._("Add Serial No")+'</button>')
Rushabh Mehta62030e02013-08-14 18:37:28 +053049 .appendTo($("<div>")
Rushabh Mehta7d8b1892013-11-08 16:27:18 +053050 .css({"margin-bottom": "10px", "margin-left": "15px"})
Rushabh Mehta62030e02013-08-14 18:37:28 +053051 .appendTo(grid_row.fields_dict.serial_no.$wrapper));
52
53 $btn.on("click", function() {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053054 var d = new frappe.ui.Dialog({
55 title: frappe._("Add Serial No"),
Rushabh Mehta62030e02013-08-14 18:37:28 +053056 fields: [
57 {
58 "fieldtype": "Link",
59 "options": "Serial No",
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053060 "label": frappe._("Serial No"),
Rushabh Mehta62030e02013-08-14 18:37:28 +053061 "get_query": {
62 item_code: grid_row.doc.item_code,
63 warehouse: grid_row.doc.warehouse
64 }
65 },
66 {
67 "fieldtype": "Button",
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053068 "label": frappe._("Add")
Rushabh Mehta62030e02013-08-14 18:37:28 +053069 }
70 ]
71 });
72
73 d.get_input("add").on("click", function() {
74 var serial_no = d.get_value("serial_no");
75 if(serial_no) {
76 var val = (grid_row.doc.serial_no || "").split("\n").concat([serial_no]).join("\n");
77 grid_row.fields_dict.serial_no.set_model_value(val.trim());
78 }
79 d.hide();
80 return false;
81 });
82
83 d.show();
84 });
85 }
Anand Doshibdee6e02013-07-09 13:03:39 +053086});