refactor: Replace Class.extend with native class
diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js
index 0428573..eb02867 100644
--- a/erpnext/selling/sales_common.js
+++ b/erpnext/selling/sales_common.js
@@ -9,15 +9,15 @@
cur_frm.email_field = "contact_email";
frappe.provide("erpnext.selling");
-erpnext.selling.SellingController = erpnext.TransactionController.extend({
- setup: function() {
- this._super();
+erpnext.selling.SellingController = class SellingController extends erpnext.TransactionController {
+ setup() {
+ super.setup();
this.frm.add_fetch("sales_partner", "commission_rate", "commission_rate");
this.frm.add_fetch("sales_person", "commission_rate", "commission_rate");
- },
+ }
- onload: function() {
- this._super();
+ onload() {
+ super.onload();
this.setup_queries();
this.frm.set_query('shipping_rule', function() {
return {
@@ -26,9 +26,9 @@
}
};
});
- },
+ }
- setup_queries: function() {
+ setup_queries() {
var me = this;
$.each([["customer", "customer"],
@@ -81,10 +81,10 @@
});
}
- },
+ }
- refresh: function() {
- this._super();
+ refresh() {
+ super.refresh();
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
@@ -95,45 +95,45 @@
this.frm.toggle_display("packing_list", packing_list_exists ? true : false);
}
this.toggle_editable_price_list_rate();
- },
+ }
- customer: function() {
+ customer() {
var me = this;
erpnext.utils.get_party_details(this.frm, null, null, function() {
me.apply_price_list();
});
- },
+ }
- customer_address: function() {
+ customer_address() {
erpnext.utils.get_address_display(this.frm, "customer_address");
erpnext.utils.set_taxes_from_address(this.frm, "customer_address", "customer_address", "shipping_address_name");
- },
+ }
- shipping_address_name: function() {
+ shipping_address_name() {
erpnext.utils.get_address_display(this.frm, "shipping_address_name", "shipping_address");
erpnext.utils.set_taxes_from_address(this.frm, "shipping_address_name", "customer_address", "shipping_address_name");
- },
+ }
- sales_partner: function() {
+ sales_partner() {
this.apply_pricing_rule();
- },
+ }
- campaign: function() {
+ campaign() {
this.apply_pricing_rule();
- },
+ }
- selling_price_list: function() {
+ selling_price_list() {
this.apply_price_list();
this.set_dynamic_labels();
- },
+ }
- discount_percentage: function(doc, cdt, cdn) {
+ discount_percentage(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
item.discount_amount = 0.0;
this.apply_discount_on_item(doc, cdt, cdn, 'discount_percentage');
- },
+ }
- discount_amount: function(doc, cdt, cdn) {
+ discount_amount(doc, cdt, cdn) {
if(doc.name === cdn) {
return;
@@ -142,9 +142,9 @@
var item = frappe.get_doc(cdt, cdn);
item.discount_percentage = 0.0;
this.apply_discount_on_item(doc, cdt, cdn, 'discount_amount');
- },
+ }
- apply_discount_on_item: function(doc, cdt, cdn, field) {
+ apply_discount_on_item(doc, cdt, cdn, field) {
var item = frappe.get_doc(cdt, cdn);
if(!item.price_list_rate) {
item[field] = 0.0;
@@ -152,14 +152,14 @@
this.price_list_rate(doc, cdt, cdn);
}
this.set_gross_profit(item);
- },
+ }
- commission_rate: function() {
+ commission_rate() {
this.calculate_commission();
refresh_field("total_commission");
- },
+ }
- total_commission: function() {
+ total_commission() {
if(this.frm.doc.base_net_total) {
frappe.model.round_floats_in(this.frm.doc, ["base_net_total", "total_commission"]);
@@ -175,9 +175,9 @@
this.frm.set_value("commission_rate",
flt(this.frm.doc.total_commission * 100.0 / this.frm.doc.base_net_total));
}
- },
+ }
- allocated_percentage: function(doc, cdt, cdn) {
+ allocated_percentage(doc, cdt, cdn) {
var sales_person = frappe.get_doc(cdt, cdn);
if(sales_person.allocated_percentage) {
@@ -193,15 +193,15 @@
refresh_field(["allocated_percentage", "allocated_amount", "commission_rate","incentives"], sales_person.name,
sales_person.parentfield);
}
- },
+ }
- sales_person: function(doc, cdt, cdn) {
+ sales_person(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
this.calculate_incentive(row);
refresh_field("incentives",row.name,row.parentfield);
- },
+ }
- warehouse: function(doc, cdt, cdn) {
+ warehouse(doc, cdt, cdn) {
var me = this;
var item = frappe.get_doc(cdt, cdn);
@@ -239,18 +239,18 @@
});
}
})
- },
+ }
- toggle_editable_price_list_rate: function() {
+ toggle_editable_price_list_rate() {
var df = frappe.meta.get_docfield(this.frm.doc.doctype + " Item", "price_list_rate", this.frm.doc.name);
var editable_price_list_rate = cint(frappe.defaults.get_default("editable_price_list_rate"));
if(df && editable_price_list_rate) {
df.read_only = 0;
}
- },
+ }
- calculate_commission: function() {
+ calculate_commission() {
if(this.frm.fields_dict.commission_rate) {
if(this.frm.doc.commission_rate > 100) {
var msg = __(frappe.meta.get_label(this.frm.doc.doctype, "commission_rate", this.frm.doc.name)) +
@@ -262,9 +262,9 @@
this.frm.doc.total_commission = flt(this.frm.doc.base_net_total * this.frm.doc.commission_rate / 100.0,
precision("total_commission"));
}
- },
+ }
- calculate_contribution: function() {
+ calculate_contribution() {
var me = this;
$.each(this.frm.doc.doctype.sales_team || [], function(i, sales_person) {
frappe.model.round_floats_in(sales_person);
@@ -274,18 +274,18 @@
precision("allocated_amount", sales_person));
}
});
- },
+ }
- calculate_incentive: function(row) {
+ calculate_incentive(row) {
if(row.allocated_amount)
{
row.incentives = flt(
row.allocated_amount * row.commission_rate / 100.0,
precision("incentives", row));
}
- },
+ }
- batch_no: function(doc, cdt, cdn) {
+ batch_no(doc, cdt, cdn) {
var me = this;
var item = frappe.get_doc(cdt, cdn);
@@ -312,14 +312,14 @@
});
}
})
- },
+ }
- set_dynamic_labels: function() {
- this._super();
+ set_dynamic_labels() {
+ super.set_dynamic_labels();
this.set_product_bundle_help(this.frm.doc);
- },
+ }
- set_product_bundle_help: function(doc) {
+ set_product_bundle_help(doc) {
if(!cur_frm.fields_dict.packing_list) return;
if ((doc.packed_items || []).length) {
$(cur_frm.fields_dict.packing_list.row.wrapper).toggle(true);
@@ -337,9 +337,9 @@
}
}
refresh_field('product_bundle_help');
- },
+ }
- company_address: function() {
+ company_address() {
var me = this;
if(this.frm.doc.company_address) {
frappe.call({
@@ -354,42 +354,42 @@
} else {
this.frm.set_value("company_address_display", "");
}
- },
+ }
- conversion_factor: function(doc, cdt, cdn, dont_fetch_price_list_rate) {
- this._super(doc, cdt, cdn, dont_fetch_price_list_rate);
+ conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate) {
+ super.conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate);
if(frappe.meta.get_docfield(cdt, "stock_qty", cdn) &&
in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) {
if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return;
this.set_batch_number(cdt, cdn);
}
- },
+ }
- batch_no: function(doc, cdt, cdn) {
- this._super(doc, cdt, cdn);
- },
+ batch_no(doc, cdt, cdn) {
+ super.batch_no(doc, cdt, cdn);
+ }
- qty: function(doc, cdt, cdn) {
- this._super(doc, cdt, cdn);
+ qty(doc, cdt, cdn) {
+ super.qty(doc, cdt, cdn);
if(in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) {
if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return;
this.set_batch_number(cdt, cdn);
}
- },
+ }
/* Determine appropriate batch number and set it in the form.
* @param {string} cdt - Document Doctype
* @param {string} cdn - Document name
*/
- set_batch_number: function(cdt, cdn) {
+ set_batch_number(cdt, cdn) {
const doc = frappe.get_doc(cdt, cdn);
if (doc && doc.has_batch_no && doc.warehouse) {
this._set_batch_number(doc);
}
- },
+ }
- _set_batch_number: function(doc) {
+ _set_batch_number(doc) {
let args = {'item_code': doc.item_code, 'warehouse': doc.warehouse, 'qty': flt(doc.qty) * flt(doc.conversion_factor)};
if (doc.has_serial_no && doc.serial_no) {
args['serial_no'] = doc.serial_no
@@ -406,9 +406,9 @@
}
}
});
- },
+ }
- 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",
@@ -426,7 +426,7 @@
})
}
}
-});
+};
frappe.ui.form.on(cur_frm.doctype,"project", function(frm) {
if(in_list(["Delivery Note", "Sales Invoice"], frm.doc.doctype)) {