refactor: Replace Class.extend with native class
diff --git a/erpnext/public/js/account_tree_grid.js b/erpnext/public/js/account_tree_grid.js
index 757f33e..413a5ee 100644
--- a/erpnext/public/js/account_tree_grid.js
+++ b/erpnext/public/js/account_tree_grid.js
@@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-erpnext.AccountTreeGrid = frappe.views.TreeGridReport.extend({
- init: function(wrapper, title) {
- this._super({
+erpnext.AccountTreeGrid = class AccountTreeGrid extends frappe.views.TreeGridReport {
+ constructor(wrapper, title) {
+ super({
title: title,
parent: $(wrapper).find('.layout-main'),
page: wrapper.page,
@@ -33,8 +33,24 @@
}
},
});
- },
- setup_columns: function() {
+
+ this.filters = [
+ {fieldtype: "Select", label: __("Company"), link:"Company", fieldname: "company",
+ default_value: __("Select Company..."),
+ filter: function(val, item, opts, me) {
+ if (item.company == val || val == opts.default_value) {
+ return me.apply_zero_filter(val, item, opts, me);
+ }
+ return false;
+ }},
+ {fieldtype: "Select", label: "Fiscal Year", link:"Fiscal Year", fieldname: "fiscal_year",
+ default_value: __("Select Fiscal Year...")},
+ {fieldtype: "Date", label: __("From Date"), fieldname: "from_date"},
+ {fieldtype: "Label", label: __("To")},
+ {fieldtype: "Date", label: __("To Date"), fieldname: "to_date"}
+ ]
+ }
+ setup_columns() {
this.columns = [
{id: "name", name: __("Account"), field: "name", width: 300, cssClass: "cell-title"},
{id: "opening_dr", name: __("Opening (Dr)"), field: "opening_dr", width: 100,
@@ -50,25 +66,10 @@
{id: "closing_cr", name: __("Closing (Cr)"), field: "closing_cr", width: 100,
formatter: this.currency_formatter}
];
+ }
- },
- filters: [
- {fieldtype: "Select", label: __("Company"), link:"Company", fieldname: "company",
- default_value: __("Select Company..."),
- filter: function(val, item, opts, me) {
- if (item.company == val || val == opts.default_value) {
- return me.apply_zero_filter(val, item, opts, me);
- }
- return false;
- }},
- {fieldtype: "Select", label: "Fiscal Year", link:"Fiscal Year", fieldname: "fiscal_year",
- default_value: __("Select Fiscal Year...")},
- {fieldtype: "Date", label: __("From Date"), fieldname: "from_date"},
- {fieldtype: "Label", label: __("To")},
- {fieldtype: "Date", label: __("To Date"), fieldname: "to_date"}
- ],
- setup_filters: function() {
- this._super();
+ setup_filters() {
+ super.setup_filters();
var me = this;
// default filters
this.filter_inputs.fiscal_year.change(function() {
@@ -83,8 +84,8 @@
});
me.show_zero_check()
if(me.ignore_closing_entry) me.ignore_closing_entry();
- },
- prepare_data: function() {
+ }
+ prepare_data() {
var me = this;
if(!this.primary_data) {
// make accounts list
@@ -113,12 +114,12 @@
this.set_indent();
this.prepare_balances();
- },
- init_account: function(d) {
+ }
+ init_account(d) {
this.reset_item_values(d);
- },
+ }
- prepare_balances: function() {
+ prepare_balances() {
var gl = frappe.report_dump.data['GL Entry'];
var me = this;
@@ -139,8 +140,8 @@
});
this.update_groups();
- },
- update_balances: function(account, posting_date, v) {
+ }
+ update_balances(account, posting_date, v) {
// opening
if (posting_date < this.opening_date || v.is_opening === "Yes") {
if (account.report_type === "Profit and Loss" &&
@@ -161,8 +162,8 @@
var closing_bal = flt(account.opening_dr) - flt(account.opening_cr) +
flt(account.debit) - flt(account.credit);
this.set_debit_or_credit(account, "closing", closing_bal);
- },
- set_debit_or_credit: function(account, field, balance) {
+ }
+ set_debit_or_credit(account, field, balance) {
if(balance > 0) {
account[field+"_dr"] = balance;
account[field+"_cr"] = 0;
@@ -170,8 +171,8 @@
account[field+"_cr"] = Math.abs(balance);
account[field+"_dr"] = 0;
}
- },
- update_groups: function() {
+ }
+ update_groups() {
// update groups
var me= this;
$.each(this.data, function(i, account) {
@@ -202,9 +203,9 @@
}
}
});
- },
+ }
- set_fiscal_year: function() {
+ set_fiscal_year() {
if (this.opening_date > this.closing_date) {
frappe.msgprint(__("Opening Date should be before Closing Date"));
return;
@@ -223,9 +224,9 @@
frappe.msgprint(__("Opening Date and Closing Date should be within same Fiscal Year"));
return;
}
- },
+ }
- show_general_ledger: function(account) {
+ show_general_ledger(account) {
frappe.route_options = {
account: account,
company: this.company,
@@ -234,4 +235,4 @@
};
frappe.set_route("query-report", "General Ledger");
}
-});
+};
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;
diff --git a/erpnext/public/js/payment/payments.js b/erpnext/public/js/payment/payments.js
index 0d656bc..7df976c 100644
--- a/erpnext/public/js/payment/payments.js
+++ b/erpnext/public/js/payment/payments.js
@@ -1,31 +1,31 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
-erpnext.payments = erpnext.stock.StockController.extend({
- make_payment: function() {
+erpnext.payments = class payments extends erpnext.stock.StockController {
+ make_payment() {
var me = this;
this.dialog = new frappe.ui.Dialog({
title: 'Payment'
});
-
+
this.dialog.show();
this.$body = this.dialog.body;
this.set_payment_primary_action();
this.make_keyboard();
this.select_text()
- },
+ }
- select_text: function(){
+ select_text(){
var me = this;
$(this.$body).find('.form-control').click(function(){
$(this).select();
})
- },
+ }
- set_payment_primary_action: function(){
+ set_payment_primary_action(){
var me = this;
-
+
this.dialog.set_primary_action(__("Submit"), function() {
// Allow no ZERO payment
$.each(me.frm.doc.payments, function (index, data) {
@@ -36,18 +36,18 @@
}
});
})
- },
+ }
- make_keyboard: function(){
+ make_keyboard(){
var me = this;
$(this.$body).empty();
$(this.$body).html(frappe.render_template('pos_payment', this.frm.doc))
this.show_payment_details();
this.bind_keyboard_event()
this.clear_amount()
- },
+ }
- make_multimode_payment: function(){
+ make_multimode_payment(){
var me = this;
if(this.frm.doc.change_amount > 0){
@@ -57,9 +57,9 @@
this.payments = frappe.model.add_child(this.frm.doc, 'Multi Mode Payment', "payments");
this.payments.mode_of_payment = this.dialog.fields_dict.mode_of_payment.get_value();
this.payments.amount = flt(this.payment_val);
- },
+ }
- show_payment_details: function(){
+ show_payment_details(){
var me = this;
var multimode_payments = $(this.$body).find('.multimode-payments').empty();
if(this.frm.doc.payments.length){
@@ -82,9 +82,9 @@
}else{
$("<p>No payment mode selected in pos profile</p>").appendTo(multimode_payments)
}
- },
+ }
- set_outstanding_amount: function(){
+ set_outstanding_amount(){
this.selected_mode = $(this.$body).find(repl("input[idx='%(idx)s']",{'idx': this.idx}));
this.highlight_selected_row()
this.payment_val = 0.0
@@ -99,47 +99,47 @@
}
this.selected_mode.select()
this.bind_amount_change_event();
- },
-
- bind_keyboard_event: function(){
+ }
+
+ bind_keyboard_event(){
var me = this;
this.payment_val = '';
this.bind_form_control_event();
this.bind_numeric_keys_event();
- },
+ }
- bind_form_control_event: function(){
+ bind_form_control_event(){
var me = this;
$(this.$body).find('.pos-payment-row').click(function(){
me.idx = $(this).attr("idx");
me.set_outstanding_amount()
})
-
+
$(this.$body).find('.form-control').click(function(){
me.idx = $(this).attr("idx");
me.set_outstanding_amount();
me.update_paid_amount(true);
})
-
+
$(this.$body).find('.write_off_amount').change(function(){
me.write_off_amount(flt($(this).val()), precision("write_off_amount"));
})
-
+
$(this.$body).find('.change_amount').change(function(){
me.change_amount(flt($(this).val()), precision("change_amount"));
})
- },
+ }
- highlight_selected_row: function(){
+ highlight_selected_row(){
var me = this;
var selected_row = $(this.$body).find(repl(".pos-payment-row[idx='%(idx)s']",{'idx': this.idx}));
$(this.$body).find('.pos-payment-row').removeClass('selected-payment-mode')
selected_row.addClass('selected-payment-mode')
$(this.$body).find('.amount').attr('disabled', true);
this.selected_mode.attr('disabled', false);
- },
-
- bind_numeric_keys_event: function(){
+ }
+
+ bind_numeric_keys_event(){
var me = this;
$(this.$body).find('.pos-keyboard-key').click(function(){
me.payment_val += $(this).text();
@@ -147,7 +147,7 @@
me.idx = me.selected_mode.attr("idx")
me.update_paid_amount()
})
-
+
$(this.$body).find('.delete-btn').click(function(){
me.payment_val = cstr(flt(me.selected_mode.val())).slice(0, -1);
me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency));
@@ -155,9 +155,9 @@
me.update_paid_amount();
})
- },
-
- bind_amount_change_event: function(){
+ }
+
+ bind_amount_change_event(){
var me = this;
this.selected_mode.change(function(){
me.payment_val = flt($(this).val()) || 0.0;
@@ -165,9 +165,9 @@
me.idx = me.selected_mode.attr("idx")
me.update_payment_amount()
})
- },
+ }
- clear_amount: function() {
+ clear_amount() {
var me = this;
$(this.$body).find('.clr').click(function(e){
e.stopPropagation();
@@ -178,9 +178,9 @@
me.highlight_selected_row();
me.update_payment_amount();
})
- },
+ }
- write_off_amount: function(write_off_amount) {
+ write_off_amount(write_off_amount) {
var me = this;
this.frm.doc.write_off_amount = flt(write_off_amount, precision("write_off_amount"));
@@ -188,17 +188,17 @@
precision("base_write_off_amount"));
this.calculate_outstanding_amount(false)
this.show_amounts()
- },
+ }
- change_amount: function(change_amount) {
+ change_amount(change_amount) {
var me = this;
this.frm.doc.change_amount = flt(change_amount, precision("change_amount"));
this.calculate_write_off_amount()
this.show_amounts()
- },
+ }
- update_paid_amount: function(update_write_off) {
+ update_paid_amount(update_write_off) {
var me = this;
if(in_list(['change_amount', 'write_off_amount'], this.idx)){
var value = me.selected_mode.val();
@@ -213,9 +213,9 @@
}else{
this.update_payment_amount()
}
- },
+ }
- update_payment_amount: function(){
+ update_payment_amount(){
var me = this;
$.each(this.frm.doc.payments, function(index, data){
@@ -226,9 +226,9 @@
this.calculate_outstanding_amount(false);
this.show_amounts();
- },
+ }
- show_amounts: function(){
+ show_amounts(){
var me = this;
$(this.$body).find(".write_off_amount").val(format_currency(this.frm.doc.write_off_amount, this.frm.doc.currency));
$(this.$body).find('.paid_amount').text(format_currency(this.frm.doc.paid_amount, this.frm.doc.currency));
@@ -236,4 +236,4 @@
$(this.$body).find('.outstanding_amount').text(format_currency(this.frm.doc.outstanding_amount, frappe.get_doc(":Company", this.frm.doc.company).default_currency))
this.update_invoice();
}
-})
\ No newline at end of file
+}
diff --git a/erpnext/public/js/stock_analytics.js b/erpnext/public/js/stock_analytics.js
index 140c9dc..c74b45e 100644
--- a/erpnext/public/js/stock_analytics.js
+++ b/erpnext/public/js/stock_analytics.js
@@ -2,8 +2,8 @@
// License: GNU General Public License v3. See license.txt
-erpnext.StockAnalytics = erpnext.StockGridReport.extend({
- init: function(wrapper, opts) {
+erpnext.StockAnalytics = class StockAnalytics extends erpnext.StockGridReport {
+ constructor(wrapper, opts) {
var args = {
title: __("Stock Analytics"),
parent: $(wrapper).find('.layout-main'),
@@ -30,9 +30,9 @@
if(opts) $.extend(args, opts);
- this._super(args);
- },
- setup_columns: function() {
+ super(args);
+ }
+ setup_columns() {
var std_columns = [
{id: "name", name: __("Item"), field: "name", width: 300},
{id: "brand", name: __("Brand"), field: "brand", width: 100},
@@ -43,8 +43,9 @@
this.make_date_range_columns();
this.columns = std_columns.concat(this.columns);
- },
- filters: [
+ }
+
+ filters = [
{fieldtype:"Select", label: __("Value or Qty"), fieldname: "value_or_qty",
options:[{label:__("Value"), value:"Value"}, {label:__("Quantity"), value:"Quantity"}],
filter: function(val, item, opts, me) {
@@ -66,20 +67,21 @@
{label:__("Quarterly"), value:"Quarterly"},
{label:__("Yearly"), value:"Yearly"},
]}
- ],
- setup_filters: function() {
+ ]
+
+ setup_filters() {
var me = this;
- this._super();
+ super.setup_filters();
this.trigger_refresh_on_change(["value_or_qty", "brand", "warehouse", "range"]);
this.show_zero_check();
- },
- init_filter_values: function() {
- this._super();
+ }
+ init_filter_values() {
+ super.init_filter_values();
this.filter_inputs.range && this.filter_inputs.range.val('Monthly');
- },
- prepare_data: function() {
+ }
+ prepare_data() {
var me = this;
if(!this.data) {
@@ -112,8 +114,8 @@
this.prepare_balances();
this.update_groups();
- },
- prepare_balances: function() {
+ }
+ prepare_balances() {
var me = this;
var from_date = frappe.datetime.str_to_obj(this.from_date);
var to_date = frappe.datetime.str_to_obj(this.to_date);
@@ -164,8 +166,8 @@
item.closing_qty_value += diff;
}
}
- },
- update_groups: function() {
+ }
+ update_groups() {
var me = this;
$.each(this.data, function(i, item) {
// update groups
@@ -192,8 +194,8 @@
}
}
});
- },
- show_stock_ledger: function(item_code) {
+ }
+ show_stock_ledger(item_code) {
frappe.route_options = {
item_code: item_code,
from_date: this.from_date,
@@ -201,5 +203,5 @@
};
frappe.set_route("query-report", "Stock Ledger");
}
-});
+};
diff --git a/erpnext/public/js/stock_grid_report.js b/erpnext/public/js/stock_grid_report.js
index 832fd3e..752fafd 100644
--- a/erpnext/public/js/stock_grid_report.js
+++ b/erpnext/public/js/stock_grid_report.js
@@ -1,16 +1,16 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
-erpnext.StockGridReport = frappe.views.TreeGridReport.extend({
- get_item_warehouse: function(warehouse, item) {
+erpnext.StockGridReport = class StockGridReport extends frappe.views.TreeGridReport {
+ get_item_warehouse(warehouse, item) {
if(!this.item_warehouse[item]) this.item_warehouse[item] = {};
if(!this.item_warehouse[item][warehouse]) this.item_warehouse[item][warehouse] = {
balance_qty: 0.0, balance_value: 0.0, fifo_stack: []
};
return this.item_warehouse[item][warehouse];
- },
+ }
- get_value_diff: function(wh, sl, is_fifo) {
+ get_value_diff(wh, sl, is_fifo) {
// value
if(sl.qty > 0) {
// incoming - rate is given
@@ -59,8 +59,8 @@
wh.balance_qty += sl.qty;
wh.balance_value += value_diff;
return value_diff;
- },
- get_fifo_value_diff: function(wh, sl) {
+ }
+ get_fifo_value_diff(wh, sl) {
// get exact rate from fifo stack
var fifo_stack = (wh.fifo_stack || []).reverse();
var fifo_value_diff = 0.0;
@@ -89,9 +89,9 @@
// reset the updated stack
wh.fifo_stack = fifo_stack.reverse();
return -fifo_value_diff;
- },
+ }
- get_serialized_value_diff: function(sl) {
+ get_serialized_value_diff(sl) {
var me = this;
var value_diff = 0.0;
@@ -103,9 +103,9 @@
});
return value_diff;
- },
+ }
- get_serialized_buying_rates: function() {
+ get_serialized_buying_rates() {
var serialized_buying_rates = {};
if (frappe.report_dump.data["Serial No"]) {
@@ -115,5 +115,5 @@
}
return serialized_buying_rates;
- },
-});
+ }
+};
diff --git a/erpnext/public/js/telephony.js b/erpnext/public/js/telephony.js
index 9548d6c..1c3e314 100644
--- a/erpnext/public/js/telephony.js
+++ b/erpnext/public/js/telephony.js
@@ -1,19 +1,19 @@
-frappe.ui.form.ControlData = frappe.ui.form.ControlData.extend( {
+frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlData {
make_input() {
- this._super();
+ super.make_input();
if (this.df.options == 'Phone') {
this.setup_phone();
}
if (this.frm && this.frm.fields_dict) {
Object.values(this.frm.fields_dict).forEach(function(field) {
- if (field.df.read_only === 1 && field.df.options === 'Phone'
+ if (field.df.read_only === 1 && field.df.options === 'Phone'
&& field.disp_area.style[0] != 'display' && !field.has_icon) {
field.setup_phone();
field.has_icon = true;
}
});
}
- },
+ }
setup_phone() {
if (frappe.phone_call.handler) {
let control = this.df.read_only ? '.control-value' : '.control-input';
@@ -30,4 +30,4 @@
});
}
}
-});
+};
diff --git a/erpnext/public/js/utils/customer_quick_entry.js b/erpnext/public/js/utils/customer_quick_entry.js
index ebe6cd9..efb8dd9 100644
--- a/erpnext/public/js/utils/customer_quick_entry.js
+++ b/erpnext/public/js/utils/customer_quick_entry.js
@@ -1,17 +1,17 @@
frappe.provide('frappe.ui.form');
-frappe.ui.form.CustomerQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
- init: function(doctype, after_insert) {
+frappe.ui.form.CustomerQuickEntryForm = class CustomerQuickEntryForm extends frappe.ui.form.QuickEntryForm {
+ constructor(doctype, after_insert) {
+ super(doctype, after_insert);
this.skip_redirect_on_error = true;
- this._super(doctype, after_insert);
- },
+ }
- render_dialog: function() {
+ render_dialog() {
this.mandatory = this.mandatory.concat(this.get_variant_fields());
- this._super();
- },
+ super.render_dialog();
+ }
- get_variant_fields: function() {
+ get_variant_fields() {
var variant_fields = [{
fieldtype: "Section Break",
label: __("Primary Contact Details"),
@@ -77,5 +77,5 @@
}];
return variant_fields;
- },
-})
\ No newline at end of file
+ }
+}
diff --git a/erpnext/public/js/utils/item_quick_entry.js b/erpnext/public/js/utils/item_quick_entry.js
index 27ef107..7e0198d 100644
--- a/erpnext/public/js/utils/item_quick_entry.js
+++ b/erpnext/public/js/utils/item_quick_entry.js
@@ -1,27 +1,27 @@
frappe.provide('frappe.ui.form');
-frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
- init: function(doctype, after_insert) {
- this._super(doctype, after_insert);
- },
+frappe.ui.form.ItemQuickEntryForm = class ItemQuickEntryForm extends frappe.ui.form.QuickEntryForm {
+ constructor(doctype, after_insert) {
+ super(doctype, after_insert);
+ }
- render_dialog: function() {
+ render_dialog() {
this.mandatory = this.get_variant_fields().concat(this.mandatory);
this.mandatory = this.mandatory.concat(this.get_attributes_fields());
this.check_naming_series_based_on();
- this._super();
+ super.render_dialog();
this.init_post_render_dialog_operations();
this.preset_fields_for_template();
this.dialog.$wrapper.find('.edit-full').text(__('Edit in full page for more options like assets, serial nos, batches etc.'))
- },
+ }
- check_naming_series_based_on: function() {
+ check_naming_series_based_on() {
if (frappe.defaults.get_default("item_naming_by") === "Naming Series") {
this.mandatory = this.mandatory.filter(d => d.fieldname !== "item_code");
}
- },
+ }
- init_post_render_dialog_operations: function() {
+ init_post_render_dialog_operations() {
this.dialog.fields_dict.attribute_html.$wrapper.append(frappe.render_template("item_quick_entry"));
this.init_for_create_variant_trigger();
this.init_for_item_template_trigger();
@@ -29,9 +29,9 @@
this.toggle_manufacturer_fields();
this.dialog.get_field("item_template").df.hidden = 1;
this.dialog.get_field("item_template").refresh();
- },
+ }
- register_primary_action: function() {
+ register_primary_action() {
var me = this;
this.dialog.set_primary_action(__('Save'), function() {
if (me.dialog.working) return;
@@ -59,9 +59,9 @@
me.insert(variant_values);
}
});
- },
+ }
- insert: function(variant_values) {
+ insert(variant_values) {
let me = this;
return new Promise(resolve => {
frappe.call({
@@ -94,9 +94,9 @@
freeze: true
});
});
- },
+ }
- open_doc: function() {
+ open_doc() {
this.dialog.hide();
this.update_doc();
if (this.dialog.fields_dict.create_variant.$input.prop("checked")) {
@@ -106,9 +106,9 @@
} else {
frappe.set_route('Form', this.doctype, this.doc.name);
}
- },
+ }
- get_variant_fields: function() {
+ get_variant_fields() {
var variant_fields = [{
fieldname: "create_variant",
fieldtype: "Check",
@@ -130,9 +130,9 @@
}];
return variant_fields;
- },
+ }
- get_manufacturing_fields: function() {
+ get_manufacturing_fields() {
this.manufacturer_fields = [{
fieldtype: 'Link',
options: 'Manufacturer',
@@ -148,9 +148,9 @@
reqd: 0
}];
return this.manufacturer_fields;
- },
+ }
- get_attributes_fields: function() {
+ get_attributes_fields() {
var attribute_fields = [{
fieldname: 'attribute_html',
fieldtype: 'HTML'
@@ -158,18 +158,18 @@
attribute_fields = attribute_fields.concat(this.get_manufacturing_fields());
return attribute_fields;
- },
+ }
- init_for_create_variant_trigger: function() {
+ init_for_create_variant_trigger() {
var me = this;
this.dialog.fields_dict.create_variant.$input.on("click", function() {
me.preset_fields_for_template();
me.init_post_template_trigger_operations(false, [], true);
});
- },
+ }
- preset_fields_for_template: function() {
+ preset_fields_for_template() {
var for_variant = this.dialog.get_value('create_variant');
// setup template field, seen and mandatory if variant
@@ -195,9 +195,9 @@
f.refresh();
});
- },
+ }
- init_for_item_template_trigger: function() {
+ init_for_item_template_trigger() {
var me = this;
me.dialog.fields_dict["item_template"].df.onchange = () => {
@@ -228,9 +228,9 @@
me.init_post_template_trigger_operations(false, [], true);
}
}
- },
+ }
- init_post_template_trigger_operations: function(is_manufacturer, attributes, attributes_flag) {
+ init_post_template_trigger_operations(is_manufacturer, attributes, attributes_flag) {
this.attributes = attributes;
this.attribute_values = {};
this.attributes_count = attributes.length;
@@ -240,23 +240,23 @@
this.toggle_manufacturer_fields();
this.dialog.fields_dict.attribute_html.$wrapper.find(".attributes").toggleClass("hide-control", attributes_flag);
this.dialog.fields_dict.attribute_html.$wrapper.find(".attributes-header").toggleClass("hide-control", attributes_flag);
- },
+ }
- toggle_manufacturer_fields: function() {
+ toggle_manufacturer_fields() {
var me = this;
$.each(this.manufacturer_fields, function(i, dialog_field) {
me.dialog.get_field(dialog_field.fieldname).df.hidden = !me.is_manufacturer;
me.dialog.get_field(dialog_field.fieldname).df.reqd = dialog_field.fieldname == 'manufacturer' ? me.is_manufacturer : false;
me.dialog.get_field(dialog_field.fieldname).refresh();
});
- },
+ }
- initiate_render_attributes: function() {
+ initiate_render_attributes() {
this.dialog.fields_dict.attribute_html.$wrapper.find(".attributes").empty();
this.render_attributes(this.attributes);
- },
+ }
- render_attributes: function(attributes) {
+ render_attributes(attributes) {
var me = this;
this.dialog.get_field('attribute_html').toggle(true);
@@ -291,9 +291,9 @@
});
}
});
- },
+ }
- init_make_control: function(fieldtype, row) {
+ init_make_control(fieldtype, row) {
this[row.attribute] = frappe.ui.form.make_control({
df: {
"fieldtype": fieldtype,
@@ -305,9 +305,9 @@
only_input: false
});
this[row.attribute].make_input();
- },
+ }
- init_awesomplete_for_attribute: function(row) {
+ init_awesomplete_for_attribute(row) {
var me = this;
this[row.attribute].input.awesomplete = new Awesomplete(this[row.attribute].input, {
@@ -343,9 +343,9 @@
me.attribute_values[$(e.target).attr("data-fieldname")] = e.target.value;
$(e.target).closest(".frappe-control").toggleClass("has-error", e.target.value ? false : true);
});
- },
+ }
- get_variant_doc: function() {
+ get_variant_doc() {
var me = this;
var variant_doc = {};
var attribute = this.validate_mandatory_attributes();
@@ -381,9 +381,9 @@
})
}
return variant_doc;
- },
+ }
- validate_mandatory_attributes: function() {
+ validate_mandatory_attributes() {
var me = this;
var attribute = {};
var mandatory = [];
@@ -404,4 +404,4 @@
}
return attribute;
}
-});
\ No newline at end of file
+};
diff --git a/erpnext/public/js/utils/item_selector.js b/erpnext/public/js/utils/item_selector.js
index d04c488..9fc2640 100644
--- a/erpnext/public/js/utils/item_selector.js
+++ b/erpnext/public/js/utils/item_selector.js
@@ -1,5 +1,5 @@
-erpnext.ItemSelector = Class.extend({
- init: function(opts) {
+erpnext.ItemSelector = class ItemSelector {
+ constructor(opts) {
$.extend(this, opts);
if (!this.item_field) {
@@ -12,9 +12,9 @@
this.grid = this.frm.get_field("items").grid;
this.setup();
- },
+ }
- setup: function() {
+ setup() {
var me = this;
if(!this.grid.add_items_button) {
this.grid.add_items_button = this.grid.add_custom_button(__('Add Items'), function() {
@@ -26,9 +26,9 @@
setTimeout(function() { me.dialog.input.focus(); }, 1000);
});
}
- },
+ }
- make_dialog: function() {
+ make_dialog() {
this.dialog = new frappe.ui.Dialog({
title: __('Add Items')
});
@@ -53,9 +53,9 @@
me.timeout_id = undefined;
}, 500);
});
- },
+ }
- add_item: function(item_code) {
+ add_item(item_code) {
// add row or update qty
var added = false;
@@ -82,9 +82,9 @@
]);
}
- },
+ }
- render_items: function() {
+ render_items() {
let args = {
query: this.item_query,
filters: {}
@@ -107,4 +107,4 @@
me.dialog.results.html(frappe.render_template('item_selector', {'data':r.values}));
});
}
-});
\ No newline at end of file
+};
diff --git a/erpnext/public/js/utils/serial_no_batch_selector.js b/erpnext/public/js/utils/serial_no_batch_selector.js
index d49a813..d44c708 100644
--- a/erpnext/public/js/utils/serial_no_batch_selector.js
+++ b/erpnext/public/js/utils/serial_no_batch_selector.js
@@ -1,6 +1,6 @@
-erpnext.SerialNoBatchSelector = Class.extend({
- init: function(opts, show_dialog) {
+erpnext.SerialNoBatchSelector = class SerialNoBatchSelector {
+ constructor(opts, show_dialog) {
$.extend(this, opts);
this.show_dialog = show_dialog;
// frm, item, warehouse_details, has_batch, oldest
@@ -12,16 +12,16 @@
if(d && d.has_serial_no && !(this.show_dialog == false)) this.has_serial_no = 1;
this.setup();
- },
+ }
- setup: function() {
+ setup() {
this.item_code = this.item.item_code;
this.qty = this.item.qty;
this.make_dialog();
this.on_close_dialog();
- },
+ }
- make_dialog: function() {
+ make_dialog() {
var me = this;
this.data = this.oldest ? this.oldest : [];
@@ -176,15 +176,15 @@
}
this.dialog.show();
- },
+ }
- on_close_dialog: function() {
+ on_close_dialog() {
this.dialog.get_close_btn().on('click', () => {
this.on_close && this.on_close(this.item);
});
- },
+ }
- validate: function() {
+ validate() {
let values = this.values;
if(!values.warehouse) {
frappe.throw(__("Please select a warehouse"));
@@ -210,7 +210,7 @@
}
return true;
}
- },
+ }
update_batch_items() {
// clones an items if muliple batches are selected.
@@ -233,14 +233,14 @@
'selected_qty', this.values.warehouse);
});
}
- },
+ }
update_serial_no_item() {
// just updates serial no for the item
if(this.has_serial_no && !this.has_batch) {
this.map_row_values(this.item, this.values, 'serial_no', 'qty');
}
- },
+ }
update_batch_serial_no_items() {
// if serial no selected is from different batches, adds new rows for each batch.
@@ -281,14 +281,14 @@
});
})
}
- },
+ }
- batch_exists: function(batch) {
+ batch_exists(batch) {
const batches = this.frm.doc.items.map(data => data.batch_no);
return (batches && in_list(batches, batch)) ? true : false;
- },
+ }
- map_row_values: function(row, values, number, qty_field, warehouse) {
+ map_row_values(row, values, number, qty_field, warehouse) {
row.qty = values[qty_field];
row.transfer_qty = flt(values[qty_field]) * flt(row.conversion_factor);
row[number] = values[number];
@@ -301,9 +301,9 @@
}
this.frm.dirty();
- },
+ }
- update_total_qty: function() {
+ update_total_qty() {
let qty_field = this.dialog.fields_dict.qty;
let total_qty = 0;
@@ -312,9 +312,9 @@
});
qty_field.set_input(total_qty);
- },
+ }
- get_batch_fields: function() {
+ get_batch_fields() {
var me = this;
return [
@@ -425,9 +425,9 @@
},
}
];
- },
+ }
- get_serial_no_fields: function() {
+ get_serial_no_fields() {
var me = this;
this.serial_list = [];
@@ -510,4 +510,4 @@
}
];
}
-});
+};