refactor: Replace Class.extend with native class
diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js
index 67b12fb..8ceae83 100644
--- a/erpnext/public/js/controllers/buying.js
+++ b/erpnext/public/js/controllers/buying.js
@@ -9,14 +9,14 @@
cur_frm.email_field = "contact_email";
-erpnext.buying.BuyingController = erpnext.TransactionController.extend({
- setup: function() {
- this._super();
- },
+erpnext.buying.BuyingController = class BuyingController extends erpnext.TransactionController {
+ setup() {
+ super.setup();
+ }
- onload: function(doc, cdt, cdn) {
+ onload(doc, cdt, cdn) {
this.setup_queries(doc, cdt, cdn);
- this._super();
+ super.onload();
this.frm.set_query('shipping_rule', function() {
return {
@@ -48,9 +48,9 @@
});
}
/* eslint-enable */
- },
+ }
- setup_queries: function(doc, cdt, cdn) {
+ setup_queries(doc, cdt, cdn) {
var me = this;
if(this.frm.fields_dict.buying_price_list) {
@@ -109,9 +109,9 @@
return me.set_query_for_item_tax_template(doc, cdt, cdn)
});
}
- },
+ }
- refresh: function(doc) {
+ refresh(doc) {
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier'};
this.frm.toggle_display("supplier_name",
@@ -122,38 +122,38 @@
this.set_from_product_bundle();
}
- this._super();
- },
+ super.refresh();
+ }
- supplier: function() {
+ supplier() {
var me = this;
erpnext.utils.get_party_details(this.frm, null, null, function(){
me.apply_price_list();
});
- },
+ }
- supplier_address: function() {
+ supplier_address() {
erpnext.utils.get_address_display(this.frm);
erpnext.utils.set_taxes_from_address(this.frm, "supplier_address", "supplier_address", "supplier_address");
- },
+ }
- buying_price_list: function() {
+ buying_price_list() {
this.apply_price_list();
- },
+ }
- discount_percentage: function(doc, cdt, cdn) {
+ discount_percentage(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
item.discount_amount = 0.0;
this.price_list_rate(doc, cdt, cdn);
- },
+ }
- discount_amount: function(doc, cdt, cdn) {
+ discount_amount(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
item.discount_percentage = 0.0;
this.price_list_rate(doc, cdt, cdn);
- },
+ }
- qty: function(doc, cdt, cdn) {
+ qty(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && (doc.update_stock || doc.is_return))) {
frappe.model.round_floats_in(item, ["qty", "received_qty"]);
@@ -168,22 +168,22 @@
item.rejected_qty = flt(item.received_qty - item.qty, precision("rejected_qty", item));
item.received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(item.received_qty);
}
- this._super(doc, cdt, cdn);
- },
+ super.qty(doc, cdt, cdn);
+ }
- batch_no: function(doc, cdt, cdn) {
- this._super(doc, cdt, cdn);
- },
+ batch_no(doc, cdt, cdn) {
+ super.batch_no(doc, cdt, cdn);
+ }
- received_qty: function(doc, cdt, cdn) {
+ received_qty(doc, cdt, cdn) {
this.calculate_accepted_qty(doc, cdt, cdn)
- },
+ }
- rejected_qty: function(doc, cdt, cdn) {
+ rejected_qty(doc, cdt, cdn) {
this.calculate_accepted_qty(doc, cdt, cdn)
- },
+ }
- calculate_accepted_qty: function(doc, cdt, cdn){
+ calculate_accepted_qty(doc, cdt, cdn){
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["received_qty", "rejected_qty"]);
@@ -191,9 +191,9 @@
item.qty = flt(item.received_qty - item.rejected_qty, precision("qty", item));
this.qty(doc, cdt, cdn);
- },
+ }
- validate_negative_quantity: function(cdt, cdn, item, fieldnames){
+ validate_negative_quantity(cdt, cdn, item, fieldnames){
if(!item || !fieldnames) { return }
var is_negative_qty = false;
@@ -206,9 +206,9 @@
}
return is_negative_qty
- },
+ }
- warehouse: function(doc, cdt, cdn) {
+ warehouse(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
if(item.item_code && item.warehouse) {
return this.frm.call({
@@ -220,9 +220,9 @@
}
});
}
- },
+ }
- project: function(doc, cdt, cdn) {
+ project(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
if(item.project) {
$.each(this.frm.doc["items"] || [],
@@ -233,48 +233,48 @@
}
});
}
- },
+ }
- rejected_warehouse: function(doc, cdt) {
+ rejected_warehouse(doc, cdt) {
// trigger autofill_warehouse only if parent rejected_warehouse field is triggered
if (["Purchase Invoice", "Purchase Receipt"].includes(cdt)) {
this.autofill_warehouse(doc.items, "rejected_warehouse", doc.rejected_warehouse);
}
- },
+ }
- category: function(doc, cdt, cdn) {
+ category(doc, cdt, cdn) {
// should be the category field of tax table
if(cdt != doc.doctype) {
this.calculate_taxes_and_totals();
}
- },
- add_deduct_tax: function(doc, cdt, cdn) {
+ }
+ add_deduct_tax(doc, cdt, cdn) {
this.calculate_taxes_and_totals();
- },
+ }
- set_from_product_bundle: function() {
+ set_from_product_bundle() {
var me = this;
this.frm.add_custom_button(__("Product Bundle"), function() {
erpnext.buying.get_items_from_product_bundle(me.frm);
}, __("Get Items From"));
- },
+ }
- shipping_address: function(){
+ shipping_address(){
var me = this;
erpnext.utils.get_address_display(this.frm, "shipping_address",
"shipping_address_display", true);
- },
+ }
- billing_address: function() {
+ billing_address() {
erpnext.utils.get_address_display(this.frm, "billing_address",
"billing_address_display", true);
- },
+ }
- tc_name: function() {
+ tc_name() {
this.get_terms();
- },
+ }
- update_auto_repeat_reference: function(doc) {
+ update_auto_repeat_reference(doc) {
if (doc.auto_repeat) {
frappe.call({
method:"frappe.automation.doctype.auto_repeat.auto_repeat.update_reference",
@@ -291,9 +291,9 @@
}
})
}
- },
+ }
- manufacturer: function(doc, cdt, cdn) {
+ manufacturer(doc, cdt, cdn) {
const row = locals[cdt][cdn];
if(row.manufacturer) {
@@ -310,9 +310,9 @@
}
});
}
- },
+ }
- manufacturer_part_no: function(doc, cdt, cdn) {
+ manufacturer_part_no(doc, cdt, cdn) {
const row = locals[cdt][cdn];
if (row.manufacturer_part_no) {
@@ -335,7 +335,7 @@
}
}
-});
+};
cur_frm.add_fetch('project', 'cost_center', 'cost_center');
@@ -496,4 +496,4 @@
});
dialog.show();
-}
\ No newline at end of file
+}
diff --git a/erpnext/public/js/controllers/stock_controller.js b/erpnext/public/js/controllers/stock_controller.js
index 87b21b7..d346357 100644
--- a/erpnext/public/js/controllers/stock_controller.js
+++ b/erpnext/public/js/controllers/stock_controller.js
@@ -3,22 +3,22 @@
frappe.provide("erpnext.stock");
-erpnext.stock.StockController = frappe.ui.form.Controller.extend({
- onload: function() {
+erpnext.stock.StockController = class StockController extends frappe.ui.form.Controller {
+ onload() {
// warehouse query if company
if (this.frm.fields_dict.company) {
this.setup_warehouse_query();
}
- },
+ }
- setup_warehouse_query: function() {
+ setup_warehouse_query() {
var me = this;
erpnext.queries.setup_queries(this.frm, "Warehouse", function() {
return erpnext.queries.warehouse(me.frm.doc);
});
- },
+ }
- setup_posting_date_time_check: function() {
+ setup_posting_date_time_check() {
// make posting date default and read only unless explictly checked
frappe.ui.form.on(this.frm.doctype, 'set_posting_date_and_time_read_only', function(frm) {
if(frm.doc.docstatus == 0 && frm.doc.set_posting_time) {
@@ -46,9 +46,9 @@
frm.trigger('set_posting_date_and_time_read_only');
}
});
- },
+ }
- show_stock_ledger: function() {
+ show_stock_ledger() {
var me = this;
if(this.frm.doc.docstatus > 0) {
cur_frm.add_custom_button(__("Stock Ledger"), function() {
@@ -63,9 +63,9 @@
}, __("View"));
}
- },
+ }
- show_general_ledger: function() {
+ show_general_ledger() {
var me = this;
if(this.frm.doc.docstatus > 0) {
cur_frm.add_custom_button(__('Accounting Ledger'), function() {
@@ -81,4 +81,4 @@
}, __("View"));
}
}
-});
+};
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 3a3ee38..448bb65 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -1,12 +1,12 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
-erpnext.taxes_and_totals = erpnext.payments.extend({
- setup: function() {
+erpnext.taxes_and_totals = class taxes_and_totals extends erpnext.payments {
+ setup() {
this.fetch_round_off_accounts();
- },
+ }
- apply_pricing_rule_on_item: function(item) {
+ apply_pricing_rule_on_item(item) {
let effective_item_rate = item.price_list_rate;
let item_rate = item.rate;
if (in_list(["Sales Order", "Quotation"], item.parenttype) && item.blanket_order_rate) {
@@ -32,9 +32,9 @@
}
frappe.model.set_value(item.doctype, item.name, "rate", item_rate);
- },
+ }
- calculate_taxes_and_totals: function(update_paid_amount) {
+ calculate_taxes_and_totals(update_paid_amount) {
this.discount_amount_applied = false;
this._calculate_taxes_and_totals();
this.calculate_discount_amount();
@@ -63,16 +63,16 @@
}
this.frm.refresh_fields();
- },
+ }
- calculate_discount_amount: function(){
+ calculate_discount_amount(){
if (frappe.meta.get_docfield(this.frm.doc.doctype, "discount_amount")) {
this.set_discount_amount();
this.apply_discount_amount();
}
- },
+ }
- _calculate_taxes_and_totals: function() {
+ _calculate_taxes_and_totals() {
this.validate_conversion_rate();
this.calculate_item_values();
this.initialize_taxes();
@@ -82,9 +82,9 @@
this.manipulate_grand_total_for_inclusive_tax();
this.calculate_totals();
this._cleanup();
- },
+ }
- validate_conversion_rate: function() {
+ validate_conversion_rate() {
this.frm.doc.conversion_rate = flt(this.frm.doc.conversion_rate, (cur_frm) ? precision("conversion_rate") : 9);
var conversion_rate_label = frappe.meta.get_label(this.frm.doc.doctype, "conversion_rate",
this.frm.doc.name);
@@ -99,9 +99,9 @@
frappe.throw(err_message);
}
}
- },
+ }
- calculate_item_values: function() {
+ calculate_item_values() {
var me = this;
if (!this.discount_amount_applied) {
$.each(this.frm.doc["items"] || [], function(i, item) {
@@ -121,16 +121,16 @@
me.set_in_company_currency(item, ["price_list_rate", "rate", "amount", "net_rate", "net_amount"]);
});
}
- },
+ }
- set_in_company_currency: function(doc, fields) {
+ set_in_company_currency(doc, fields) {
var me = this;
$.each(fields, function(i, f) {
doc["base_"+f] = flt(flt(doc[f], precision(f, doc)) * me.frm.doc.conversion_rate, precision("base_" + f, doc));
});
- },
+ }
- initialize_taxes: function() {
+ initialize_taxes() {
var me = this;
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
@@ -152,9 +152,9 @@
}
frappe.model.round_floats_in(tax);
});
- },
+ }
- fetch_round_off_accounts: function() {
+ fetch_round_off_accounts() {
let me = this;
frappe.flags.round_off_applicable_accounts = [];
@@ -170,9 +170,9 @@
}
});
}
- },
+ }
- determine_exclusive_rate: function() {
+ determine_exclusive_rate() {
var me = this;
var has_inclusive_tax = false;
@@ -210,9 +210,9 @@
me.set_in_company_currency(item, ["net_rate", "net_amount"]);
}
});
- },
+ }
- get_current_tax_fraction: function(tax, item_tax_map) {
+ get_current_tax_fraction(tax, item_tax_map) {
// Get tax fraction for calculating tax exclusive amount
// from tax inclusive amount
var current_tax_fraction = 0.0;
@@ -241,14 +241,14 @@
inclusive_tax_amount_per_qty *= -1;
}
return [current_tax_fraction, inclusive_tax_amount_per_qty];
- },
+ }
- _get_tax_rate: function(tax, item_tax_map) {
+ _get_tax_rate(tax, item_tax_map) {
return (Object.keys(item_tax_map).indexOf(tax.account_head) != -1) ?
flt(item_tax_map[tax.account_head], precision("rate", tax)) : tax.rate;
- },
+ }
- calculate_net_total: function() {
+ calculate_net_total() {
var me = this;
this.frm.doc.total_qty = this.frm.doc.total = this.frm.doc.base_total = this.frm.doc.net_total = this.frm.doc.base_net_total = 0.0;
@@ -261,9 +261,9 @@
});
frappe.model.round_floats_in(this.frm.doc, ["total", "base_total", "net_total", "base_net_total"]);
- },
+ }
- calculate_taxes: function() {
+ calculate_taxes() {
var me = this;
this.frm.doc.rounding_adjustment = 0;
var actual_tax_dict = {};
@@ -339,9 +339,9 @@
}
});
});
- },
+ }
- set_cumulative_total: function(row_idx, tax) {
+ set_cumulative_total(row_idx, tax) {
var tax_amount = tax.tax_amount_after_discount_amount;
if (tax.category == 'Valuation') {
tax_amount = 0;
@@ -354,13 +354,13 @@
} else {
tax.total = flt(this.frm.doc["taxes"][row_idx-1].total + tax_amount, precision("total", tax));
}
- },
+ }
- _load_item_tax_rate: function(item_tax_rate) {
+ _load_item_tax_rate(item_tax_rate) {
return item_tax_rate ? JSON.parse(item_tax_rate) : {};
- },
+ }
- get_current_tax_amount: function(item, tax, item_tax_map) {
+ get_current_tax_amount(item, tax, item_tax_map) {
var tax_rate = this._get_tax_rate(tax, item_tax_map);
var current_tax_amount = 0.0;
@@ -397,17 +397,17 @@
this.set_item_wise_tax(item, tax, tax_rate, current_tax_amount);
return current_tax_amount;
- },
+ }
- get_final_tax_amount: function(tax, current_tax_amount) {
+ get_final_tax_amount(tax, current_tax_amount) {
if (frappe.flags.round_off_applicable_accounts.includes(tax.account_head)) {
current_tax_amount = Math.round(current_tax_amount);
}
return current_tax_amount;
- },
+ }
- set_item_wise_tax: function(item, tax, tax_rate, current_tax_amount) {
+ set_item_wise_tax(item, tax, tax_rate, current_tax_amount) {
// store tax breakup for each item
let tax_detail = tax.item_wise_tax_detail;
let key = item.item_code || item.item_name;
@@ -417,14 +417,14 @@
item_wise_tax_amount += tax_detail[key][1];
tax_detail[key] = [tax_rate, flt(item_wise_tax_amount, precision("base_tax_amount", tax))];
- },
+ }
- round_off_totals: function(tax) {
+ round_off_totals(tax) {
tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax));
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, precision("tax_amount", tax));
- },
+ }
- manipulate_grand_total_for_inclusive_tax: function() {
+ manipulate_grand_total_for_inclusive_tax() {
var me = this;
// if fully inclusive taxes and diff
if (this.frm.doc["taxes"] && this.frm.doc["taxes"].length) {
@@ -455,9 +455,9 @@
}
}
}
- },
+ }
- calculate_totals: function() {
+ calculate_totals() {
// Changing sequence can cause rounding_adjustmentng issue and on-screen discrepency
var me = this;
var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length : 0;
@@ -503,9 +503,9 @@
// rounded totals
this.set_rounded_total();
- },
+ }
- set_rounded_total: function() {
+ set_rounded_total() {
var disable_rounded_total = 0;
if(frappe.meta.get_docfield(this.frm.doc.doctype, "disable_rounded_total", this.frm.doc.name)) {
disable_rounded_total = this.frm.doc.disable_rounded_total;
@@ -527,9 +527,9 @@
this.set_in_company_currency(this.frm.doc, ["rounding_adjustment", "rounded_total"]);
}
- },
+ }
- _cleanup: function() {
+ _cleanup() {
this.frm.doc.base_in_words = this.frm.doc.in_words = "";
if(this.frm.doc["items"] && this.frm.doc["items"].length) {
@@ -556,16 +556,16 @@
tax.item_wise_tax_detail = JSON.stringify(tax.item_wise_tax_detail);
});
}
- },
+ }
- set_discount_amount: function() {
+ set_discount_amount() {
if(this.frm.doc.additional_discount_percentage) {
this.frm.doc.discount_amount = flt(flt(this.frm.doc[frappe.scrub(this.frm.doc.apply_discount_on)])
* this.frm.doc.additional_discount_percentage / 100, precision("discount_amount"));
}
- },
+ }
- apply_discount_amount: function() {
+ apply_discount_amount() {
var me = this;
var distributed_amount = 0.0;
this.frm.doc.base_discount_amount = 0.0;
@@ -603,9 +603,9 @@
this._calculate_taxes_and_totals();
}
}
- },
+ }
- get_total_for_discount_amount: function() {
+ get_total_for_discount_amount() {
if(this.frm.doc.apply_discount_on == "Net Total") {
return this.frm.doc.net_total;
} else {
@@ -629,27 +629,27 @@
return flt(this.frm.doc.grand_total - total_actual_tax, precision("grand_total"));
}
- },
+ }
- calculate_total_advance: function(update_paid_amount) {
+ calculate_total_advance(update_paid_amount) {
var total_allocated_amount = frappe.utils.sum($.map(this.frm.doc["advances"] || [], function(adv) {
return flt(adv.allocated_amount, precision("allocated_amount", adv));
}));
this.frm.doc.total_advance = flt(total_allocated_amount, precision("total_advance"));
this.calculate_outstanding_amount(update_paid_amount);
- },
+ }
- is_internal_invoice: function() {
+ is_internal_invoice() {
if (['Sales Invoice', 'Purchase Invoice'].includes(this.frm.doc.doctype)) {
if (this.frm.doc.company === this.frm.doc.represents_company) {
return true;
}
}
return false;
- },
+ }
- calculate_outstanding_amount: function(update_paid_amount) {
+ calculate_outstanding_amount(update_paid_amount) {
// NOTE:
// paid_amount and write_off_amount is only for POS/Loyalty Point Redemption Invoice
// total_advance is only for non POS Invoice
@@ -697,9 +697,9 @@
this.frm.doc.outstanding_amount = flt(total_amount_to_pay - flt(paid_amount) +
flt(this.frm.doc.change_amount * this.frm.doc.conversion_rate), precision("outstanding_amount"));
}
- },
+ }
- update_paid_amount_for_return: function() {
+ update_paid_amount_for_return() {
var grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total;
if(this.frm.doc.party_account_currency == this.frm.doc.currency) {
@@ -723,9 +723,9 @@
this.frm.refresh_fields();
this.calculate_paid_amount();
- },
+ }
- set_default_payment: function(total_amount_to_pay, update_paid_amount) {
+ set_default_payment(total_amount_to_pay, update_paid_amount) {
var me = this;
var payment_status = true;
if(this.frm.doc.is_pos && (update_paid_amount===undefined || update_paid_amount)) {
@@ -741,9 +741,9 @@
}
});
}
- },
+ }
- calculate_paid_amount: function() {
+ calculate_paid_amount() {
var me = this;
var paid_amount = 0.0;
var base_paid_amount = 0.0;
@@ -763,9 +763,9 @@
this.frm.set_value('paid_amount', flt(paid_amount, precision("paid_amount")));
this.frm.set_value('base_paid_amount', flt(base_paid_amount, precision("base_paid_amount")));
- },
+ }
- calculate_change_amount: function(){
+ calculate_change_amount(){
this.frm.doc.change_amount = 0.0;
this.frm.doc.base_change_amount = 0.0;
if(in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype)
@@ -784,9 +784,9 @@
precision("base_change_amount"));
}
}
- },
+ }
- calculate_write_off_amount: function(){
+ calculate_write_off_amount(){
if(this.frm.doc.paid_amount > this.frm.doc.grand_total){
this.frm.doc.write_off_amount = flt(this.frm.doc.grand_total - this.frm.doc.paid_amount
+ this.frm.doc.change_amount, precision("write_off_amount"));
@@ -798,4 +798,4 @@
}
this.calculate_outstanding_amount(false);
}
-});
+};
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 1c0abdf..a4c165e 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -3,9 +3,9 @@
frappe.provide('erpnext.accounts.dimensions');
-erpnext.TransactionController = erpnext.taxes_and_totals.extend({
- setup: function() {
- this._super();
+erpnext.TransactionController = class TransactionController extends erpnext.taxes_and_totals {
+ setup() {
+ super.setup();
frappe.flags.hide_serial_batch_dialog = true;
frappe.ui.form.on(this.frm.doctype + " Item", "rate", function(frm, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
@@ -222,8 +222,8 @@
});
}
- },
- onload: function() {
+ }
+ onload() {
var me = this;
if(this.frm.doc.__islocal) {
@@ -249,15 +249,15 @@
}
]);
}
- },
+ }
- is_return: function() {
+ is_return() {
if(!this.frm.doc.is_return && this.frm.doc.return_against) {
this.frm.set_value('return_against', '');
}
- },
+ }
- setup_quality_inspection: function() {
+ setup_quality_inspection() {
if(!in_list(["Delivery Note", "Sales Invoice", "Purchase Receipt", "Purchase Invoice"], this.frm.doc.doctype)) {
return;
}
@@ -290,9 +290,9 @@
}
}
});
- },
+ }
- make_payment_request: function() {
+ make_payment_request() {
var me = this;
const payment_request_type = (in_list(['Sales Order', 'Sales Invoice'], this.frm.doc.doctype))
? "Inward" : "Outward";
@@ -314,9 +314,9 @@
}
}
})
- },
+ }
- onload_post_render: function() {
+ onload_post_render() {
if(this.frm.doc.__islocal && !(this.frm.doc.taxes || []).length
&& !(this.frm.doc.__onload ? this.frm.doc.__onload.load_after_mapping : false)) {
frappe.after_ajax(() => this.apply_default_taxes());
@@ -328,9 +328,9 @@
this.setup_item_selector();
this.frm.get_field("items").grid.set_multiple_add("item_code", "qty");
}
- },
+ }
- refresh: function() {
+ refresh() {
erpnext.toggle_naming_series();
erpnext.hide_company();
this.set_dynamic_labels();
@@ -360,9 +360,9 @@
.appendTo($input_group);
}
}
- },
+ }
- scan_barcode: function() {
+ scan_barcode() {
let scan_barcode_field = this.frm.fields_dict["scan_barcode"];
let show_description = function(idx, exist = null) {
@@ -434,9 +434,9 @@
});
}
return false;
- },
+ }
- apply_default_taxes: function() {
+ apply_default_taxes() {
var me = this;
var taxes_and_charges_field = frappe.meta.get_docfield(me.frm.doc.doctype, "taxes_and_charges",
me.frm.doc.name);
@@ -475,22 +475,22 @@
}
});
}
- },
+ }
- setup_sms: function() {
+ setup_sms() {
var me = this;
let blacklist = ['Purchase Invoice', 'BOM'];
if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped", "Closed"], this.frm.doc.status)
&& !blacklist.includes(this.frm.doctype)) {
this.frm.page.add_menu_item(__('Send SMS'), function() { me.send_sms(); });
}
- },
+ }
- send_sms: function() {
+ send_sms() {
var sms_man = new erpnext.SMSManager(this.frm.doc);
- },
+ }
- barcode: function(doc, cdt, cdn) {
+ barcode(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(d.barcode=="" || d.barcode==null) {
// barcode cleared, remove item
@@ -499,9 +499,9 @@
this.frm.from_barcode = this.frm.from_barcode ? this.frm.from_barcode + 1 : 1;
this.item_code(doc, cdt, cdn);
- },
+ }
- item_code: function(doc, cdt, cdn) {
+ item_code(doc, cdt, cdn) {
var me = this;
var item = frappe.get_doc(cdt, cdn);
var update_stock = 0, show_batch_dialog = 0;
@@ -647,9 +647,9 @@
});
}
}
- },
+ }
- price_list_rate: function(doc, cdt, cdn) {
+ price_list_rate(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["price_list_rate", "discount_percentage"]);
@@ -661,17 +661,17 @@
precision("rate", item));
this.calculate_taxes_and_totals();
- },
+ }
- margin_rate_or_amount: function(doc, cdt, cdn) {
+ margin_rate_or_amount(doc, cdt, cdn) {
// calculated the revised total margin and rate on margin rate changes
let item = frappe.get_doc(cdt, cdn);
this.apply_pricing_rule_on_item(item);
this.calculate_taxes_and_totals();
cur_frm.refresh_fields();
- },
+ }
- margin_type: function(doc, cdt, cdn) {
+ margin_type(doc, cdt, cdn) {
// calculate the revised total margin and rate on margin type changes
let item = frappe.get_doc(cdt, cdn);
if (!item.margin_type) {
@@ -681,9 +681,9 @@
this.calculate_taxes_and_totals();
cur_frm.refresh_fields();
}
- },
+ }
- get_incoming_rate: function(item, posting_date, posting_time, voucher_type, company) {
+ get_incoming_rate(item, posting_date, posting_time, voucher_type, company) {
let item_args = {
'item_code': item.item_code,
@@ -706,9 +706,9 @@
frappe.model.set_value(item.doctype, item.name, 'rate', r.message * item.conversion_factor);
}
});
- },
+ }
- add_taxes_from_item_tax_template: function(item_tax_map) {
+ add_taxes_from_item_tax_template(item_tax_map) {
let me = this;
if(item_tax_map && cint(frappe.defaults.get_default("add_taxes_from_item_tax_template"))) {
@@ -726,9 +726,9 @@
}
});
}
- },
+ }
- serial_no: function(doc, cdt, cdn) {
+ serial_no(doc, cdt, cdn) {
var me = this;
var item = frappe.get_doc(cdt, cdn);
@@ -763,17 +763,17 @@
}
}
}
- },
+ }
- validate: function() {
+ validate() {
this.calculate_taxes_and_totals(false);
- },
+ }
- update_stock: function() {
+ update_stock() {
this.frm.trigger('set_default_internal_warehouse');
- },
+ }
- set_default_internal_warehouse: function() {
+ set_default_internal_warehouse() {
let me = this;
if ((this.frm.doc.doctype === 'Sales Invoice' && me.frm.doc.update_stock)
|| this.frm.doc.doctype == 'Delivery Note') {
@@ -792,9 +792,9 @@
});
}
}
- },
+ }
- company: function() {
+ company() {
var me = this;
var set_pricing = function() {
if(me.frm.doc.company && me.frm.fields_dict.currency) {
@@ -901,16 +901,16 @@
if(this.frm.doc.company) {
erpnext.last_selected_company = this.frm.doc.company;
}
- },
+ }
- transaction_date: function() {
+ transaction_date() {
if (this.frm.doc.transaction_date) {
this.frm.transaction_date = this.frm.doc.transaction_date;
frappe.ui.form.trigger(this.frm.doc.doctype, "currency");
}
- },
+ }
- posting_date: function() {
+ posting_date() {
var me = this;
if (this.frm.doc.posting_date) {
this.frm.posting_date = this.frm.doc.posting_date;
@@ -939,9 +939,9 @@
frappe.ui.form.trigger(me.frm.doc.doctype, "currency");
}
}
- },
+ }
- due_date: function() {
+ due_date() {
// due_date is to be changed, payment terms template and/or payment schedule must
// be removed as due_date is automatically changed based on payment terms
if (this.frm.doc.due_date && !this.frm.updating_party_details && !this.frm.doc.is_pos) {
@@ -964,13 +964,13 @@
frappe.msgprint(final_message);
}
}
- },
+ }
- bill_date: function() {
+ bill_date() {
this.posting_date();
- },
+ }
- recalculate_terms: function() {
+ recalculate_terms() {
const doc = this.frm.doc;
if (doc.payment_terms_template) {
this.payment_terms_template();
@@ -989,17 +989,17 @@
}
);
}
- },
+ }
- get_company_currency: function() {
+ get_company_currency() {
return erpnext.get_currency(this.frm.doc.company);
- },
+ }
- contact_person: function() {
+ contact_person() {
erpnext.utils.get_contact_details(this.frm);
- },
+ }
- currency: function() {
+ currency() {
/* manqala 19/09/2016: let the translation date be whichever of the transaction_date or posting_date is available */
var transaction_date = this.frm.doc.transaction_date || this.frm.doc.posting_date;
/* end manqala */
@@ -1021,9 +1021,9 @@
} else {
this.conversion_rate();
}
- },
+ }
- conversion_rate: function() {
+ conversion_rate() {
const me = this.frm;
if(this.frm.doc.currency === this.get_company_currency()) {
this.frm.set_value("conversion_rate", 1.0);
@@ -1043,9 +1043,9 @@
}
// Make read only if Accounts Settings doesn't allow stale rates
this.frm.set_df_property("conversion_rate", "read_only", erpnext.stale_rate_allowed() ? 0 : 1);
- },
+ }
- shipping_rule: function() {
+ shipping_rule() {
var me = this;
if(this.frm.doc.shipping_rule) {
return this.frm.call({
@@ -1061,9 +1061,9 @@
else {
me.calculate_taxes_and_totals();
}
- },
+ }
- set_margin_amount_based_on_currency: function(exchange_rate) {
+ set_margin_amount_based_on_currency(exchange_rate) {
if (in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "Purchase Invoice", "Purchase Order", "Purchase Receipt"]), this.frm.doc.doctype) {
var me = this;
$.each(this.frm.doc.items || [], function(i, d) {
@@ -1073,9 +1073,9 @@
}
});
}
- },
+ }
- set_actual_charges_based_on_currency: function(exchange_rate) {
+ set_actual_charges_based_on_currency(exchange_rate) {
var me = this;
$.each(this.frm.doc.taxes || [], function(i, d) {
if(d.charge_type == "Actual") {
@@ -1083,9 +1083,9 @@
flt(d.tax_amount) / flt(exchange_rate));
}
});
- },
+ }
- get_exchange_rate: function(transaction_date, from_currency, to_currency, callback) {
+ get_exchange_rate(transaction_date, from_currency, to_currency, callback) {
var args;
if (["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"].includes(this.frm.doctype)) {
args = "for_selling";
@@ -1107,9 +1107,9 @@
callback(flt(r.message));
}
});
- },
+ }
- price_list_currency: function() {
+ price_list_currency() {
var me=this;
this.set_dynamic_labels();
@@ -1123,9 +1123,9 @@
} else {
this.plc_conversion_rate();
}
- },
+ }
- plc_conversion_rate: function() {
+ plc_conversion_rate() {
if(this.frm.doc.price_list_currency === this.get_company_currency()) {
this.frm.set_value("plc_conversion_rate", 1.0);
} else if(this.frm.doc.price_list_currency === this.frm.doc.currency
@@ -1137,9 +1137,9 @@
if(!this.in_apply_price_list) {
this.apply_price_list(null, true);
}
- },
+ }
- uom: function(doc, cdt, cdn) {
+ uom(doc, cdt, cdn) {
var me = this;
var item = frappe.get_doc(cdt, cdn);
if(item.item_code && item.uom) {
@@ -1157,9 +1157,9 @@
});
}
me.calculate_stock_uom_rate(doc, cdt, cdn);
- },
+ }
- conversion_factor: function(doc, cdt, cdn, dont_fetch_price_list_rate) {
+ conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate) {
if(frappe.meta.get_docfield(cdt, "stock_qty", cdn)) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["qty", "conversion_factor"]);
@@ -1179,35 +1179,35 @@
}
this.calculate_stock_uom_rate(doc, cdt, cdn);
}
- },
+ }
- batch_no: function(doc, cdt, cdn) {
+ batch_no(doc, cdt, cdn) {
let item = frappe.get_doc(cdt, cdn);
this.apply_price_list(item, true);
- },
+ }
- toggle_conversion_factor: function(item) {
+ toggle_conversion_factor(item) {
// toggle read only property for conversion factor field if the uom and stock uom are same
if(this.frm.get_field('items').grid.fields_map.conversion_factor) {
this.frm.fields_dict.items.grid.toggle_enable("conversion_factor",
((item.uom != item.stock_uom) && !frappe.meta.get_docfield(cur_frm.fields_dict.items.grid.doctype, "conversion_factor").read_only)? true: false);
}
- },
+ }
- qty: function(doc, cdt, cdn) {
+ qty(doc, cdt, cdn) {
let item = frappe.get_doc(cdt, cdn);
this.conversion_factor(doc, cdt, cdn, true);
this.calculate_stock_uom_rate(doc, cdt, cdn);
this.apply_pricing_rule(item, true);
- },
+ }
- calculate_stock_uom_rate: function(doc, cdt, cdn) {
+ calculate_stock_uom_rate(doc, cdt, cdn) {
let item = frappe.get_doc(cdt, cdn);
- item.stock_uom_rate = flt(item.rate)/flt(item.conversion_factor);
+ item.stock_uom_rate = flt(item.rate)/flt(item.conversion_factor);
refresh_field("stock_uom_rate", item.name, item.parentfield);
- },
- service_stop_date: function(frm, cdt, cdn) {
+ }
+ service_stop_date(frm, cdt, cdn) {
var child = locals[cdt][cdn];
if(child.service_stop_date) {
@@ -1223,9 +1223,9 @@
frappe.throw(__("Service Stop Date cannot be after Service End Date"));
}
}
- },
+ }
- service_start_date: function(frm, cdt, cdn) {
+ service_start_date(frm, cdt, cdn) {
var child = locals[cdt][cdn];
if(child.service_start_date) {
@@ -1237,9 +1237,9 @@
}
})
}
- },
+ }
- calculate_net_weight: function(){
+ calculate_net_weight(){
/* Calculate Total Net Weight then further applied shipping rule to calculate shipping charges.*/
var me = this;
this.frm.doc.total_net_weight= 0.0;
@@ -1249,9 +1249,9 @@
});
refresh_field("total_net_weight");
this.shipping_rule();
- },
+ }
- set_dynamic_labels: function() {
+ set_dynamic_labels() {
// 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));
@@ -1260,9 +1260,9 @@
this.change_form_labels(company_currency);
this.change_grid_labels(company_currency);
this.frm.refresh_fields();
- },
+ }
- change_form_labels: function(company_currency) {
+ change_form_labels(company_currency) {
var me = this;
this.frm.set_currency_labels(["base_total", "base_net_total", "base_total_taxes_and_charges",
@@ -1309,9 +1309,9 @@
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)));
- },
+ }
- change_grid_labels: function(company_currency) {
+ change_grid_labels(company_currency) {
var me = this;
this.frm.set_currency_labels(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount", "base_rate_with_margin"],
@@ -1375,21 +1375,21 @@
// set labels
var $wrapper = $(this.frm.wrapper);
- },
+ }
- recalculate: function() {
+ recalculate() {
this.calculate_taxes_and_totals();
- },
+ }
- recalculate_values: function() {
+ recalculate_values() {
this.calculate_taxes_and_totals();
- },
+ }
- calculate_charges: function() {
+ calculate_charges() {
this.calculate_taxes_and_totals();
- },
+ }
- ignore_pricing_rule: function() {
+ ignore_pricing_rule() {
if(this.frm.doc.ignore_pricing_rule) {
var me = this;
var item_list = [];
@@ -1423,9 +1423,9 @@
} else {
this.apply_pricing_rule();
}
- },
+ }
- apply_pricing_rule: function(item, calculate_taxes_and_totals) {
+ apply_pricing_rule(item, calculate_taxes_and_totals) {
var me = this;
var args = this._get_args(item);
if (!(args.items && args.items.length)) {
@@ -1444,9 +1444,9 @@
}
}
});
- },
+ }
- _get_args: function(item) {
+ _get_args(item) {
var me = this;
return {
"items": this._get_item_list(item),
@@ -1474,9 +1474,9 @@
"pos_profile": me.frm.doc.doctype == 'Sales Invoice' ? me.frm.doc.pos_profile : '',
"coupon_code": me.frm.doc.coupon_code
};
- },
+ }
- _get_item_list: function(item) {
+ _get_item_list(item) {
var item_list = [];
var append_item = function(d) {
if (d.item_code) {
@@ -1517,9 +1517,9 @@
});
}
return item_list;
- },
+ }
- _set_values_for_item_list: function(children) {
+ _set_values_for_item_list(children) {
var me = this;
var price_list_rate_changed = false;
var items_rule_dict = {};
@@ -1556,9 +1556,9 @@
me.apply_rule_on_other_items(items_rule_dict);
if(!price_list_rate_changed) me.calculate_taxes_and_totals();
- },
+ }
- apply_rule_on_other_items: function(args) {
+ apply_rule_on_other_items(args) {
const me = this;
const fields = ["discount_percentage", "pricing_rules", "discount_amount", "rate"];
@@ -1577,9 +1577,9 @@
});
}
}
- },
+ }
- apply_product_discount: function(free_item_data) {
+ apply_product_discount(free_item_data) {
const items = this.frm.doc.items.filter(d => (d.item_code == free_item_data.item_code
&& d.is_free_item)) || [];
@@ -1593,9 +1593,9 @@
} if (items && items.length && free_item_data) {
items[0].qty = free_item_data.qty
}
- },
+ }
- apply_price_list: function(item, reset_plc_conversion) {
+ apply_price_list(item, reset_plc_conversion) {
// We need to reset plc_conversion_rate sometimes because the call to
// `erpnext.stock.get_item_details.apply_price_list` is sensitive to its value
if (!reset_plc_conversion) {
@@ -1634,9 +1634,9 @@
}).always(() => {
me.in_apply_price_list = false;
});
- },
+ }
- remove_pricing_rule: function(item) {
+ remove_pricing_rule(item) {
let me = this;
const fields = ["discount_percentage",
"discount_amount", "margin_rate_or_amount", "rate_with_margin"];
@@ -1670,18 +1670,18 @@
me.trigger_price_list_rate();
}
- },
+ }
- trigger_price_list_rate: function() {
+ trigger_price_list_rate() {
var me = this;
this.frm.doc.items.forEach(child_row => {
me.frm.script_manager.trigger("price_list_rate",
child_row.doctype, child_row.name);
})
- },
+ }
- validate_company_and_party: function() {
+ validate_company_and_party() {
var me = this;
var valid = true;
@@ -1696,9 +1696,9 @@
}
});
return valid;
- },
+ }
- get_terms: function() {
+ get_terms() {
var me = this;
erpnext.utils.get_terms(this.frm.doc.tc_name, this.frm.doc, function(r) {
@@ -1706,9 +1706,9 @@
me.frm.set_value("terms", r.message);
}
});
- },
+ }
- taxes_and_charges: function() {
+ taxes_and_charges() {
var me = this;
if(this.frm.doc.taxes_and_charges) {
return this.frm.call({
@@ -1734,9 +1734,9 @@
}
});
}
- },
+ }
- tax_category: function() {
+ tax_category() {
var me = this;
if(me.frm.updating_party_details) return;
@@ -1744,9 +1744,9 @@
() => this.update_item_tax_map(),
() => erpnext.utils.set_taxes(this.frm, "tax_category"),
]);
- },
+ }
- item_tax_template: function(doc, cdt, cdn) {
+ item_tax_template(doc, cdt, cdn) {
var me = this;
if(me.frm.updating_party_details) return;
@@ -1772,9 +1772,9 @@
item.item_tax_rate = "{}";
me.calculate_taxes_and_totals();
}
- },
+ }
- update_item_tax_map: function() {
+ update_item_tax_map() {
var me = this;
var item_codes = [];
$.each(this.frm.doc.items || [], function(i, item) {
@@ -1810,9 +1810,9 @@
}
});
}
- },
+ }
- is_recurring: function() {
+ is_recurring() {
// set default values for recurring documents
if(this.frm.doc.is_recurring && this.frm.doc.__islocal) {
frappe.msgprint(__("Please set recurring after saving"));
@@ -1835,9 +1835,9 @@
}
refresh_many(["notification_email_address", "repeat_on_day_of_month"]);
- },
+ }
- from_date: function() {
+ from_date() {
// set to_date
if(this.frm.doc.from_date) {
var recurring_type_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6,
@@ -1851,25 +1851,25 @@
refresh_field('to_date');
}
}
- },
+ }
- set_gross_profit: function(item) {
+ set_gross_profit(item) {
if (["Sales Order", "Quotation"].includes(this.frm.doc.doctype) && item.valuation_rate) {
var rate = flt(item.rate) * flt(this.frm.doc.conversion_rate || 1);
item.gross_profit = flt(((rate - item.valuation_rate) * item.stock_qty), precision("amount", item));
}
- },
+ }
- setup_item_selector: function() {
+ setup_item_selector() {
// TODO: remove item selector
return;
// if(!this.item_selector) {
// this.item_selector = new erpnext.ItemSelector({frm: this.frm});
// }
- },
+ }
- get_advances: function() {
+ get_advances() {
if(!this.frm.is_return) {
return this.frm.call({
method: "set_advances",
@@ -1879,9 +1879,9 @@
}
})
}
- },
+ }
- make_payment_entry: function() {
+ make_payment_entry() {
return frappe.call({
method: cur_frm.cscript.get_method_for_payment(),
args: {
@@ -1894,9 +1894,9 @@
// cur_frm.refresh_fields()
}
});
- },
+ }
- get_method_for_payment: function(){
+ get_method_for_payment(){
var method = "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry";
if(cur_frm.doc.__onload && cur_frm.doc.__onload.make_payment_via_journal_entry){
if(in_list(['Sales Invoice', 'Purchase Invoice'], cur_frm.doc.doctype)){
@@ -1907,9 +1907,9 @@
}
return method
- },
+ }
- set_query_for_batch: function(doc, cdt, cdn) {
+ set_query_for_batch(doc, cdt, cdn) {
// Show item's batches in the dropdown of batch no
var me = this;
@@ -1939,9 +1939,9 @@
filters: filters
}
}
- },
+ }
- set_query_for_item_tax_template: function(doc, cdt, cdn) {
+ set_query_for_item_tax_template(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
if(!item.item_code) {
return doc.company ? {filters: {company: doc.company}} : {};
@@ -1961,9 +1961,9 @@
filters: filters
}
}
- },
+ }
- payment_terms_template: function() {
+ payment_terms_template() {
var me = this;
const doc = this.frm.doc;
if(doc.payment_terms_template && doc.doctype !== 'Delivery Note') {
@@ -1983,9 +1983,9 @@
}
})
}
- },
+ }
- payment_term: function(doc, cdt, cdn) {
+ payment_term(doc, cdt, cdn) {
var row = locals[cdt][cdn];
if(row.payment_term) {
frappe.call({
@@ -2005,17 +2005,17 @@
}
})
}
- },
+ }
- against_blanket_order: function(doc, cdt, cdn) {
+ against_blanket_order(doc, cdt, cdn) {
var item = locals[cdt][cdn];
if(!item.against_blanket_order) {
frappe.model.set_value(this.frm.doctype + " Item", item.name, "blanket_order", null);
frappe.model.set_value(this.frm.doctype + " Item", item.name, "blanket_order_rate", 0.00);
}
- },
+ }
- blanket_order: function(doc, cdt, cdn) {
+ blanket_order(doc, cdt, cdn) {
var me = this;
var item = locals[cdt][cdn];
if (item.blanket_order && (item.parenttype=="Sales Order" || item.parenttype=="Purchase Order")) {
@@ -2043,34 +2043,34 @@
}
})
}
- },
+ }
- set_reserve_warehouse: function() {
+ set_reserve_warehouse() {
this.autofill_warehouse(this.frm.doc.supplied_items, "reserve_warehouse", this.frm.doc.set_reserve_warehouse);
- },
+ }
- set_warehouse: function() {
+ set_warehouse() {
this.autofill_warehouse(this.frm.doc.items, "warehouse", this.frm.doc.set_warehouse);
- },
+ }
- set_target_warehouse: function() {
+ set_target_warehouse() {
this.autofill_warehouse(this.frm.doc.items, "target_warehouse", this.frm.doc.set_target_warehouse);
- },
+ }
- set_from_warehouse: function() {
+ set_from_warehouse() {
this.autofill_warehouse(this.frm.doc.items, "from_warehouse", this.frm.doc.set_from_warehouse);
- },
+ }
- autofill_warehouse : function (child_table, warehouse_field, warehouse) {
+ autofill_warehouse(child_table, warehouse_field, warehouse) {
if (warehouse && child_table && child_table.length) {
let doctype = child_table[0].doctype;
$.each(child_table || [], function(i, item) {
frappe.model.set_value(doctype, item.name, warehouse_field, warehouse);
});
}
- },
+ }
- coupon_code: function() {
+ coupon_code() {
var me = this;
frappe.run_serially([
() => this.frm.doc.ignore_pricing_rule=1,
@@ -2079,7 +2079,7 @@
() => me.apply_pricing_rule()
]);
}
-});
+};
erpnext.show_serial_batch_selector = function (frm, d, callback, on_close, show_dialog) {
let warehouse, receiving_stock, existing_stock;