2015-03-03 09:25:30 +00:00
|
|
|
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
// License: GNU General Public License v3. See license.txt
|
2013-05-24 13:55:01 +00:00
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.provide("erpnext");
|
2015-01-22 11:43:13 +00:00
|
|
|
frappe.require("assets/erpnext/js/controllers/taxes_and_totals.js");
|
2014-10-03 12:13:02 +00:00
|
|
|
frappe.require("assets/erpnext/js/utils.js");
|
2013-05-24 13:55:01 +00:00
|
|
|
|
2015-01-22 11:43:13 +00:00
|
|
|
erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
2013-05-24 13:55:01 +00:00
|
|
|
onload: function() {
|
2013-08-23 07:26:33 +00:00
|
|
|
var me = this;
|
2013-05-24 13:55:01 +00:00
|
|
|
if(this.frm.doc.__islocal) {
|
2013-08-23 07:26:33 +00:00
|
|
|
var today = get_today(),
|
2014-03-14 09:40:42 +00:00
|
|
|
currency = frappe.defaults.get_user_default("currency");
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-24 13:55:01 +00:00
|
|
|
$.each({
|
2013-05-27 13:59:07 +00:00
|
|
|
posting_date: today,
|
|
|
|
due_date: today,
|
|
|
|
transaction_date: today,
|
|
|
|
currency: currency,
|
|
|
|
price_list_currency: currency,
|
|
|
|
status: "Draft",
|
|
|
|
is_subcontracted: "No",
|
2013-05-24 13:55:01 +00:00
|
|
|
}, function(fieldname, value) {
|
|
|
|
if(me.frm.fields_dict[fieldname] && !me.frm.doc[fieldname])
|
|
|
|
me.frm.set_value(fieldname, value);
|
2014-04-15 13:10:00 +00:00
|
|
|
});
|
2014-07-07 11:21:52 +00:00
|
|
|
|
2014-07-28 09:25:08 +00:00
|
|
|
if(this.frm.doc.company && !this.frm.doc.amended_from) {
|
2014-07-07 11:21:52 +00:00
|
|
|
cur_frm.script_manager.trigger("company");
|
|
|
|
}
|
2013-05-24 13:55:01 +00:00
|
|
|
}
|
2013-10-17 06:01:11 +00:00
|
|
|
|
2014-12-26 07:45:21 +00:00
|
|
|
if(this.frm.fields_dict["taxes"]) {
|
|
|
|
this["taxes_remove"] = this.calculate_taxes_and_totals;
|
2013-08-23 07:30:47 +00:00
|
|
|
}
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2014-12-26 07:45:21 +00:00
|
|
|
if(this.frm.fields_dict["items"]) {
|
|
|
|
this["items_remove"] = this.calculate_taxes_and_totals;
|
2013-08-23 07:26:33 +00:00
|
|
|
}
|
2013-05-24 13:55:01 +00:00
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-08-06 11:53:44 +00:00
|
|
|
onload_post_render: function() {
|
2013-10-15 14:54:34 +00:00
|
|
|
var me = this;
|
2015-05-12 09:37:02 +00:00
|
|
|
if(this.frm.doc.__islocal && !(this.frm.doc.taxes || []).length
|
|
|
|
&& !(this.frm.doc.__onload ? this.frm.doc.__onload.load_after_mapping : false)) {
|
|
|
|
this.apply_default_taxes();
|
|
|
|
}
|
2015-05-19 05:40:12 +00:00
|
|
|
|
2014-12-26 07:45:21 +00:00
|
|
|
if(this.frm.doc.__islocal && this.frm.doc.company && this.frm.doc["items"] && !this.frm.doc.is_pos) {
|
2014-04-22 15:05:22 +00:00
|
|
|
this.calculate_taxes_and_totals();
|
2013-08-06 11:53:44 +00:00
|
|
|
}
|
2014-12-26 07:45:21 +00:00
|
|
|
if(frappe.meta.get_docfield(this.frm.doc.doctype + " Item", "item_code")) {
|
|
|
|
cur_frm.get_field("items").grid.set_multiple_add("item_code", "qty");
|
2014-06-04 07:40:41 +00:00
|
|
|
}
|
2013-08-06 11:53:44 +00:00
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-24 13:55:01 +00:00
|
|
|
refresh: function() {
|
2014-04-24 12:41:49 +00:00
|
|
|
erpnext.toggle_naming_series();
|
2013-07-09 07:33:39 +00:00
|
|
|
erpnext.hide_company();
|
2015-01-15 08:51:41 +00:00
|
|
|
this.hide_currency_and_price_list()
|
2013-05-24 13:55:01 +00:00
|
|
|
this.show_item_wise_taxes();
|
2013-07-29 13:30:53 +00:00
|
|
|
this.set_dynamic_labels();
|
2015-01-06 11:44:13 +00:00
|
|
|
erpnext.pos.make_pos_btn(this.frm);
|
2015-02-18 14:21:48 +00:00
|
|
|
this.setup_sms();
|
2013-09-17 06:26:17 +00:00
|
|
|
},
|
|
|
|
|
2015-05-12 09:37:02 +00:00
|
|
|
apply_default_taxes: function() {
|
2013-09-17 06:26:17 +00:00
|
|
|
var me = this;
|
2015-05-21 07:21:07 +00:00
|
|
|
var taxes_and_charges_field = frappe.meta.get_docfield(me.frm.doc.doctype, "taxes_and_charges",
|
|
|
|
me.frm.doc.name);
|
|
|
|
|
|
|
|
if(taxes_and_charges_field) {
|
|
|
|
frappe.call({
|
|
|
|
method: "erpnext.controllers.accounts_controller.get_default_taxes_and_charges",
|
|
|
|
args: {
|
|
|
|
"master_doctype": taxes_and_charges_field.options
|
|
|
|
},
|
|
|
|
callback: function(r) {
|
|
|
|
if(!r.exc) {
|
|
|
|
me.frm.set_value("taxes", r.message);
|
|
|
|
}
|
2015-05-12 09:37:02 +00:00
|
|
|
}
|
2015-05-21 07:21:07 +00:00
|
|
|
});
|
|
|
|
}
|
2015-05-12 09:37:02 +00:00
|
|
|
},
|
2014-08-08 10:00:49 +00:00
|
|
|
|
2015-02-18 14:21:48 +00:00
|
|
|
setup_sms: function() {
|
|
|
|
var me = this;
|
2015-05-19 05:40:12 +00:00
|
|
|
if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped"], this.frm.doc.status)
|
|
|
|
&& this.frm.doctype != "Purchase Invoice") {
|
2015-02-18 14:21:48 +00:00
|
|
|
this.frm.page.add_menu_item(__('Send SMS'), function() { me.send_sms(); });
|
2014-08-08 10:00:49 +00:00
|
|
|
}
|
2013-09-17 06:26:17 +00:00
|
|
|
},
|
|
|
|
|
2015-02-18 14:21:48 +00:00
|
|
|
send_sms: function() {
|
|
|
|
frappe.require("assets/erpnext/js/sms_manager.js");
|
2015-05-19 05:40:12 +00:00
|
|
|
var sms_man = new SMSManager(this.frm.doc);
|
2015-01-15 08:51:41 +00:00
|
|
|
},
|
2013-09-17 06:26:17 +00:00
|
|
|
|
2015-01-15 08:51:41 +00:00
|
|
|
hide_currency_and_price_list: function() {
|
2015-05-26 05:17:52 +00:00
|
|
|
if(this.frm.doc.conversion_rate == 1 && this.frm.doc.docstatus > 0) {
|
2015-01-15 08:51:41 +00:00
|
|
|
hide_field("currency_and_price_list");
|
|
|
|
} else {
|
|
|
|
unhide_field("currency_and_price_list");
|
2013-09-17 06:26:17 +00:00
|
|
|
}
|
2013-05-24 13:55:01 +00:00
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2015-06-09 09:51:50 +00:00
|
|
|
barcode: function(doc, cdt, cdn) {
|
|
|
|
var d = locals[cdt][cdn];
|
|
|
|
if(d.barcode=="" || d.barcode==null) {
|
|
|
|
// barcode cleared, remove item
|
|
|
|
d.item_code = "";
|
|
|
|
}
|
|
|
|
this.item_code(doc, cdt, cdn);
|
|
|
|
},
|
|
|
|
|
2014-02-12 09:23:18 +00:00
|
|
|
item_code: function(doc, cdt, cdn) {
|
|
|
|
var me = this;
|
2014-03-27 08:47:33 +00:00
|
|
|
var item = frappe.get_doc(cdt, cdn);
|
2014-02-12 09:23:18 +00:00
|
|
|
if(item.item_code || item.barcode || item.serial_no) {
|
|
|
|
if(!this.validate_company_and_party()) {
|
2014-12-26 07:45:21 +00:00
|
|
|
cur_frm.fields_dict["items"].grid.grid_rows[item.idx - 1].remove();
|
2014-02-12 09:23:18 +00:00
|
|
|
} else {
|
|
|
|
return this.frm.call({
|
|
|
|
method: "erpnext.stock.get_item_details.get_item_details",
|
|
|
|
child: item,
|
|
|
|
args: {
|
|
|
|
args: {
|
|
|
|
item_code: item.item_code,
|
|
|
|
barcode: item.barcode,
|
|
|
|
serial_no: item.serial_no,
|
|
|
|
warehouse: item.warehouse,
|
2014-06-20 10:29:49 +00:00
|
|
|
parenttype: me.frm.doc.doctype,
|
|
|
|
parent: me.frm.doc.name,
|
2014-02-12 09:23:18 +00:00
|
|
|
customer: me.frm.doc.customer,
|
|
|
|
supplier: me.frm.doc.supplier,
|
|
|
|
currency: me.frm.doc.currency,
|
|
|
|
conversion_rate: me.frm.doc.conversion_rate,
|
|
|
|
price_list: me.frm.doc.selling_price_list ||
|
|
|
|
me.frm.doc.buying_price_list,
|
|
|
|
price_list_currency: me.frm.doc.price_list_currency,
|
|
|
|
plc_conversion_rate: me.frm.doc.plc_conversion_rate,
|
|
|
|
company: me.frm.doc.company,
|
|
|
|
order_type: me.frm.doc.order_type,
|
|
|
|
is_pos: cint(me.frm.doc.is_pos),
|
|
|
|
is_subcontracted: me.frm.doc.is_subcontracted,
|
2015-03-09 09:24:37 +00:00
|
|
|
transaction_date: me.frm.doc.transaction_date || me.frm.doc.posting_date,
|
2014-06-20 10:29:49 +00:00
|
|
|
ignore_pricing_rule: me.frm.doc.ignore_pricing_rule,
|
|
|
|
doctype: item.doctype,
|
2014-08-26 08:55:53 +00:00
|
|
|
name: item.name,
|
2015-01-05 10:49:12 +00:00
|
|
|
project_name: item.project_name || me.frm.doc.project_name,
|
|
|
|
qty: item.qty
|
2014-02-12 09:23:18 +00:00
|
|
|
}
|
|
|
|
},
|
2014-09-21 14:15:49 +00:00
|
|
|
|
2014-02-12 09:23:18 +00:00
|
|
|
callback: function(r) {
|
|
|
|
if(!r.exc) {
|
|
|
|
me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-04-15 13:10:00 +00:00
|
|
|
},
|
2013-10-18 08:54:21 +00:00
|
|
|
|
|
|
|
serial_no: function(doc, cdt, cdn) {
|
|
|
|
var me = this;
|
2014-03-27 08:47:33 +00:00
|
|
|
var item = frappe.get_doc(cdt, cdn);
|
2013-10-18 08:54:21 +00:00
|
|
|
|
|
|
|
if (item.serial_no) {
|
|
|
|
if (!item.item_code) {
|
|
|
|
this.frm.script_manager.trigger("item_code", cdt, cdn);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var sr_no = [];
|
|
|
|
|
|
|
|
// Replacing all occurences of comma with carriage return
|
|
|
|
var serial_nos = item.serial_no.trim().replace(/,/g, '\n');
|
|
|
|
|
|
|
|
serial_nos = serial_nos.trim().split('\n');
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-10-18 08:54:21 +00:00
|
|
|
// Trim each string and push unique string to new list
|
|
|
|
for (var x=0; x<=serial_nos.length - 1; x++) {
|
|
|
|
if (serial_nos[x].trim() != "" && sr_no.indexOf(serial_nos[x].trim()) == -1) {
|
|
|
|
sr_no.push(serial_nos[x].trim());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the new list to the serial no. field in grid with each in new line
|
|
|
|
item.serial_no = "";
|
|
|
|
for (var x=0; x<=sr_no.length - 1; x++)
|
|
|
|
item.serial_no += sr_no[x] + '\n';
|
|
|
|
|
|
|
|
refresh_field("serial_no", item.name, item.parentfield);
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.model.set_value(item.doctype, item.name, "qty", sr_no.length);
|
2013-10-18 08:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-28 11:53:36 +00:00
|
|
|
validate: function() {
|
2014-04-16 09:51:46 +00:00
|
|
|
this.calculate_taxes_and_totals(false);
|
2013-05-28 11:53:36 +00:00
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-24 13:55:01 +00:00
|
|
|
company: function() {
|
2014-10-09 09:30:10 +00:00
|
|
|
var me = this;
|
|
|
|
var fn = function() {
|
|
|
|
if(me.frm.doc.company && me.frm.fields_dict.currency) {
|
|
|
|
var company_currency = me.get_company_currency();
|
2015-05-19 06:30:34 +00:00
|
|
|
var company_doc = frappe.get_doc(":Company", me.frm.doc.company);
|
2014-10-09 09:30:10 +00:00
|
|
|
if (!me.frm.doc.currency) {
|
|
|
|
me.frm.set_value("currency", company_currency);
|
|
|
|
}
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2014-10-09 09:30:10 +00:00
|
|
|
if (me.frm.doc.currency == company_currency) {
|
|
|
|
me.frm.set_value("conversion_rate", 1.0);
|
|
|
|
}
|
|
|
|
if (me.frm.doc.price_list_currency == company_currency) {
|
|
|
|
me.frm.set_value('plc_conversion_rate', 1.0);
|
|
|
|
}
|
2015-05-19 06:30:34 +00:00
|
|
|
if (company_doc.default_letter_head) {
|
2015-05-27 06:59:57 +00:00
|
|
|
if(me.frm.fields_dict.letter_head) {
|
|
|
|
me.frm.set_value("letter_head", company_doc.default_letter_head);
|
|
|
|
}
|
2015-05-19 06:30:34 +00:00
|
|
|
}
|
2015-05-27 06:59:57 +00:00
|
|
|
if (company_doc.default_terms && me.frm.doc.doctype != "Purchase Invoice") {
|
2015-05-19 06:30:34 +00:00
|
|
|
me.frm.set_value("tc_name", company_doc.default_terms);
|
|
|
|
}
|
2013-10-11 08:04:10 +00:00
|
|
|
|
2014-10-09 09:30:10 +00:00
|
|
|
me.frm.script_manager.trigger("currency");
|
|
|
|
me.apply_pricing_rule();
|
2013-10-11 13:36:30 +00:00
|
|
|
}
|
2013-05-24 13:55:01 +00:00
|
|
|
}
|
2013-10-11 08:04:10 +00:00
|
|
|
|
2014-10-09 09:30:10 +00:00
|
|
|
if (this.frm.doc.posting_date) var date = this.frm.doc.posting_date;
|
|
|
|
else var date = this.frm.doc.transaction_date;
|
|
|
|
erpnext.get_fiscal_year(this.frm.doc.company, date, fn);
|
2015-04-28 10:32:09 +00:00
|
|
|
|
|
|
|
if(this.frm.doc.company) {
|
|
|
|
erpnext.last_selected_company = this.frm.doc.company;
|
2013-05-24 13:55:01 +00:00
|
|
|
}
|
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2014-10-09 09:30:10 +00:00
|
|
|
transaction_date: function() {
|
|
|
|
erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.transaction_date);
|
2014-10-03 12:13:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
posting_date: function() {
|
2014-10-07 12:56:39 +00:00
|
|
|
erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.posting_date);
|
2013-05-24 13:55:01 +00:00
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-24 13:55:01 +00:00
|
|
|
get_company_currency: function() {
|
|
|
|
return erpnext.get_currency(this.frm.doc.company);
|
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-24 13:55:01 +00:00
|
|
|
currency: function() {
|
2013-06-21 12:25:31 +00:00
|
|
|
var me = this;
|
|
|
|
this.set_dynamic_labels();
|
2013-10-11 13:36:30 +00:00
|
|
|
|
2013-06-21 12:25:31 +00:00
|
|
|
var company_currency = this.get_company_currency();
|
2015-05-02 13:15:02 +00:00
|
|
|
// Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
|
|
|
|
if(this.frm.doc.currency !== company_currency && !this.frm.doc.ignore_pricing_rule) {
|
2014-04-15 13:10:00 +00:00
|
|
|
this.get_exchange_rate(this.frm.doc.currency, company_currency,
|
2013-06-21 12:25:31 +00:00
|
|
|
function(exchange_rate) {
|
2013-10-11 13:36:30 +00:00
|
|
|
me.frm.set_value("conversion_rate", exchange_rate);
|
2013-06-21 12:25:31 +00:00
|
|
|
});
|
|
|
|
} else {
|
2014-04-15 13:10:00 +00:00
|
|
|
this.conversion_rate();
|
2013-06-21 12:25:31 +00:00
|
|
|
}
|
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-06-21 12:25:31 +00:00
|
|
|
conversion_rate: function() {
|
2013-07-19 08:21:07 +00:00
|
|
|
if(this.frm.doc.currency === this.get_company_currency()) {
|
|
|
|
this.frm.set_value("conversion_rate", 1.0);
|
2013-10-17 07:34:26 +00:00
|
|
|
}
|
|
|
|
if(this.frm.doc.currency === this.frm.doc.price_list_currency &&
|
2013-06-21 12:25:31 +00:00
|
|
|
this.frm.doc.plc_conversion_rate !== this.frm.doc.conversion_rate) {
|
|
|
|
this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate);
|
|
|
|
}
|
2015-05-19 05:40:12 +00:00
|
|
|
|
2014-05-28 07:19:20 +00:00
|
|
|
if(flt(this.frm.doc.conversion_rate)>0.0) {
|
2014-06-20 10:29:49 +00:00
|
|
|
if(this.frm.doc.ignore_pricing_rule) {
|
|
|
|
this.calculate_taxes_and_totals();
|
2014-07-04 10:14:26 +00:00
|
|
|
} else if (!this.in_apply_price_list){
|
|
|
|
this.apply_price_list();
|
2014-06-20 10:29:49 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 07:19:20 +00:00
|
|
|
}
|
2013-05-24 13:55:01 +00:00
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-06-21 12:25:31 +00:00
|
|
|
get_exchange_rate: function(from_currency, to_currency, callback) {
|
2015-05-07 06:55:33 +00:00
|
|
|
frappe.call({
|
|
|
|
method: "erpnext.setup.utils.get_exchange_rate",
|
|
|
|
args: {
|
|
|
|
from_currency: from_currency,
|
|
|
|
to_currency: to_currency
|
|
|
|
},
|
|
|
|
callback: function(r) {
|
|
|
|
callback(flt(r.message));
|
|
|
|
}
|
2013-06-21 12:25:31 +00:00
|
|
|
});
|
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-24 13:55:01 +00:00
|
|
|
price_list_currency: function() {
|
2013-09-11 07:35:24 +00:00
|
|
|
var me=this;
|
2013-06-21 12:25:31 +00:00
|
|
|
this.set_dynamic_labels();
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2015-05-11 12:44:45 +00:00
|
|
|
var company_currency = this.get_company_currency();
|
|
|
|
// Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
|
|
|
|
if(this.frm.doc.price_list_currency !== company_currency && !this.frm.doc.ignore_pricing_rule) {
|
|
|
|
this.get_exchange_rate(this.frm.doc.price_list_currency, company_currency,
|
|
|
|
function(exchange_rate) {
|
|
|
|
me.frm.set_value("plc_conversion_rate", exchange_rate);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.plc_conversion_rate();
|
2013-05-24 13:55:01 +00:00
|
|
|
}
|
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2015-05-11 12:44:45 +00:00
|
|
|
plc_conversion_rate: function() {
|
2013-06-21 12:25:31 +00:00
|
|
|
if(this.frm.doc.price_list_currency === this.get_company_currency()) {
|
|
|
|
this.frm.set_value("plc_conversion_rate", 1.0);
|
2015-05-11 12:44:45 +00:00
|
|
|
} else if(this.frm.doc.price_list_currency === this.frm.doc.currency && this.frm.doc.plc_conversion_rate && cint(this.frm.doc.plc_conversion_rate) != 1 &&
|
|
|
|
cint(this.frm.doc.plc_conversion_rate) != cint(this.frm.doc.conversion_rate)) {
|
|
|
|
this.frm.set_value("conversion_rate", this.frm.doc.plc_conversion_rate);
|
2013-10-17 06:01:11 +00:00
|
|
|
}
|
2015-05-19 05:40:12 +00:00
|
|
|
|
2015-05-11 12:44:45 +00:00
|
|
|
if(!this.in_apply_price_list) {
|
|
|
|
this.apply_price_list();
|
2013-06-21 12:25:31 +00:00
|
|
|
}
|
2013-05-24 13:55:01 +00:00
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-24 13:55:01 +00:00
|
|
|
qty: function(doc, cdt, cdn) {
|
2014-06-20 10:29:49 +00:00
|
|
|
this.apply_pricing_rule(frappe.get_doc(cdt, cdn), true);
|
2013-05-24 13:55:01 +00:00
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-06-21 12:25:31 +00:00
|
|
|
set_dynamic_labels: function() {
|
|
|
|
// What TODO? should we make price list system non-mandatory?
|
|
|
|
this.frm.toggle_reqd("plc_conversion_rate",
|
|
|
|
!!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency));
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-06-21 12:25:31 +00:00
|
|
|
var company_currency = this.get_company_currency();
|
|
|
|
this.change_form_labels(company_currency);
|
|
|
|
this.change_grid_labels(company_currency);
|
2013-08-05 06:46:04 +00:00
|
|
|
this.frm.refresh_fields();
|
2013-06-21 12:25:31 +00:00
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2015-02-23 06:28:15 +00:00
|
|
|
change_form_labels: function(company_currency) {
|
|
|
|
var me = this;
|
|
|
|
var field_label_map = {};
|
|
|
|
|
|
|
|
var setup_field_label_map = function(fields_list, currency) {
|
|
|
|
$.each(fields_list, function(i, fname) {
|
|
|
|
var docfield = frappe.meta.docfield_map[me.frm.doc.doctype][fname];
|
|
|
|
if(docfield) {
|
|
|
|
var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
|
|
|
|
field_label_map[fname] = label.trim() + " (" + currency + ")";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
setup_field_label_map(["base_total", "base_net_total", "base_total_taxes_and_charges",
|
|
|
|
"base_discount_amount", "base_grand_total", "base_rounded_total", "base_in_words",
|
|
|
|
"base_taxes_and_charges_added", "base_taxes_and_charges_deducted", "total_amount_to_pay",
|
2015-02-23 10:31:33 +00:00
|
|
|
"outstanding_amount", "total_advance", "paid_amount", "write_off_amount"], company_currency);
|
2015-02-23 06:28:15 +00:00
|
|
|
|
|
|
|
setup_field_label_map(["total", "net_total", "total_taxes_and_charges", "discount_amount",
|
|
|
|
"grand_total", "taxes_and_charges_added", "taxes_and_charges_deducted",
|
|
|
|
"rounded_total", "in_words"], this.frm.doc.currency);
|
|
|
|
|
|
|
|
cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
|
|
|
|
+ " = [?] " + company_currency)
|
|
|
|
|
|
|
|
if(this.frm.doc.price_list_currency && this.frm.doc.price_list_currency!=company_currency) {
|
|
|
|
cur_frm.set_df_property("plc_conversion_rate", "description", "1 " + this.frm.doc.price_list_currency
|
|
|
|
+ " = [?] " + company_currency)
|
|
|
|
}
|
|
|
|
|
|
|
|
// toggle fields
|
|
|
|
this.frm.toggle_display(["conversion_rate", "base_total", "base_net_total", "base_total_taxes_and_charges",
|
|
|
|
"base_taxes_and_charges_added", "base_taxes_and_charges_deducted",
|
|
|
|
"base_grand_total", "base_rounded_total", "base_in_words", "base_discount_amount"],
|
|
|
|
this.frm.doc.currency != company_currency);
|
|
|
|
|
|
|
|
this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],
|
|
|
|
this.frm.doc.price_list_currency != company_currency);
|
|
|
|
|
|
|
|
// set labels
|
|
|
|
$.each(field_label_map, function(fname, label) {
|
|
|
|
me.frm.fields_dict[fname].set_label(label);
|
|
|
|
});
|
2015-02-23 10:31:33 +00:00
|
|
|
|
2015-02-24 09:54:49 +00:00
|
|
|
var show =cint(cur_frm.doc.discount_amount) ||
|
|
|
|
((cur_frm.doc.taxes || []).filter(function(d) {return d.included_in_print_rate===1}).length);
|
|
|
|
|
|
|
|
if(frappe.meta.get_docfield(cur_frm.doctype, "net_total"))
|
|
|
|
cur_frm.toggle_display("net_total", show);
|
|
|
|
|
|
|
|
if(frappe.meta.get_docfield(cur_frm.doctype, "base_net_total"))
|
|
|
|
cur_frm.toggle_display("base_net_total", (show && (me.frm.doc.currency != company_currency)));
|
|
|
|
|
2015-02-23 06:28:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
change_grid_labels: function(company_currency) {
|
|
|
|
var me = this;
|
|
|
|
var field_label_map = {};
|
|
|
|
|
|
|
|
var setup_field_label_map = function(fields_list, currency, parentfield) {
|
|
|
|
var grid_doctype = me.frm.fields_dict[parentfield].grid.doctype;
|
|
|
|
$.each(fields_list, function(i, fname) {
|
|
|
|
var docfield = frappe.meta.docfield_map[grid_doctype][fname];
|
|
|
|
if(docfield) {
|
|
|
|
var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
|
|
|
|
field_label_map[grid_doctype + "-" + fname] =
|
|
|
|
label.trim() + " (" + currency + ")";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_field_label_map(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount"],
|
|
|
|
company_currency, "items");
|
|
|
|
|
|
|
|
setup_field_label_map(["rate", "net_rate", "price_list_rate", "amount", "net_amount"],
|
|
|
|
this.frm.doc.currency, "items");
|
|
|
|
|
|
|
|
if(this.frm.fields_dict["taxes"]) {
|
|
|
|
setup_field_label_map(["tax_amount", "total", "tax_amount_after_discount"], this.frm.doc.currency, "taxes");
|
|
|
|
|
|
|
|
setup_field_label_map(["base_tax_amount", "base_total", "base_tax_amount_after_discount"], company_currency, "taxes");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this.frm.fields_dict["advances"]) {
|
|
|
|
setup_field_label_map(["advance_amount", "allocated_amount"], company_currency, "advances");
|
|
|
|
}
|
|
|
|
|
|
|
|
// toggle columns
|
|
|
|
var item_grid = this.frm.fields_dict["items"].grid;
|
|
|
|
$.each(["base_rate", "base_price_list_rate", "base_amount"], function(i, fname) {
|
|
|
|
if(frappe.meta.get_docfield(item_grid.doctype, fname))
|
|
|
|
item_grid.set_column_disp(fname, me.frm.doc.currency != company_currency);
|
|
|
|
});
|
|
|
|
|
|
|
|
var show = (cint(cur_frm.doc.discount_amount)) ||
|
|
|
|
((cur_frm.doc.taxes || []).filter(function(d) {return d.included_in_print_rate===1}).length);
|
|
|
|
|
|
|
|
$.each(["net_rate", "net_amount"], function(i, fname) {
|
|
|
|
if(frappe.meta.get_docfield(item_grid.doctype, fname))
|
|
|
|
item_grid.set_column_disp(fname, show);
|
|
|
|
});
|
|
|
|
|
|
|
|
$.each(["base_net_rate", "base_net_amount"], function(i, fname) {
|
|
|
|
if(frappe.meta.get_docfield(item_grid.doctype, fname))
|
|
|
|
item_grid.set_column_disp(fname, (show && (me.frm.doc.currency != company_currency)));
|
|
|
|
});
|
|
|
|
|
|
|
|
// set labels
|
|
|
|
var $wrapper = $(this.frm.wrapper);
|
|
|
|
$.each(field_label_map, function(fname, label) {
|
|
|
|
fname = fname.split("-");
|
|
|
|
var df = frappe.meta.get_docfield(fname[0], fname[1], me.frm.doc.name);
|
|
|
|
if(df) df.label = label;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-05-28 11:53:36 +00:00
|
|
|
recalculate: function() {
|
|
|
|
this.calculate_taxes_and_totals();
|
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-28 11:53:36 +00:00
|
|
|
recalculate_values: function() {
|
|
|
|
this.calculate_taxes_and_totals();
|
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-28 13:24:48 +00:00
|
|
|
calculate_charges: function() {
|
|
|
|
this.calculate_taxes_and_totals();
|
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2014-06-20 10:29:49 +00:00
|
|
|
ignore_pricing_rule: function() {
|
|
|
|
this.apply_pricing_rule();
|
|
|
|
},
|
2014-05-28 07:19:20 +00:00
|
|
|
|
2014-06-20 10:29:49 +00:00
|
|
|
apply_pricing_rule: function(item, calculate_taxes_and_totals) {
|
|
|
|
var me = this;
|
2014-07-01 12:15:15 +00:00
|
|
|
return this.frm.call({
|
|
|
|
method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.apply_pricing_rule",
|
|
|
|
args: { args: this._get_args(item) },
|
|
|
|
callback: function(r) {
|
2014-07-16 12:22:08 +00:00
|
|
|
if (!r.exc && r.message) {
|
2014-07-01 12:15:15 +00:00
|
|
|
me._set_values_for_item_list(r.message);
|
|
|
|
if(calculate_taxes_and_totals) me.calculate_taxes_and_totals();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_get_args: function(item) {
|
|
|
|
var me = this;
|
|
|
|
return {
|
|
|
|
"item_list": this._get_item_list(item),
|
2014-06-20 10:29:49 +00:00
|
|
|
"customer": me.frm.doc.customer,
|
|
|
|
"customer_group": me.frm.doc.customer_group,
|
|
|
|
"territory": me.frm.doc.territory,
|
|
|
|
"supplier": me.frm.doc.supplier,
|
|
|
|
"supplier_type": me.frm.doc.supplier_type,
|
|
|
|
"currency": me.frm.doc.currency,
|
|
|
|
"conversion_rate": me.frm.doc.conversion_rate,
|
|
|
|
"price_list": me.frm.doc.selling_price_list || me.frm.doc.buying_price_list,
|
2015-05-11 11:19:17 +00:00
|
|
|
"price_list_currency": me.frm.doc.price_list_currency,
|
2014-06-20 10:29:49 +00:00
|
|
|
"plc_conversion_rate": me.frm.doc.plc_conversion_rate,
|
|
|
|
"company": me.frm.doc.company,
|
|
|
|
"transaction_date": me.frm.doc.transaction_date || me.frm.doc.posting_date,
|
|
|
|
"campaign": me.frm.doc.campaign,
|
|
|
|
"sales_partner": me.frm.doc.sales_partner,
|
|
|
|
"ignore_pricing_rule": me.frm.doc.ignore_pricing_rule,
|
|
|
|
"parenttype": me.frm.doc.doctype,
|
|
|
|
"parent": me.frm.doc.name
|
|
|
|
};
|
|
|
|
},
|
2014-05-28 07:19:20 +00:00
|
|
|
|
2014-06-20 10:29:49 +00:00
|
|
|
_get_item_list: function(item) {
|
|
|
|
var item_list = [];
|
|
|
|
var append_item = function(d) {
|
2014-07-28 10:30:19 +00:00
|
|
|
if (d.item_code) {
|
|
|
|
item_list.push({
|
|
|
|
"doctype": d.doctype,
|
|
|
|
"name": d.name,
|
|
|
|
"item_code": d.item_code,
|
|
|
|
"item_group": d.item_group,
|
|
|
|
"brand": d.brand,
|
|
|
|
"qty": d.qty
|
|
|
|
});
|
|
|
|
}
|
2014-06-20 10:29:49 +00:00
|
|
|
};
|
2014-05-28 07:19:20 +00:00
|
|
|
|
2014-06-20 10:29:49 +00:00
|
|
|
if (item) {
|
|
|
|
append_item(item);
|
2014-05-30 06:13:00 +00:00
|
|
|
} else {
|
2015-01-21 11:52:11 +00:00
|
|
|
$.each(this.frm.doc["items"] || [], function(i, d) {
|
2014-06-20 10:29:49 +00:00
|
|
|
append_item(d);
|
2014-05-28 07:19:20 +00:00
|
|
|
});
|
|
|
|
}
|
2014-06-20 10:29:49 +00:00
|
|
|
return item_list;
|
2014-05-28 07:19:20 +00:00
|
|
|
},
|
|
|
|
|
2014-07-01 12:15:15 +00:00
|
|
|
_set_values_for_item_list: function(children) {
|
2014-12-17 05:51:32 +00:00
|
|
|
var me = this;
|
2014-12-30 10:05:45 +00:00
|
|
|
var price_list_rate_changed = false;
|
2015-02-05 09:35:58 +00:00
|
|
|
for(var i=0, l=children.length; i<l; i++) {
|
|
|
|
var d = children[i];
|
2014-12-17 05:51:32 +00:00
|
|
|
var existing_pricing_rule = frappe.model.get_value(d.doctype, d.name, "pricing_rule");
|
2015-02-05 09:35:58 +00:00
|
|
|
|
|
|
|
for(var k in d) {
|
|
|
|
var v = d[k];
|
2014-07-01 12:15:15 +00:00
|
|
|
if (["doctype", "name"].indexOf(k)===-1) {
|
2014-12-30 10:05:45 +00:00
|
|
|
if(k=="price_list_rate") {
|
|
|
|
if(flt(v) != flt(d.price_list_rate)) price_list_rate_changed = true;
|
|
|
|
}
|
2014-07-01 12:15:15 +00:00
|
|
|
frappe.model.set_value(d.doctype, d.name, k, v);
|
|
|
|
}
|
2015-02-05 09:35:58 +00:00
|
|
|
}
|
|
|
|
|
2014-12-17 05:51:32 +00:00
|
|
|
// if pricing rule set as blank from an existing value, apply price_list
|
2014-12-22 05:12:48 +00:00
|
|
|
if(!me.frm.doc.ignore_pricing_rule && existing_pricing_rule && !d.pricing_rule) {
|
2014-12-17 05:51:32 +00:00
|
|
|
me.apply_price_list(frappe.get_doc(d.doctype, d.name));
|
|
|
|
}
|
2015-02-05 09:35:58 +00:00
|
|
|
}
|
2014-12-30 10:05:45 +00:00
|
|
|
|
2015-02-05 09:35:58 +00:00
|
|
|
if(!price_list_rate_changed) me.calculate_taxes_and_totals();
|
2014-07-01 12:15:15 +00:00
|
|
|
},
|
|
|
|
|
2014-12-17 05:51:32 +00:00
|
|
|
apply_price_list: function(item) {
|
2014-07-01 12:15:15 +00:00
|
|
|
var me = this;
|
2015-01-30 11:27:24 +00:00
|
|
|
var args = this._get_args(item);
|
2015-02-23 10:31:33 +00:00
|
|
|
|
2014-07-01 12:15:15 +00:00
|
|
|
return this.frm.call({
|
|
|
|
method: "erpnext.stock.get_item_details.apply_price_list",
|
2015-01-30 11:27:24 +00:00
|
|
|
args: { args: args },
|
2014-07-01 12:15:15 +00:00
|
|
|
callback: function(r) {
|
|
|
|
if (!r.exc) {
|
2014-07-04 10:14:26 +00:00
|
|
|
me.in_apply_price_list = true;
|
2014-07-01 12:15:15 +00:00
|
|
|
me.frm.set_value("price_list_currency", r.message.parent.price_list_currency);
|
|
|
|
me.frm.set_value("plc_conversion_rate", r.message.parent.plc_conversion_rate);
|
2014-07-04 10:14:26 +00:00
|
|
|
me.in_apply_price_list = false;
|
2014-07-01 12:15:15 +00:00
|
|
|
|
2015-02-23 10:31:33 +00:00
|
|
|
if(args.item_list.length) {
|
|
|
|
me._set_values_for_item_list(r.message.children);
|
|
|
|
}
|
2013-05-24 13:55:01 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-01 12:15:15 +00:00
|
|
|
});
|
2013-05-24 13:55:01 +00:00
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-24 13:55:01 +00:00
|
|
|
get_item_wise_taxes_html: function() {
|
|
|
|
var item_tax = {};
|
|
|
|
var tax_accounts = [];
|
|
|
|
var company_currency = this.get_company_currency();
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2015-01-21 11:52:11 +00:00
|
|
|
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
|
2013-05-24 13:55:01 +00:00
|
|
|
var tax_amount_precision = precision("tax_amount", tax);
|
2013-05-31 06:20:01 +00:00
|
|
|
var tax_rate_precision = precision("rate", tax);
|
2014-04-15 13:10:00 +00:00
|
|
|
$.each(JSON.parse(tax.item_wise_tax_detail || '{}'),
|
2013-05-31 06:20:01 +00:00
|
|
|
function(item_code, tax_data) {
|
2013-05-24 13:55:01 +00:00
|
|
|
if(!item_tax[item_code]) item_tax[item_code] = {};
|
2013-05-31 06:20:01 +00:00
|
|
|
if($.isArray(tax_data)) {
|
2013-08-23 07:26:33 +00:00
|
|
|
var tax_rate = "";
|
|
|
|
if(tax_data[0] != null) {
|
|
|
|
tax_rate = (tax.charge_type === "Actual") ?
|
|
|
|
format_currency(flt(tax_data[0], tax_amount_precision), company_currency, tax_amount_precision) :
|
|
|
|
(flt(tax_data[0], tax_rate_precision) + "%");
|
|
|
|
}
|
|
|
|
var tax_amount = format_currency(flt(tax_data[1], tax_amount_precision), company_currency,
|
|
|
|
tax_amount_precision);
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-08-05 07:30:53 +00:00
|
|
|
item_tax[item_code][tax.name] = [tax_rate, tax_amount];
|
2013-05-31 06:20:01 +00:00
|
|
|
} else {
|
2013-08-05 07:30:53 +00:00
|
|
|
item_tax[item_code][tax.name] = [flt(tax_data, tax_rate_precision) + "%", ""];
|
2013-05-31 06:20:01 +00:00
|
|
|
}
|
2013-05-24 13:55:01 +00:00
|
|
|
});
|
2013-08-05 07:30:53 +00:00
|
|
|
tax_accounts.push([tax.name, tax.account_head]);
|
2013-05-24 13:55:01 +00:00
|
|
|
});
|
2014-04-15 13:10:00 +00:00
|
|
|
|
|
|
|
var headings = $.map([__("Item Name")].concat($.map(tax_accounts, function(head) { return head[1]; })),
|
2013-05-24 13:55:01 +00:00
|
|
|
function(head) { return '<th style="min-width: 100px;">' + (head || "") + "</th>" }).join("\n");
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-09-05 11:23:57 +00:00
|
|
|
var distinct_item_names = [];
|
|
|
|
var distinct_items = [];
|
2015-01-21 11:52:11 +00:00
|
|
|
$.each(this.frm.doc["items"] || [], function(i, item) {
|
2013-09-05 11:23:57 +00:00
|
|
|
if(distinct_item_names.indexOf(item.item_code || item.item_name)===-1) {
|
|
|
|
distinct_item_names.push(item.item_code || item.item_name);
|
|
|
|
distinct_items.push(item);
|
|
|
|
}
|
|
|
|
});
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-09-05 11:23:57 +00:00
|
|
|
var rows = $.map(distinct_items, function(item) {
|
2013-05-24 13:55:01 +00:00
|
|
|
var item_tax_record = item_tax[item.item_code || item.item_name];
|
2013-05-31 06:20:01 +00:00
|
|
|
if(!item_tax_record) { return null; }
|
2013-05-24 13:55:01 +00:00
|
|
|
return repl("<tr><td>%(item_name)s</td>%(taxes)s</tr>", {
|
|
|
|
item_name: item.item_name,
|
|
|
|
taxes: $.map(tax_accounts, function(head) {
|
2013-08-05 07:30:53 +00:00
|
|
|
return item_tax_record[head[0]] ?
|
|
|
|
"<td>(" + item_tax_record[head[0]][0] + ") " + item_tax_record[head[0]][1] + "</td>" :
|
2013-07-17 09:42:22 +00:00
|
|
|
"<td></td>";
|
2013-05-24 13:55:01 +00:00
|
|
|
}).join("\n")
|
|
|
|
});
|
|
|
|
}).join("\n");
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-05-31 06:20:01 +00:00
|
|
|
if(!rows) return "";
|
2013-11-08 10:57:18 +00:00
|
|
|
return '<p><a href="#" onclick="$(\'.tax-break-up\').toggleClass(\'hide\'); return false;">Show / Hide tax break-up</a><br><br></p>\
|
|
|
|
<div class="tax-break-up hide" style="overflow-x: auto;"><table class="table table-bordered table-hover">\
|
2013-05-24 13:55:01 +00:00
|
|
|
<thead><tr>' + headings + '</tr></thead> \
|
|
|
|
<tbody>' + rows + '</tbody> \
|
|
|
|
</table></div>';
|
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2014-02-12 09:23:18 +00:00
|
|
|
validate_company_and_party: function() {
|
2013-05-28 11:53:36 +00:00
|
|
|
var me = this;
|
2013-05-24 13:55:01 +00:00
|
|
|
var valid = true;
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2014-02-20 05:57:47 +00:00
|
|
|
$.each(["company", "customer"], function(i, fieldname) {
|
2014-02-14 10:17:51 +00:00
|
|
|
if(frappe.meta.has_field(me.frm.doc.doctype, fieldname)) {
|
2014-02-12 09:23:18 +00:00
|
|
|
if (!me.frm.doc[fieldname]) {
|
2014-04-15 13:10:00 +00:00
|
|
|
msgprint(__("Please specify") + ": " +
|
|
|
|
frappe.meta.get_label(me.frm.doc.doctype, fieldname, me.frm.doc.name) +
|
2014-04-14 10:55:30 +00:00
|
|
|
". " + __("It is needed to fetch Item Details."));
|
2014-02-12 09:23:18 +00:00
|
|
|
valid = false;
|
|
|
|
}
|
2013-05-24 13:55:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return valid;
|
|
|
|
},
|
2014-04-15 13:10:00 +00:00
|
|
|
|
2013-06-05 08:41:32 +00:00
|
|
|
get_terms: function() {
|
|
|
|
var me = this;
|
|
|
|
if(this.frm.doc.tc_name) {
|
2013-07-29 14:00:39 +00:00
|
|
|
return this.frm.call({
|
2014-02-14 10:17:51 +00:00
|
|
|
method: "frappe.client.get_value",
|
2013-06-05 08:41:32 +00:00
|
|
|
args: {
|
|
|
|
doctype: "Terms and Conditions",
|
|
|
|
fieldname: "terms",
|
|
|
|
filters: { name: this.frm.doc.tc_name },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2014-01-29 11:01:38 +00:00
|
|
|
|
|
|
|
taxes_and_charges: function() {
|
|
|
|
var me = this;
|
|
|
|
if(this.frm.doc.taxes_and_charges) {
|
|
|
|
return this.frm.call({
|
2014-05-02 10:15:10 +00:00
|
|
|
method: "erpnext.controllers.accounts_controller.get_taxes_and_charges",
|
|
|
|
args: {
|
2014-05-13 11:08:31 +00:00
|
|
|
"master_doctype": frappe.meta.get_docfield(this.frm.doc.doctype, "taxes_and_charges",
|
|
|
|
this.frm.doc.name).options,
|
2014-05-02 10:15:10 +00:00
|
|
|
"master_name": this.frm.doc.taxes_and_charges,
|
|
|
|
},
|
2014-01-29 11:01:38 +00:00
|
|
|
callback: function(r) {
|
|
|
|
if(!r.exc) {
|
2014-12-26 07:45:21 +00:00
|
|
|
me.frm.set_value("taxes", r.message);
|
2014-01-29 11:01:38 +00:00
|
|
|
me.calculate_taxes_and_totals();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-05-02 11:33:18 +00:00
|
|
|
}
|
2014-01-29 11:01:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
show_item_wise_taxes: function() {
|
|
|
|
if(this.frm.fields_dict.other_charges_calculation) {
|
2015-02-04 13:22:35 +00:00
|
|
|
var html = this.get_item_wise_taxes_html();
|
|
|
|
if (html) {
|
|
|
|
this.frm.toggle_display("other_charges_calculation", true);
|
|
|
|
$(this.frm.fields_dict.other_charges_calculation.wrapper).html(html);
|
|
|
|
} else {
|
|
|
|
this.frm.toggle_display("other_charges_calculation", false);
|
|
|
|
}
|
2014-01-29 11:01:38 +00:00
|
|
|
}
|
|
|
|
},
|
2014-09-21 14:15:49 +00:00
|
|
|
|
|
|
|
is_recurring: function() {
|
|
|
|
// set default values for recurring documents
|
|
|
|
if(this.frm.doc.is_recurring) {
|
|
|
|
var owner_email = this.frm.doc.owner=="Administrator"
|
|
|
|
? frappe.user_info("Administrator").email
|
|
|
|
: this.frm.doc.owner;
|
|
|
|
|
|
|
|
this.frm.doc.notification_email_address = $.map([cstr(owner_email),
|
|
|
|
cstr(this.frm.doc.contact_email)], function(v) { return v || null; }).join(", ");
|
|
|
|
this.frm.doc.repeat_on_day_of_month = frappe.datetime.str_to_obj(this.frm.doc.posting_date).getDate();
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh_many(["notification_email_address", "repeat_on_day_of_month"]);
|
|
|
|
},
|
|
|
|
|
|
|
|
from_date: function() {
|
|
|
|
// set to_date
|
|
|
|
if(this.frm.doc.from_date) {
|
|
|
|
var recurring_type_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6,
|
|
|
|
'Yearly': 12};
|
|
|
|
|
|
|
|
var months = recurring_type_map[this.frm.doc.recurring_type];
|
|
|
|
if(months) {
|
|
|
|
var to_date = frappe.datetime.add_months(this.frm.doc.from_date,
|
|
|
|
months);
|
|
|
|
this.frm.doc.to_date = frappe.datetime.add_days(to_date, -1);
|
|
|
|
refresh_field('to_date');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-15 13:10:00 +00:00
|
|
|
});
|
2015-02-22 14:44:49 +00:00
|
|
|
|
2015-02-24 11:38:34 +00:00
|
|
|
frappe.ui.form.on(cur_frm.doctype + " Item", "rate", function(frm, cdt, cdn) {
|
2015-02-22 14:44:49 +00:00
|
|
|
var item = frappe.get_doc(cdt, cdn);
|
|
|
|
frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
|
|
|
|
|
|
|
|
if(item.price_list_rate) {
|
|
|
|
item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0, precision("discount_percentage", item));
|
|
|
|
} else {
|
|
|
|
item.discount_percentage = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_frm.cscript.calculate_taxes_and_totals();
|
|
|
|
})
|
2015-02-23 06:28:15 +00:00
|
|
|
|
|
|
|
frappe.ui.form.on(cur_frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
|
|
|
|
cur_frm.cscript.calculate_taxes_and_totals();
|
|
|
|
})
|
|
|
|
|
|
|
|
frappe.ui.form.on(cur_frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
|
|
|
|
cur_frm.cscript.calculate_taxes_and_totals();
|
|
|
|
})
|
|
|
|
|
|
|
|
frappe.ui.form.on(cur_frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
|
|
|
|
cur_frm.cscript.calculate_taxes_and_totals();
|
|
|
|
})
|
|
|
|
|
|
|
|
frappe.ui.form.on(cur_frm.cscript.tax_table, "included_in_print_rate", function(frm, cdt, cdn) {
|
2015-02-24 09:54:49 +00:00
|
|
|
cur_frm.cscript.set_dynamic_labels();
|
2015-02-23 06:28:15 +00:00
|
|
|
cur_frm.cscript.calculate_taxes_and_totals();
|
|
|
|
})
|
2015-02-23 10:31:33 +00:00
|
|
|
|
|
|
|
frappe.ui.form.on(cur_frm.doctype, "apply_discount_on", function(frm) {
|
|
|
|
cur_frm.cscript.calculate_taxes_and_totals();
|
|
|
|
})
|
|
|
|
|
|
|
|
frappe.ui.form.on(cur_frm.doctype, "discount_amount", function(frm) {
|
2015-02-24 09:54:49 +00:00
|
|
|
cur_frm.cscript.set_dynamic_labels();
|
2015-02-23 10:31:33 +00:00
|
|
|
cur_frm.cscript.calculate_taxes_and_totals();
|
|
|
|
})
|