refactor: Replace Class.extend with native class

This commit is contained in:
Faris Ansari 2021-04-23 08:04:00 +05:30
parent 5e1cb5e4bc
commit 1fe891b287
44 changed files with 1200 additions and 1196 deletions

View File

@ -194,19 +194,19 @@ var update_jv_details = function(doc, r) {
refresh_field("accounts");
}
erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
onload: function() {
erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Controller {
onload() {
this.load_defaults();
this.setup_queries();
this.setup_balance_formatter();
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
},
}
onload_post_render: function() {
onload_post_render() {
cur_frm.get_field("accounts").grid.set_multiple_add("account");
},
}
load_defaults: function() {
load_defaults() {
//this.frm.show_print_first = true;
if(this.frm.doc.__islocal && this.frm.doc.company) {
frappe.model.set_default_values(this.frm.doc);
@ -216,9 +216,9 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
var posting_date = this.frm.doc.posting_date;
if(!this.frm.doc.amended_from) this.frm.set_value('posting_date', posting_date || frappe.datetime.get_today());
}
},
}
setup_queries: function() {
setup_queries() {
var me = this;
me.frm.set_query("account", "accounts", function(doc, cdt, cdn) {
@ -324,9 +324,9 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
});
},
}
setup_balance_formatter: function() {
setup_balance_formatter() {
var me = this;
$.each(["balance", "party_balance"], function(i, field) {
var df = frappe.meta.get_docfield("Journal Entry Account", field, me.frm.doc.name);
@ -339,9 +339,9 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
+ "</div>";
}
})
},
}
reference_name: function(doc, cdt, cdn) {
reference_name(doc, cdt, cdn) {
var d = frappe.get_doc(cdt, cdn);
if(d.reference_name) {
@ -353,9 +353,9 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
this.get_outstanding('Journal Entry', d.reference_name, doc.company, d);
}
}
},
}
get_outstanding: function(doctype, docname, company, child, due_date) {
get_outstanding(doctype, docname, company, child, due_date) {
var me = this;
var args = {
"doctype": doctype,
@ -377,9 +377,9 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
}
}
});
},
}
accounts_add: function(doc, cdt, cdn) {
accounts_add(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
$.each(doc.accounts, function(i, d) {
if(d.account && d.party && d.party_type) {
@ -402,9 +402,9 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
cur_frm.cscript.update_totals(doc);
erpnext.accounts.dimensions.copy_dimension_from_first_row(this.frm, cdt, cdn, 'accounts');
},
}
});
};
cur_frm.script_manager.make(erpnext.accounts.JournalEntry);

View File

@ -34,8 +34,8 @@ frappe.ui.form.on("Payment Reconciliation Payment", {
}
});
erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.extend({
onload: function() {
erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationController extends frappe.ui.form.Controller {
onload() {
var me = this;
this.frm.set_query("party", function() {
@ -84,18 +84,18 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
frappe.throw({message: __("Please Select Both Company and Party Type First"), title: title});
}
};
},
}
refresh: function() {
refresh() {
this.frm.disable_save();
this.toggle_primary_action();
},
}
onload_post_render: function() {
onload_post_render() {
this.toggle_primary_action();
},
}
party: function() {
party() {
var me = this
if (!me.frm.doc.receivable_payable_account && me.frm.doc.party_type && me.frm.doc.party) {
return frappe.call({
@ -112,9 +112,9 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
}
});
}
},
}
get_unreconciled_entries: function() {
get_unreconciled_entries() {
var me = this;
return this.frm.call({
doc: me.frm.doc,
@ -125,9 +125,9 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
}
});
},
}
reconcile: function() {
reconcile() {
var me = this;
var show_dialog = me.frm.doc.payments.filter(d => d.difference_amount && !d.difference_account);
@ -209,9 +209,9 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
} else {
this.reconcile_payment_entries();
}
},
}
reconcile_payment_entries: function() {
reconcile_payment_entries() {
var me = this;
return this.frm.call({
@ -222,9 +222,9 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
me.toggle_primary_action();
}
});
},
}
set_invoice_options: function() {
set_invoice_options() {
var me = this;
var invoices = [];
@ -243,9 +243,9 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
}
refresh_field("payments");
},
}
toggle_primary_action: function() {
toggle_primary_action() {
if ((this.frm.doc.payments || []).length) {
this.frm.fields_dict.reconcile.$input
&& this.frm.fields_dict.reconcile.$input.addClass("btn-primary");
@ -259,6 +259,6 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext
}
}
});
};
$.extend(cur_frm.cscript, new erpnext.accounts.PaymentReconciliationController({frm: cur_frm}));

View File

@ -4,18 +4,18 @@
{% include 'erpnext/selling/sales_common.js' %};
frappe.provide("erpnext.accounts");
erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend({
erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnext.selling.SellingController {
setup(doc) {
this.setup_posting_date_time_check();
this._super(doc);
},
super.setup(doc);
}
company: function() {
company() {
erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype);
},
}
onload(doc) {
this._super();
super.onload();
this.frm.ignore_doctypes_on_cancel_all = ['POS Invoice Merge Log'];
if(doc.__islocal && doc.is_pos && frappe.get_route_str() !== 'point-of-sale') {
this.frm.script_manager.trigger("is_pos");
@ -23,10 +23,10 @@ erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend(
}
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
},
}
refresh(doc) {
this._super();
super.refresh();
if (doc.docstatus == 1 && !doc.is_return) {
this.frm.add_custom_button(__('Return'), this.make_sales_return, __('Create'));
this.frm.page.set_inner_btn_group_as_primary(__('Create'));
@ -36,13 +36,13 @@ erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend(
this.frm.return_print_format = "Sales Invoice Return";
this.frm.set_value('consolidated_invoice', '');
}
},
}
is_pos: function() {
is_pos() {
this.set_pos_data();
},
}
set_pos_data: async function() {
async set_pos_data() {
if(this.frm.doc.is_pos) {
this.frm.set_value("allocate_advances_automatically", 0);
if(!this.frm.doc.company) {
@ -69,7 +69,7 @@ erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend(
}
}
}
},
}
customer() {
if (!this.frm.doc.customer) return
@ -86,13 +86,13 @@ erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend(
}, () => {
this.apply_pricing_rule();
});
},
}
amount: function(){
amount(){
this.write_off_outstanding_amount_automatically()
},
}
change_amount: function(){
change_amount(){
if(this.frm.doc.paid_amount > this.frm.doc.grand_total){
this.calculate_write_off_amount();
}else {
@ -101,16 +101,16 @@ erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend(
}
this.frm.refresh_fields();
},
}
loyalty_amount: function(){
loyalty_amount(){
this.calculate_outstanding_amount();
this.frm.refresh_field("outstanding_amount");
this.frm.refresh_field("paid_amount");
this.frm.refresh_field("base_paid_amount");
},
}
write_off_outstanding_amount_automatically: function() {
write_off_outstanding_amount_automatically() {
if(cint(this.frm.doc.write_off_outstanding_amount_automatically)) {
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "paid_amount"]);
// this will make outstanding amount 0
@ -125,15 +125,15 @@ erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend(
this.calculate_outstanding_amount(false);
this.frm.refresh_fields();
},
}
make_sales_return: function() {
make_sales_return() {
frappe.model.open_mapped_doc({
method: "erpnext.accounts.doctype.pos_invoice.pos_invoice.make_sales_return",
frm: cur_frm
})
},
})
}
}
$.extend(cur_frm.cscript, new erpnext.selling.POSInvoiceController({ frm: cur_frm }))

View File

@ -4,10 +4,10 @@
frappe.provide("erpnext.accounts");
{% include 'erpnext/public/js/controllers/buying.js' %};
erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
setup: function(doc) {
erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying.BuyingController {
setup(doc) {
this.setup_posting_date_time_check();
this._super(doc);
super.setup(doc);
// formatter for purchase invoice item
if(this.frm.doc.update_stock) {
@ -25,14 +25,14 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
}
};
});
},
}
company: function() {
company() {
erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype);
},
}
onload: function() {
this._super();
onload() {
super.onload();
if(!this.frm.doc.__islocal) {
// show credit_to in print format
@ -48,11 +48,11 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
}
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
},
}
refresh: function(doc) {
refresh(doc) {
const me = this;
this._super();
super.refresh();
hide_fields(this.frm.doc);
// Show / Hide button
@ -161,26 +161,26 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
}
this.frm.set_df_property("tax_withholding_category", "hidden", doc.apply_tds ? 0 : 1);
},
}
unblock_invoice: function() {
unblock_invoice() {
const me = this;
frappe.call({
'method': 'erpnext.accounts.doctype.purchase_invoice.purchase_invoice.unblock_invoice',
'args': {'name': me.frm.doc.name},
'callback': (r) => me.frm.reload_doc()
});
},
}
block_invoice: function() {
block_invoice() {
this.make_comment_dialog_and_block_invoice();
},
}
change_release_date: function() {
change_release_date() {
this.make_dialog_and_set_release_date();
},
}
can_change_release_date: function(date) {
can_change_release_date(date) {
const diff = frappe.datetime.get_diff(date, frappe.datetime.nowdate());
if (diff < 0) {
frappe.throw(__('New release date should be in the future'));
@ -188,9 +188,9 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
} else {
return true;
}
},
}
make_comment_dialog_and_block_invoice: function(){
make_comment_dialog_and_block_invoice(){
const me = this;
const title = __('Block Invoice');
@ -232,9 +232,9 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
});
this.dialog.show();
},
}
make_dialog_and_set_release_date: function() {
make_dialog_and_set_release_date() {
const me = this;
const title = __('Set New Release Date');
@ -263,17 +263,17 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
});
this.dialog.show();
},
}
set_release_date: function(data) {
set_release_date(data) {
return frappe.call({
'method': 'erpnext.accounts.doctype.purchase_invoice.purchase_invoice.change_release_date',
'args': data,
'callback': (r) => this.frm.reload_doc()
});
},
}
supplier: function() {
supplier() {
var me = this;
// Do not update if inter company reference is there as the details will already be updated
@ -295,9 +295,9 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
me.frm.set_df_property("apply_tds", "read_only", me.frm.supplier_tds ? 0 : 1);
me.frm.set_df_property("tax_withholding_category", "hidden", me.frm.supplier_tds ? 0 : 1);
})
},
}
apply_tds: function(frm) {
apply_tds(frm) {
var me = this;
if (!me.frm.doc.apply_tds) {
@ -307,9 +307,9 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
me.frm.set_value("tax_withholding_category", me.frm.supplier_tds);
me.frm.set_df_property("tax_withholding_category", "hidden", 0);
}
},
}
credit_to: function() {
credit_to() {
var me = this;
if(this.frm.doc.credit_to) {
me.frm.call({
@ -327,16 +327,16 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
}
});
}
},
}
make_inter_company_invoice: function(frm) {
make_inter_company_invoice(frm) {
frappe.model.open_mapped_doc({
method: "erpnext.accounts.doctype.purchase_invoice.purchase_invoice.make_inter_company_sales_invoice",
frm: frm
});
},
}
is_paid: function() {
is_paid() {
hide_fields(this.frm.doc);
if(cint(this.frm.doc.is_paid)) {
this.frm.set_value("allocate_advances_automatically", 0);
@ -347,44 +347,44 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
}
this.calculate_outstanding_amount();
this.frm.refresh_fields();
},
}
write_off_amount: function() {
write_off_amount() {
this.set_in_company_currency(this.frm.doc, ["write_off_amount"]);
this.calculate_outstanding_amount();
this.frm.refresh_fields();
},
}
paid_amount: function() {
paid_amount() {
this.set_in_company_currency(this.frm.doc, ["paid_amount"]);
this.write_off_amount();
this.frm.refresh_fields();
},
}
allocated_amount: function() {
allocated_amount() {
this.calculate_total_advance();
this.frm.refresh_fields();
},
}
items_add: function(doc, cdt, cdn) {
items_add(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
this.frm.script_manager.copy_from_first_row("items", row,
["expense_account", "cost_center", "project"]);
},
}
on_submit: function() {
on_submit() {
$.each(this.frm.doc["items"] || [], function(i, row) {
if(row.purchase_receipt) frappe.model.clear_doc("Purchase Receipt", row.purchase_receipt)
})
},
}
make_debit_note: function() {
make_debit_note() {
frappe.model.open_mapped_doc({
method: "erpnext.accounts.doctype.purchase_invoice.purchase_invoice.make_debit_note",
frm: cur_frm
})
},
});
}
};
cur_frm.script_manager.make(erpnext.accounts.PurchaseInvoice);

View File

@ -2,23 +2,24 @@
// License: GNU General Public License v3. See license.txt
// print heading
frappe.provide('cur_frm.pformat')
cur_frm.pformat.print_heading = 'Invoice';
{% include 'erpnext/selling/sales_common.js' %};
frappe.provide("erpnext.accounts");
erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({
setup: function(doc) {
erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends erpnext.selling.SellingController {
setup(doc) {
this.setup_posting_date_time_check();
this._super(doc);
},
company: function() {
super.setup(doc);
}
company() {
erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype);
},
onload: function() {
}
onload() {
var me = this;
this._super();
super.onload();
this.frm.ignore_doctypes_on_cancel_all = ['POS Invoice'];
if(!this.frm.doc.__islocal && !this.frm.doc.customer && this.frm.doc.debit_to) {
@ -38,11 +39,11 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
}
erpnext.queries.setup_warehouse_query(this.frm);
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
},
}
refresh: function(doc, dt, dn) {
refresh(doc, dt, dn) {
const me = this;
this._super();
super.refresh();
if(cur_frm.msgbox && cur_frm.msgbox.$wrapper.is(":visible")) {
// hide new msgbox
cur_frm.msgbox.hide();
@ -141,16 +142,16 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
}, __('Create'));
}
}
},
}
make_maintenance_schedule: function() {
make_maintenance_schedule() {
frappe.model.open_mapped_doc({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.make_maintenance_schedule",
frm: cur_frm
})
},
}
on_submit: function(doc, dt, dn) {
on_submit(doc, dt, dn) {
var me = this;
if (frappe.get_route()[0] != 'Form') {
@ -160,9 +161,9 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
$.each(doc["items"], function(i, row) {
if(row.delivery_note) frappe.model.clear_doc("Delivery Note", row.delivery_note)
})
},
}
set_default_print_format: function() {
set_default_print_format() {
// set default print format to POS type or Credit Note
if(cur_frm.doc.is_pos) {
if(cur_frm.pos_print_format) {
@ -183,9 +184,9 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
cur_frm.meta._default_print_format = null;
}
}
},
}
sales_order_btn: function() {
sales_order_btn() {
var me = this;
this.$sales_order_btn = this.frm.add_custom_button(__('Sales Order'),
function() {
@ -204,9 +205,9 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
}
})
}, __("Get Items From"));
},
}
quotation_btn: function() {
quotation_btn() {
var me = this;
this.$quotation_btn = this.frm.add_custom_button(__('Quotation'),
function() {
@ -228,9 +229,9 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
}
})
}, __("Get Items From"));
},
}
delivery_note_btn: function() {
delivery_note_btn() {
var me = this;
this.$delivery_note_btn = this.frm.add_custom_button(__('Delivery Note'),
function() {
@ -256,12 +257,12 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
}
});
}, __("Get Items From"));
},
}
tc_name: function() {
tc_name() {
this.get_terms();
},
customer: function() {
}
customer() {
if (this.frm.doc.is_pos){
var pos_profile = this.frm.doc.pos_profile;
}
@ -292,16 +293,16 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
}
});
}
},
}
make_inter_company_invoice: function() {
make_inter_company_invoice() {
frappe.model.open_mapped_doc({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.make_inter_company_purchase_invoice",
frm: me.frm
});
},
}
debit_to: function() {
debit_to() {
var me = this;
if(this.frm.doc.debit_to) {
me.frm.call({
@ -319,14 +320,14 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
}
});
}
},
}
allocated_amount: function() {
allocated_amount() {
this.calculate_total_advance();
this.frm.refresh_fields();
},
}
write_off_outstanding_amount_automatically: function() {
write_off_outstanding_amount_automatically() {
if(cint(this.frm.doc.write_off_outstanding_amount_automatically)) {
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "paid_amount"]);
// this will make outstanding amount 0
@ -341,39 +342,39 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
this.calculate_outstanding_amount(false);
this.frm.refresh_fields();
},
}
write_off_amount: function() {
write_off_amount() {
this.set_in_company_currency(this.frm.doc, ["write_off_amount"]);
this.write_off_outstanding_amount_automatically();
},
}
items_add: function(doc, cdt, cdn) {
items_add(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
this.frm.script_manager.copy_from_first_row("items", row, ["income_account", "cost_center"]);
},
}
set_dynamic_labels: function() {
this._super();
set_dynamic_labels() {
super.set_dynamic_labels();
this.frm.events.hide_fields(this.frm)
},
}
items_on_form_rendered: function() {
items_on_form_rendered() {
erpnext.setup_serial_no();
},
}
packed_items_on_form_rendered: function(doc, grid_row) {
packed_items_on_form_rendered(doc, grid_row) {
erpnext.setup_serial_no();
},
}
make_sales_return: function() {
make_sales_return() {
frappe.model.open_mapped_doc({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.make_sales_return",
frm: cur_frm
})
},
}
asset: function(frm, cdt, cdn) {
asset(frm, cdt, cdn) {
var row = locals[cdt][cdn];
if(row.asset) {
frappe.call({
@ -387,18 +388,18 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
}
})
}
},
}
is_pos: function(frm){
is_pos(frm){
this.set_pos_data();
},
}
pos_profile: function() {
pos_profile() {
this.frm.doc.taxes = []
this.set_pos_data();
},
}
set_pos_data: function() {
set_pos_data() {
if(this.frm.doc.is_pos) {
this.frm.set_value("allocate_advances_automatically", 0);
if(!this.frm.doc.company) {
@ -428,13 +429,13 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
}
}
else this.frm.trigger("refresh");
},
}
amount: function(){
amount(){
this.write_off_outstanding_amount_automatically()
},
}
change_amount: function(){
change_amount(){
if(this.frm.doc.paid_amount > this.frm.doc.grand_total){
this.calculate_write_off_amount();
}else {
@ -443,15 +444,15 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
}
this.frm.refresh_fields();
},
}
loyalty_amount: function(){
loyalty_amount(){
this.calculate_outstanding_amount();
this.frm.refresh_field("outstanding_amount");
this.frm.refresh_field("paid_amount");
this.frm.refresh_field("base_paid_amount");
}
});
};
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new erpnext.accounts.SalesInvoiceController({frm: cur_frm}));

View File

@ -61,8 +61,8 @@ frappe.ui.form.on("Purchase Order Item", {
}
});
erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({
setup: function() {
erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends erpnext.buying.BuyingController {
setup() {
this.frm.custom_make_buttons = {
'Purchase Receipt': 'Purchase Receipt',
'Purchase Invoice': 'Purchase Invoice',
@ -70,13 +70,13 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
'Payment Entry': 'Payment',
}
this._super();
super.setup();
},
}
refresh: function(doc, cdt, cdn) {
refresh(doc, cdt, cdn) {
var me = this;
this._super();
super.refresh();
var allow_receipt = false;
var is_drop_ship = false;
@ -182,9 +182,9 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
} else if(doc.docstatus===0) {
cur_frm.cscript.add_from_mappers();
}
},
}
get_items_from_open_material_requests: function() {
get_items_from_open_material_requests() {
erpnext.utils.map_current_doc({
method: "erpnext.stock.doctype.material_request.material_request.make_purchase_order_based_on_supplier",
args: {
@ -202,17 +202,17 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
},
get_query_method: "erpnext.stock.doctype.material_request.material_request.get_material_requests_based_on_supplier"
});
},
}
validate: function() {
validate() {
set_schedule_date(this.frm);
},
}
has_unsupplied_items: function() {
has_unsupplied_items() {
return this.frm.doc['supplied_items'].some(item => item.required_qty != item.supplied_qty)
},
}
make_stock_entry: function() {
make_stock_entry() {
var items = $.map(cur_frm.doc.items, function(d) { return d.bom ? d.item_code : false; });
var me = this;
@ -326,9 +326,9 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
me.dialog.hide();
});
},
}
_make_rm_stock_entry: function(rm_items) {
_make_rm_stock_entry(rm_items) {
frappe.call({
method:"erpnext.buying.doctype.purchase_order.purchase_order.make_rm_stock_entry",
args: {
@ -341,31 +341,31 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
}
});
},
}
make_inter_company_order: function(frm) {
make_inter_company_order(frm) {
frappe.model.open_mapped_doc({
method: "erpnext.buying.doctype.purchase_order.purchase_order.make_inter_company_sales_order",
frm: frm
});
},
}
make_purchase_receipt: function() {
make_purchase_receipt() {
frappe.model.open_mapped_doc({
method: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_receipt",
frm: cur_frm,
freeze_message: __("Creating Purchase Receipt ...")
})
},
}
make_purchase_invoice: function() {
make_purchase_invoice() {
frappe.model.open_mapped_doc({
method: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_invoice",
frm: cur_frm
})
},
}
add_from_mappers: function() {
add_from_mappers() {
var me = this;
this.frm.add_custom_button(__('Material Request'),
function() {
@ -471,13 +471,13 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
}
});
}, __("Tools"));
},
}
tc_name: function() {
tc_name() {
this.get_terms();
},
}
items_add: function(doc, cdt, cdn) {
items_add(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
if(doc.schedule_date) {
row.schedule_date = doc.schedule_date;
@ -485,13 +485,13 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
} else {
this.frm.script_manager.copy_from_first_row("items", row, ["schedule_date"]);
}
},
}
unhold_purchase_order: function(){
unhold_purchase_order(){
cur_frm.cscript.update_status("Resume", "Draft")
},
}
hold_purchase_order: function(){
hold_purchase_order(){
var me = this;
var d = new frappe.ui.Dialog({
title: __('Reason for Hold'),
@ -523,28 +523,28 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
}
});
d.show();
},
}
unclose_purchase_order: function(){
unclose_purchase_order(){
cur_frm.cscript.update_status('Re-open', 'Submitted')
},
}
close_purchase_order: function(){
close_purchase_order(){
cur_frm.cscript.update_status('Close', 'Closed')
},
}
delivered_by_supplier: function(){
delivered_by_supplier(){
cur_frm.cscript.update_status('Deliver', 'Delivered')
},
}
items_on_form_rendered: function() {
set_schedule_date(this.frm);
},
schedule_date: function() {
items_on_form_rendered() {
set_schedule_date(this.frm);
}
});
schedule_date() {
set_schedule_date(this.frm);
}
};
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new erpnext.buying.PurchaseOrderController({frm: cur_frm}));

View File

@ -205,10 +205,10 @@ frappe.ui.form.on("Request for Quotation Supplier",{
})
erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.extend({
refresh: function() {
erpnext.buying.RequestforQuotationController = class RequestforQuotationController extends erpnext.buying.BuyingController {
refresh() {
var me = this;
this._super();
super.refresh();
if (this.frm.doc.docstatus===0) {
this.frm.add_custom_button(__('Material Request'),
function() {
@ -302,17 +302,17 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e
me.get_suppliers_button(me.frm);
}, __("Tools"));
}
},
}
calculate_taxes_and_totals: function() {
calculate_taxes_and_totals() {
return;
},
}
tc_name: function() {
tc_name() {
this.get_terms();
},
}
get_suppliers_button: function (frm) {
get_suppliers_button (frm) {
var doc = frm.doc;
var dialog = new frappe.ui.Dialog({
title: __("Get Suppliers"),
@ -410,8 +410,8 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e
});
dialog.show();
},
});
}
};
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new erpnext.buying.RequestforQuotationController({frm: cur_frm}));

View File

@ -4,19 +4,19 @@
// attach required files
{% include 'erpnext/public/js/controllers/buying.js' %};
erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.extend({
setup: function() {
erpnext.buying.SupplierQuotationController = class SupplierQuotationController extends erpnext.buying.BuyingController {
setup() {
this.frm.custom_make_buttons = {
'Purchase Order': 'Purchase Order',
'Quotation': 'Quotation'
}
this._super();
},
super.setup();
}
refresh: function() {
refresh() {
var me = this;
this._super();
super.refresh();
if (this.frm.doc.__islocal && !this.frm.doc.valid_till) {
this.frm.set_value('valid_till', frappe.datetime.add_months(this.frm.doc.transaction_date, 1));
@ -77,22 +77,22 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext
})
}, __("Get Items From"));
}
},
}
make_purchase_order: function() {
make_purchase_order() {
frappe.model.open_mapped_doc({
method: "erpnext.buying.doctype.supplier_quotation.supplier_quotation.make_purchase_order",
frm: cur_frm
})
},
make_quotation: function() {
}
make_quotation() {
frappe.model.open_mapped_doc({
method: "erpnext.buying.doctype.supplier_quotation.supplier_quotation.make_quotation",
frm: cur_frm
})
}
});
};
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new erpnext.buying.SupplierQuotationController({frm: cur_frm}));

View File

@ -4,8 +4,8 @@
frappe.provide("erpnext");
cur_frm.email_field = "email_id";
erpnext.LeadController = frappe.ui.form.Controller.extend({
setup: function () {
erpnext.LeadController = class LeadController extends frappe.ui.form.Controller {
setup () {
this.frm.make_methods = {
'Customer': this.make_customer,
'Quotation': this.make_quotation,
@ -13,9 +13,9 @@ erpnext.LeadController = frappe.ui.form.Controller.extend({
};
this.frm.toggle_reqd("lead_name", !this.frm.doc.organization_lead);
},
}
onload: function () {
onload () {
this.frm.set_query("customer", function (doc, cdt, cdn) {
return { query: "erpnext.controllers.queries.customer_query" }
});
@ -27,9 +27,9 @@ erpnext.LeadController = frappe.ui.form.Controller.extend({
this.frm.set_query("contact_by", function (doc, cdt, cdn) {
return { query: "frappe.core.doctype.user.user.user_query" }
});
},
}
refresh: function () {
refresh () {
let doc = this.frm.doc;
erpnext.toggle_naming_series();
frappe.dynamic_link = { doc: doc, fieldname: 'name', doctype: 'Lead' }
@ -45,47 +45,47 @@ erpnext.LeadController = frappe.ui.form.Controller.extend({
} else {
frappe.contacts.clear_address_and_contact(this.frm);
}
},
}
make_customer: function () {
make_customer () {
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_customer",
frm: cur_frm
})
},
}
make_opportunity: function () {
make_opportunity () {
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_opportunity",
frm: cur_frm
})
},
}
make_quotation: function () {
make_quotation () {
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.lead.lead.make_quotation",
frm: cur_frm
})
},
}
organization_lead: function () {
organization_lead () {
this.frm.toggle_reqd("lead_name", !this.frm.doc.organization_lead);
this.frm.toggle_reqd("company_name", this.frm.doc.organization_lead);
},
}
company_name: function () {
company_name () {
if (this.frm.doc.organization_lead && !this.frm.doc.lead_name) {
this.frm.set_value("lead_name", this.frm.doc.company_name);
}
},
}
contact_date: function () {
contact_date () {
if (this.frm.doc.contact_date) {
let d = moment(this.frm.doc.contact_date);
d.add(1, "day");
this.frm.set_value("ends_on", d.format(frappe.defaultDatetimeFormat));
}
}
});
};
$.extend(cur_frm.cscript, new erpnext.LeadController({ frm: cur_frm }));

View File

@ -145,8 +145,8 @@ frappe.ui.form.on("Opportunity", {
})
// TODO commonify this code
erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({
onload: function() {
erpnext.crm.Opportunity = class Opportunity extends frappe.ui.form.Controller {
onload() {
if(!this.frm.doc.status) {
frm.set_value('status', 'Open');
@ -159,9 +159,9 @@ erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({
}
this.setup_queries();
},
}
setup_queries: function() {
setup_queries() {
var me = this;
if(this.frm.fields_dict.contact_by.df.options.match(/^User/)) {
@ -185,15 +185,15 @@ erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({
else if (me.frm.doc.opportunity_from == "Customer") {
me.frm.set_query('party_name', erpnext.queries['customer']);
}
},
}
create_quotation: function() {
create_quotation() {
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.opportunity.opportunity.make_quotation",
frm: cur_frm
})
}
});
};
$.extend(cur_frm.cscript, new erpnext.crm.Opportunity({frm: cur_frm}));

View File

@ -72,8 +72,8 @@ frappe.ui.form.on('Student Attendance Tool', {
});
education.StudentsEditor = Class.extend({
init: function(frm, wrapper, students) {
education.StudentsEditor = class StudentsEditor {
constructor(frm, wrapper, students) {
this.wrapper = wrapper;
this.frm = frm;
if(students.length > 0) {
@ -81,8 +81,8 @@ education.StudentsEditor = Class.extend({
} else {
this.show_empty_state();
}
},
make: function(frm, students) {
}
make(frm, students) {
var me = this;
$(this.wrapper).empty();
@ -173,13 +173,13 @@ education.StudentsEditor = Class.extend({
});
$(htmls.join("")).appendTo(me.wrapper);
},
}
show_empty_state: function() {
show_empty_state() {
$(this.wrapper).html(
`<div class="text-center text-muted" style="line-height: 100px;">
${__("No Students in")} ${this.frm.doc.student_group}
</div>`
);
}
});
};

View File

@ -9,14 +9,14 @@ frappe.ui.form.on('Exercise Type', {
}
});
erpnext.ExerciseEditor = Class.extend({
init: function(frm, wrapper) {
erpnext.ExerciseEditor = class ExerciseEditor {
constructor(frm, wrapper) {
this.wrapper = wrapper;
this.frm = frm;
this.make(frm, wrapper);
},
}
make: function(frm, wrapper) {
make(frm, wrapper) {
$(this.wrapper).empty();
this.exercise_toolbar = $('<p>\
@ -38,9 +38,9 @@ erpnext.ExerciseEditor = Class.extend({
this.make_cards(frm);
this.make_buttons(frm);
}
},
}
make_cards: function(frm) {
make_cards(frm) {
var me = this;
$(me.exercise_cards).empty();
@ -60,9 +60,9 @@ erpnext.ExerciseEditor = Class.extend({
</div>
</div>`, {image_src: step.image, title: step.title, description: step.description, col_id: "col-"+i, card_id: "card-"+i, id: i})).appendTo(me.row);
});
},
}
make_buttons: function(frm) {
make_buttons(frm) {
let me = this;
$('.btn-edit').on('click', function() {
let id = $(this).attr('data-id');
@ -82,9 +82,9 @@ erpnext.ExerciseEditor = Class.extend({
frm.dirty();
}, 300);
});
},
}
show_add_card_dialog: function(frm) {
show_add_card_dialog(frm) {
let me = this;
let d = new frappe.ui.Dialog({
title: __('Add Exercise Step'),
@ -137,9 +137,9 @@ erpnext.ExerciseEditor = Class.extend({
primary_action_label: __('Add')
});
d.show();
},
}
show_edit_card_dialog: function(frm, id) {
show_edit_card_dialog(frm, id) {
let new_dialog = new frappe.ui.Dialog({
title: __("Edit Exercise Step"),
fields: [
@ -183,4 +183,4 @@ erpnext.ExerciseEditor = Class.extend({
});
new_dialog.show();
}
});
};

View File

@ -2,8 +2,8 @@
// License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.hr");
erpnext.hr.EmployeeController = frappe.ui.form.Controller.extend({
setup: function() {
erpnext.hr.EmployeeController = class EmployeeController extends frappe.ui.form.Controller {
setup() {
this.frm.fields_dict.user_id.get_query = function(doc, cdt, cdn) {
return {
query: "frappe.core.doctype.user.user.user_query",
@ -12,30 +12,30 @@ erpnext.hr.EmployeeController = frappe.ui.form.Controller.extend({
}
this.frm.fields_dict.reports_to.get_query = function(doc, cdt, cdn) {
return { query: "erpnext.controllers.queries.employee_query"} }
},
}
refresh: function() {
refresh() {
var me = this;
erpnext.toggle_naming_series();
},
}
date_of_birth: function() {
date_of_birth() {
return cur_frm.call({
method: "get_retirement_date",
args: {date_of_birth: this.frm.doc.date_of_birth}
});
},
}
salutation: function() {
salutation() {
if(this.frm.doc.salutation) {
this.frm.set_value("gender", {
"Mr": "Male",
"Ms": "Female"
}[this.frm.doc.salutation]);
}
},
}
});
};
frappe.ui.form.on('Employee',{
setup: function(frm) {
frm.set_query("leave_policy", function() {

View File

@ -68,13 +68,13 @@ erpnext.employee_attendance_tool = {
}
}
erpnext.MarkedEmployee = Class.extend({
init: function(frm, wrapper, employee) {
erpnext.MarkedEmployee = class MarkedEmployee {
constructor(frm, wrapper, employee) {
this.wrapper = wrapper;
this.frm = frm;
this.make(frm, employee);
},
make: function(frm, employee) {
}
make(frm, employee) {
var me = this;
$(this.wrapper).empty();
@ -104,16 +104,16 @@ erpnext.MarkedEmployee = Class.extend({
})).appendTo(row);
});
}
});
};
erpnext.EmployeeSelector = Class.extend({
init: function(frm, wrapper, employee) {
erpnext.EmployeeSelector = class EmployeeSelector {
constructor(frm, wrapper, employee) {
this.wrapper = wrapper;
this.frm = frm;
this.make(frm, employee);
},
make: function(frm, employee) {
}
make(frm, employee) {
var me = this;
$(this.wrapper).empty();
@ -266,6 +266,6 @@ erpnext.EmployeeSelector = Class.extend({
mark_employee_toolbar.appendTo($(this.wrapper));
}
});
};

View File

@ -5,19 +5,19 @@
frappe.provide("erpnext.hr");
erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({
onload: function() {
erpnext.hr.AttendanceControlPanel = class AttendanceControlPanel extends frappe.ui.form.Controller {
onload() {
this.frm.set_value("att_fr_date", frappe.datetime.get_today());
this.frm.set_value("att_to_date", frappe.datetime.get_today());
},
}
refresh: function() {
refresh() {
this.frm.disable_save();
this.show_upload();
this.setup_import_progress();
},
}
get_template:function() {
get_template() {
if(!this.frm.doc.att_fr_date || !this.frm.doc.att_to_date) {
frappe.msgprint(__("Attendance From Date and Attendance To Date is mandatory"));
return;
@ -28,7 +28,7 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({
from_date: this.frm.doc.att_fr_date,
to_date: this.frm.doc.att_to_date,
});
},
}
show_upload() {
var $wrapper = $(cur_frm.fields_dict.upload_html.wrapper).empty();
@ -36,7 +36,7 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({
wrapper: $wrapper,
method: 'erpnext.hr.doctype.upload_attendance.upload_attendance.upload'
});
},
}
setup_import_progress() {
var $log_wrapper = $(this.frm.fields_dict.import_log.wrapper).empty();
@ -64,6 +64,6 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({
}
});
}
})
}
cur_frm.cscript = new erpnext.hr.AttendanceControlPanel({frm: cur_frm});

View File

@ -45,8 +45,8 @@ frappe.ui.form.on('Maintenance Schedule', {
})
// TODO commonify this code
erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
refresh: function() {
erpnext.maintenance.MaintenanceSchedule = class MaintenanceSchedule extends frappe.ui.form.Controller {
refresh() {
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
var me = this;
@ -76,21 +76,21 @@ erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
});
}, __('Create'));
}
},
}
start_date: function(doc, cdt, cdn) {
start_date(doc, cdt, cdn) {
this.set_no_of_visits(doc, cdt, cdn);
},
}
end_date: function(doc, cdt, cdn) {
end_date(doc, cdt, cdn) {
this.set_no_of_visits(doc, cdt, cdn);
},
}
periodicity: function(doc, cdt, cdn) {
periodicity(doc, cdt, cdn) {
this.set_no_of_visits(doc, cdt, cdn);
},
}
set_no_of_visits: function(doc, cdt, cdn) {
set_no_of_visits(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
if (item.start_date && item.end_date && item.periodicity) {
@ -112,8 +112,8 @@ erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
var no_of_visits = cint(date_diff / days_in_period[item.periodicity]);
frappe.model.set_value(item.doctype, item.name, "no_of_visits", no_of_visits);
}
},
});
}
};
$.extend(cur_frm.cscript, new erpnext.maintenance.MaintenanceSchedule({frm: cur_frm}));

View File

@ -41,8 +41,8 @@ frappe.ui.form.on('Maintenance Visit', {
})
// TODO commonify this code
erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
refresh: function() {
erpnext.maintenance.MaintenanceVisit = class MaintenanceVisit extends frappe.ui.form.Controller {
refresh() {
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
var me = this;
@ -96,7 +96,7 @@ erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
})
}, __("Get Items From"));
}
},
});
}
};
$.extend(cur_frm.cscript, new erpnext.maintenance.MaintenanceVisit({frm: cur_frm}));
$.extend(cur_frm.cscript, new erpnext.maintenance.MaintenanceVisit({frm: cur_frm}));

View File

@ -357,16 +357,16 @@ frappe.ui.form.on("BOM", {
}
});
erpnext.bom.BomController = erpnext.TransactionController.extend({
conversion_rate: function(doc) {
erpnext.bom.BomController = class BomController extends erpnext.TransactionController {
conversion_rate(doc) {
if(this.frm.doc.currency === this.get_company_currency()) {
this.frm.set_value("conversion_rate", 1.0);
} else {
erpnext.bom.update_cost(doc);
}
},
}
item_code: function(doc, cdt, cdn){
item_code(doc, cdt, cdn){
var scrap_items = false;
var child = locals[cdt][cdn];
if (child.doctype == 'BOM Scrap Item') {
@ -378,19 +378,19 @@ erpnext.bom.BomController = erpnext.TransactionController.extend({
}
get_bom_material_detail(doc, cdt, cdn, scrap_items);
},
}
buying_price_list: function(doc) {
buying_price_list(doc) {
this.apply_price_list();
},
}
plc_conversion_rate: function(doc) {
plc_conversion_rate(doc) {
if (!this.in_apply_price_list) {
this.apply_price_list(null, true);
}
},
}
conversion_factor: function(doc, cdt, cdn) {
conversion_factor(doc, cdt, cdn) {
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"]);
@ -399,8 +399,8 @@ erpnext.bom.BomController = erpnext.TransactionController.extend({
this.toggle_conversion_factor(item);
this.frm.events.update_cost(this.frm);
}
},
});
}
};
$.extend(cur_frm.cscript, new erpnext.bom.BomController({frm: cur_frm}));

View File

@ -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 @@ erpnext.AccountTreeGrid = frappe.views.TreeGridReport.extend({
}
},
});
},
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 @@ erpnext.AccountTreeGrid = frappe.views.TreeGridReport.extend({
{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 @@ erpnext.AccountTreeGrid = frappe.views.TreeGridReport.extend({
});
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 @@ erpnext.AccountTreeGrid = frappe.views.TreeGridReport.extend({
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 @@ erpnext.AccountTreeGrid = frappe.views.TreeGridReport.extend({
});
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 @@ erpnext.AccountTreeGrid = frappe.views.TreeGridReport.extend({
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 @@ erpnext.AccountTreeGrid = frappe.views.TreeGridReport.extend({
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 @@ erpnext.AccountTreeGrid = frappe.views.TreeGridReport.extend({
}
}
});
},
}
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 @@ erpnext.AccountTreeGrid = frappe.views.TreeGridReport.extend({
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 @@ erpnext.AccountTreeGrid = frappe.views.TreeGridReport.extend({
};
frappe.set_route("query-report", "General Ledger");
}
});
};

View File

@ -9,14 +9,14 @@ cur_frm.cscript.tax_table = "Purchase Taxes and Charges";
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 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
});
}
/* 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 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
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 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
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 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
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 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
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 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
}
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 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
}
});
}
},
}
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 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
}
});
}
},
}
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 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
}
})
}
},
}
manufacturer: function(doc, cdt, cdn) {
manufacturer(doc, cdt, cdn) {
const row = locals[cdt][cdn];
if(row.manufacturer) {
@ -310,9 +310,9 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
}
});
}
},
}
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 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
}
}
});
};
cur_frm.add_fetch('project', 'cost_center', 'cost_center');
@ -496,4 +496,4 @@ erpnext.buying.get_items_from_product_bundle = function(frm) {
});
dialog.show();
}
}

View File

@ -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 @@ erpnext.stock.StockController = frappe.ui.form.Controller.extend({
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 @@ erpnext.stock.StockController = frappe.ui.form.Controller.extend({
}, __("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 @@ erpnext.stock.StockController = frappe.ui.form.Controller.extend({
}, __("View"));
}
}
});
};

View File

@ -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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
}
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
}
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
}
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
}
});
}
},
}
determine_exclusive_rate: function() {
determine_exclusive_rate() {
var me = this;
var has_inclusive_tax = false;
@ -210,9 +210,9 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
});
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
}
});
});
},
}
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
} 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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
}
}
}
},
}
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
// 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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
}
});
}
},
}
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
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 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
}
this.calculate_outstanding_amount(false);
}
});
};

View File

@ -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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
});
}
},
onload: function() {
}
onload() {
var me = this;
if(this.frm.doc.__islocal) {
@ -249,15 +249,15 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
]);
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
}
});
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
}
})
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
.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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
});
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
});
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
});
}
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
});
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
}
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
});
}
}
},
}
company: function() {
company() {
var me = this;
var set_pricing = function() {
if(me.frm.doc.company && me.frm.fields_dict.currency) {
@ -901,16 +901,16 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
);
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
} 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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
// 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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
});
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
callback(flt(r.message));
}
});
},
}
price_list_currency: function() {
price_list_currency() {
var me=this;
this.set_dynamic_labels();
@ -1123,9 +1123,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
} 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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
});
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
})
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
});
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
// 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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
} 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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
}
});
},
}
_get_args: function(item) {
_get_args(item) {
var me = this;
return {
"items": this._get_item_list(item),
@ -1474,9 +1474,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
"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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
});
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
});
}
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
} 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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}).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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
});
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
});
}
},
}
tax_category: function() {
tax_category() {
var me = this;
if(me.frm.updating_party_details) return;
@ -1744,9 +1744,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
() => 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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
});
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
})
}
},
}
make_payment_entry: function() {
make_payment_entry() {
return frappe.call({
method: cur_frm.cscript.get_method_for_payment(),
args: {
@ -1894,9 +1894,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
// 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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
})
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
})
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
})
}
},
}
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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
() => me.apply_pricing_rule()
]);
}
});
};
erpnext.show_serial_batch_selector = function (frm, d, callback, on_close, show_dialog) {
let warehouse, receiving_stock, existing_stock;

View File

@ -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 @@ erpnext.payments = erpnext.stock.StockController.extend({
}
});
})
},
}
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 @@ erpnext.payments = erpnext.stock.StockController.extend({
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 @@ erpnext.payments = erpnext.stock.StockController.extend({
}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 @@ erpnext.payments = erpnext.stock.StockController.extend({
}
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 @@ erpnext.payments = erpnext.stock.StockController.extend({
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 @@ erpnext.payments = erpnext.stock.StockController.extend({
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 @@ erpnext.payments = erpnext.stock.StockController.extend({
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 @@ erpnext.payments = erpnext.stock.StockController.extend({
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 @@ erpnext.payments = erpnext.stock.StockController.extend({
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 @@ erpnext.payments = erpnext.stock.StockController.extend({
}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 @@ erpnext.payments = erpnext.stock.StockController.extend({
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 @@ erpnext.payments = erpnext.stock.StockController.extend({
$(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();
}
})
}

View File

@ -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 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
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 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
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 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
{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 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
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 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
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 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
}
}
});
},
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 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
};
frappe.set_route("query-report", "Stock Ledger");
}
});
};

View File

@ -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 @@ erpnext.StockGridReport = frappe.views.TreeGridReport.extend({
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 @@ erpnext.StockGridReport = frappe.views.TreeGridReport.extend({
// 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 @@ erpnext.StockGridReport = frappe.views.TreeGridReport.extend({
});
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 @@ erpnext.StockGridReport = frappe.views.TreeGridReport.extend({
}
return serialized_buying_rates;
},
});
}
};

View File

@ -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 @@ frappe.ui.form.ControlData = frappe.ui.form.ControlData.extend( {
});
}
}
});
};

View File

@ -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 @@ frappe.ui.form.CustomerQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
}];
return variant_fields;
},
})
}
}

View File

@ -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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
me.insert(variant_values);
}
});
},
}
insert: function(variant_values) {
insert(variant_values) {
let me = this;
return new Promise(resolve => {
frappe.call({
@ -94,9 +94,9 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
} 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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
}];
return variant_fields;
},
}
get_manufacturing_fields: function() {
get_manufacturing_fields() {
this.manufacturer_fields = [{
fieldtype: 'Link',
options: 'Manufacturer',
@ -148,9 +148,9 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
});
}
});
},
}
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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
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 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
})
}
return variant_doc;
},
}
validate_mandatory_attributes: function() {
validate_mandatory_attributes() {
var me = this;
var attribute = {};
var mandatory = [];
@ -404,4 +404,4 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
}
return attribute;
}
});
};

View File

@ -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 @@ erpnext.ItemSelector = Class.extend({
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 @@ erpnext.ItemSelector = Class.extend({
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 @@ erpnext.ItemSelector = Class.extend({
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 @@ erpnext.ItemSelector = Class.extend({
]);
}
},
}
render_items: function() {
render_items() {
let args = {
query: this.item_query,
filters: {}
@ -107,4 +107,4 @@ erpnext.ItemSelector = Class.extend({
me.dialog.results.html(frappe.render_template('item_selector', {'data':r.values}));
});
}
});
};

View File

@ -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 @@ erpnext.SerialNoBatchSelector = Class.extend({
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 @@ erpnext.SerialNoBatchSelector = Class.extend({
}
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 @@ erpnext.SerialNoBatchSelector = Class.extend({
}
return true;
}
},
}
update_batch_items() {
// clones an items if muliple batches are selected.
@ -233,14 +233,14 @@ erpnext.SerialNoBatchSelector = Class.extend({
'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 @@ erpnext.SerialNoBatchSelector = Class.extend({
});
})
}
},
}
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 @@ erpnext.SerialNoBatchSelector = Class.extend({
}
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 @@ erpnext.SerialNoBatchSelector = Class.extend({
});
qty_field.set_input(total_qty);
},
}
get_batch_fields: function() {
get_batch_fields() {
var me = this;
return [
@ -425,9 +425,9 @@ erpnext.SerialNoBatchSelector = Class.extend({
},
}
];
},
}
get_serial_no_fields: function() {
get_serial_no_fields() {
var me = this;
this.serial_list = [];
@ -510,4 +510,4 @@ erpnext.SerialNoBatchSelector = Class.extend({
}
];
}
});
};

View File

@ -30,8 +30,8 @@ frappe.ui.form.on('Installation Note', {
frappe.provide("erpnext.selling");
// TODO commonify this code
erpnext.selling.InstallationNote = frappe.ui.form.Controller.extend({
refresh: function() {
erpnext.selling.InstallationNote = class InstallationNote extends frappe.ui.form.Controller {
refresh() {
var me = this;
if (this.frm.doc.docstatus===0) {
this.frm.add_custom_button(__('From Delivery Note'),
@ -54,7 +54,7 @@ erpnext.selling.InstallationNote = frappe.ui.form.Controller.extend({
}, "fa fa-download", "btn-default"
);
}
},
});
}
};
$.extend(cur_frm.cscript, new erpnext.selling.InstallationNote({frm: cur_frm}));

View File

@ -36,13 +36,13 @@ frappe.ui.form.on('Quotation', {
}
});
erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
onload: function(doc, dt, dn) {
erpnext.selling.QuotationController = class QuotationController extends erpnext.selling.SellingController {
onload(doc, dt, dn) {
var me = this;
this._super(doc, dt, dn);
super.(doc, dt, dn);
},
party_name: function() {
}
party_name() {
var me = this;
erpnext.utils.get_party_details(this.frm, null, null, function() {
me.apply_price_list();
@ -51,9 +51,9 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
if(me.frm.doc.quotation_to=="Lead" && me.frm.doc.party_name) {
me.frm.trigger("get_lead_details");
}
},
refresh: function(doc, dt, dn) {
this._super(doc, dt, dn);
}
refresh(doc, dt, dn) {
super.refresh(doc, dt, dn);
doctype = doc.quotation_to == 'Customer' ? 'Customer':'Lead';
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'party_name', doctype: doctype}
@ -121,9 +121,9 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
this.toggle_reqd_lead_customer();
},
}
set_dynamic_field_label: function(){
set_dynamic_field_label(){
if (this.frm.doc.quotation_to == "Customer")
{
this.frm.set_df_property("party_name", "label", "Customer");
@ -138,22 +138,22 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
return{ query: "erpnext.controllers.queries.lead_query" }
}
}
},
}
toggle_reqd_lead_customer: function() {
toggle_reqd_lead_customer() {
var me = this;
// to overwrite the customer_filter trigger from queries.js
this.frm.toggle_reqd("party_name", this.frm.doc.quotation_to);
this.frm.set_query('customer_address', this.address_query);
this.frm.set_query('shipping_address_name', this.address_query);
},
}
tc_name: function() {
tc_name() {
this.get_terms();
},
}
address_query: function(doc) {
address_query(doc) {
return {
query: 'frappe.contacts.doctype.address.address.address_query',
filters: {
@ -161,20 +161,20 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
link_name: doc.party_name
}
};
},
}
validate_company_and_party: function(party_field) {
validate_company_and_party(party_field) {
if(!this.frm.doc.quotation_to) {
frappe.msgprint(__("Please select a value for {0} quotation_to {1}", [this.frm.doc.doctype, this.frm.doc.name]));
return false;
} else if (this.frm.doc.quotation_to == "Lead") {
return true;
} else {
return this._super(party_field);
return super.validate_company_and_party(party_field);
}
},
}
get_lead_details: function() {
get_lead_details() {
var me = this;
if(!this.frm.doc.quotation_to === "Lead") {
return;
@ -198,7 +198,7 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
}
})
}
});
};
cur_frm.script_manager.make(erpnext.selling.QuotationController);

View File

@ -102,14 +102,14 @@ frappe.ui.form.on("Sales Order Item", {
}
});
erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend({
onload: function(doc, dt, dn) {
this._super();
},
erpnext.selling.SalesOrderController = class SalesOrderController extends erpnext.selling.SellingController {
onload(doc, dt, dn) {
super.onload();
}
refresh: function(doc, dt, dn) {
refresh(doc, dt, dn) {
var me = this;
this._super();
super.refresh();
let allow_delivery = false;
if (doc.docstatus==1) {
@ -241,14 +241,14 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
}
this.order_type(doc);
},
}
create_pick_list() {
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.create_pick_list",
frm: this.frm
})
},
}
make_work_order() {
var me = this;
@ -343,33 +343,33 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
}
}
});
},
}
order_type: function() {
order_type() {
this.toggle_delivery_date();
},
}
tc_name: function() {
tc_name() {
this.get_terms();
},
}
make_material_request: function() {
make_material_request() {
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_material_request",
frm: this.frm
})
},
}
skip_delivery_note: function() {
skip_delivery_note() {
this.toggle_delivery_date();
},
}
toggle_delivery_date: function() {
toggle_delivery_date() {
this.frm.fields_dict.items.grid.toggle_reqd("delivery_date",
(this.frm.doc.order_type == "Sales" && !this.frm.doc.skip_delivery_note));
},
}
make_raw_material_request: function() {
make_raw_material_request() {
var me = this;
this.frm.call({
doc: this.frm.doc,
@ -390,9 +390,9 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
}
}
});
},
}
make_raw_material_request_dialog: function(r) {
make_raw_material_request_dialog(r) {
var fields = [
{fieldtype:'Check', fieldname:'include_exploded_items',
label: __('Include Exploded Items')},
@ -447,9 +447,9 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
primary_action_label: __('Create')
});
d.show();
},
}
make_delivery_note_based_on_delivery_date: function() {
make_delivery_note_based_on_delivery_date() {
var me = this;
var delivery_dates = [];
@ -509,51 +509,51 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
} else {
this.make_delivery_note();
}
},
}
make_delivery_note: function() {
make_delivery_note() {
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_delivery_note",
frm: this.frm
})
},
}
make_sales_invoice: function() {
make_sales_invoice() {
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice",
frm: this.frm
})
},
}
make_maintenance_schedule: function() {
make_maintenance_schedule() {
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_schedule",
frm: this.frm
})
},
}
make_project: function() {
make_project() {
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_project",
frm: this.frm
})
},
}
make_inter_company_order: function() {
make_inter_company_order() {
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_inter_company_purchase_order",
frm: this.frm
});
},
}
make_maintenance_visit: function() {
make_maintenance_visit() {
frappe.model.open_mapped_doc({
method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_visit",
frm: this.frm
})
},
}
make_purchase_order: function(){
make_purchase_order(){
let pending_items = this.frm.doc.items.some((item) =>{
let pending_qty = flt(item.stock_qty) - flt(item.ordered_qty);
return pending_qty > 0;
@ -690,9 +690,9 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
dialog.get_field("items_for_po").refresh();
dialog.wrapper.find('.grid-heading-row .grid-row-check').click();
dialog.show();
},
}
hold_sales_order: function(){
hold_sales_order(){
var me = this;
var d = new frappe.ui.Dialog({
title: __('Reason for Hold'),
@ -724,11 +724,11 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
}
});
d.show();
},
close_sales_order: function(){
}
close_sales_order(){
this.frm.cscript.update_status("Close", "Closed")
},
update_status: function(label, status){
}
update_status(label, status){
var doc = this.frm.doc;
var me = this;
frappe.ui.form.is_saving = true;
@ -743,5 +743,5 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend(
}
});
}
});
};
$.extend(cur_frm.cscript, new erpnext.selling.SalesOrderController({frm: cur_frm}));

View File

@ -9,15 +9,15 @@ cur_frm.cscript.tax_table = "Sales Taxes and Charges";
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}
};
});
},
}
setup_queries: function() {
setup_queries() {
var me = this;
$.each([["customer", "customer"],
@ -81,10 +81,10 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
});
}
},
}
refresh: function() {
this._super();
refresh() {
super.refresh();
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
@ -95,45 +95,45 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
});
}
})
},
}
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
});
}
})
},
}
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}
}
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
} 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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}
}
});
},
}
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 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
})
}
}
});
};
frappe.ui.form.on(cur_frm.doctype,"project", function(frm) {
if(in_list(["Delivery Note", "Sales Invoice"], frm.doc.doctype)) {

View File

@ -1,11 +1,11 @@
frappe.provide('erpnext.stock');
erpnext.stock.ItemDashboard = Class.extend({
init: function(opts) {
erpnext.stock.ItemDashboard = class ItemDashboard {
constructor(opts) {
$.extend(this, opts);
this.make();
},
make: function() {
}
make() {
var me = this;
this.start = 0;
if(!this.sort_by) {
@ -73,8 +73,8 @@ erpnext.stock.ItemDashboard = Class.extend({
me.refresh();
});
},
refresh: function() {
}
refresh() {
if(this.before_refresh) {
this.before_refresh();
}
@ -98,8 +98,8 @@ erpnext.stock.ItemDashboard = Class.extend({
me.render(r.message);
}
});
},
render: function(data) {
}
render(data) {
if (this.start===0) {
this.max_count = 0;
this.result.empty();
@ -135,9 +135,9 @@ erpnext.stock.ItemDashboard = Class.extend({
$(`<div class='text-muted' style='margin: 20px 5px;'>
${message} </div>`).appendTo(this.result);
}
},
}
get_item_dashboard_data: function(data, max_count, show_item) {
get_item_dashboard_data(data, max_count, show_item) {
if(!max_count) max_count = 0;
if(!data) data = [];
@ -164,9 +164,9 @@ erpnext.stock.ItemDashboard = Class.extend({
can_write:can_write,
show_item: show_item || false
};
},
}
get_capacity_dashboard_data: function(data) {
get_capacity_dashboard_data(data) {
if (!data) data = [];
data.forEach(function(d) {
@ -183,7 +183,7 @@ erpnext.stock.ItemDashboard = Class.extend({
can_write: can_write,
};
}
});
};
erpnext.stock.move_item = function(item, source, target, actual_qty, rate, callback) {
var dialog = new frappe.ui.Dialog({

View File

@ -123,17 +123,17 @@ frappe.ui.form.on("Delivery Note Item", {
}
});
erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend({
setup: function(doc) {
erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends erpnext.selling.SellingController {
setup(doc) {
this.setup_posting_date_time_check();
this._super(doc);
super.setup(doc);
this.frm.make_methods = {
'Delivery Trip': this.make_delivery_trip,
};
},
refresh: function(doc, dt, dn) {
}
refresh(doc, dt, dn) {
var me = this;
this._super();
super.refresh();
if ((!doc.is_return) && (doc.status!="Closed" || this.frm.is_new())) {
if (this.frm.doc.docstatus===0) {
this.frm.add_custom_button(__('Sales Order'),
@ -231,64 +231,64 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
erpnext.utils.make_subscription(doc.doctype, doc.name)
}, __('Create'))
}
},
}
make_shipment: function() {
make_shipment() {
frappe.model.open_mapped_doc({
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_shipment",
frm: this.frm
})
},
}
make_sales_invoice: function() {
make_sales_invoice() {
frappe.model.open_mapped_doc({
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice",
frm: this.frm
})
},
}
make_installation_note: function() {
make_installation_note() {
frappe.model.open_mapped_doc({
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_installation_note",
frm: this.frm
});
},
}
make_sales_return: function() {
make_sales_return() {
frappe.model.open_mapped_doc({
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_sales_return",
frm: this.frm
})
},
}
make_delivery_trip: function() {
make_delivery_trip() {
frappe.model.open_mapped_doc({
method: "erpnext.stock.doctype.delivery_note.delivery_note.make_delivery_trip",
frm: cur_frm
})
},
}
tc_name: function() {
tc_name() {
this.get_terms();
},
}
items_on_form_rendered: function(doc, grid_row) {
items_on_form_rendered(doc, grid_row) {
erpnext.setup_serial_no();
},
}
packed_items_on_form_rendered: function(doc, grid_row) {
packed_items_on_form_rendered(doc, grid_row) {
erpnext.setup_serial_no();
},
}
close_delivery_note: function(doc){
close_delivery_note(doc){
this.update_status("Closed")
},
}
reopen_delivery_note : function() {
reopen_delivery_note() {
this.update_status("Submitted")
},
}
update_status: function(status) {
update_status(status) {
var me = this;
frappe.ui.form.is_saving = true;
frappe.call({
@ -302,8 +302,8 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
frappe.ui.form.is_saving = false;
}
})
},
});
}
};
$.extend(cur_frm.cscript, new erpnext.stock.DeliveryNoteController({frm: cur_frm}));

View File

@ -5,8 +5,8 @@
frappe.provide("erpnext.stock");
erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({
setup: function() {
erpnext.stock.LandedCostVoucher = class LandedCostVoucher extends erpnext.stock.StockController {
setup() {
var me = this;
this.frm.fields_dict.purchase_receipts.grid.get_field('receipt_document').get_query =
function (doc, cdt, cdn) {
@ -30,9 +30,9 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({
this.frm.add_fetch("receipt_document", "supplier", "supplier");
this.frm.add_fetch("receipt_document", "posting_date", "posting_date");
this.frm.add_fetch("receipt_document", "base_grand_total", "grand_total");
},
}
refresh: function() {
refresh() {
var help_content =
`<br><br>
<table class="table table-bordered" style="background-color: #f9f9f9;">
@ -67,9 +67,9 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({
let company_currency = frappe.get_doc(":Company", this.frm.doc.company).default_currency;
this.frm.set_currency_labels(["total_taxes_and_charges"], company_currency);
}
},
}
get_items_from_purchase_receipts: function() {
get_items_from_purchase_receipts() {
var me = this;
if(!this.frm.doc.purchase_receipts.length) {
frappe.msgprint(__("Please enter Purchase Receipt first"));
@ -82,22 +82,22 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({
}
});
}
},
}
amount: function(frm) {
amount(frm) {
this.set_total_taxes_and_charges();
this.set_applicable_charges_for_item();
},
}
set_total_taxes_and_charges: function() {
set_total_taxes_and_charges() {
var total_taxes_and_charges = 0.0;
$.each(this.frm.doc.taxes || [], function(i, d) {
total_taxes_and_charges += flt(d.base_amount);
});
this.frm.set_value("total_taxes_and_charges", total_taxes_and_charges);
},
}
set_applicable_charges_for_item: function() {
set_applicable_charges_for_item() {
var me = this;
if(this.frm.doc.taxes.length) {
@ -123,15 +123,15 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({
refresh_field("items");
}
}
},
distribute_charges_based_on: function (frm) {
}
distribute_charges_based_on (frm) {
this.set_applicable_charges_for_item();
},
}
items_remove: () => {
items_remove() {
this.trigger('set_applicable_charges_for_item');
}
});
};
cur_frm.script_manager.make(erpnext.stock.LandedCostVoucher);

View File

@ -403,28 +403,28 @@ frappe.ui.form.on("Material Request Item", {
}
});
erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.extend({
tc_name: function() {
erpnext.buying.MaterialRequestController = class MaterialRequestController extends erpnext.buying.BuyingController {
tc_name() {
this.get_terms();
},
}
item_code: function() {
item_code() {
// to override item code trigger from transaction.js
},
}
validate_company_and_party: function() {
validate_company_and_party() {
return true;
},
}
calculate_taxes_and_totals: function() {
calculate_taxes_and_totals() {
return;
},
}
validate: function() {
validate() {
set_schedule_date(this.frm);
},
}
onload: function(doc, cdt, cdn) {
onload(doc, cdt, cdn) {
this.frm.set_query("item_code", "items", function() {
if (doc.material_request_type == "Customer Provided") {
return{
@ -438,9 +438,9 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
}
}
});
},
}
items_add: function(doc, cdt, cdn) {
items_add(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
if(doc.schedule_date) {
row.schedule_date = doc.schedule_date;
@ -448,16 +448,16 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
} else {
this.frm.script_manager.copy_from_first_row("items", row, ["schedule_date"]);
}
},
}
items_on_form_rendered: function() {
set_schedule_date(this.frm);
},
schedule_date: function() {
items_on_form_rendered() {
set_schedule_date(this.frm);
}
});
schedule_date() {
set_schedule_date(this.frm);
}
};
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new erpnext.buying.MaterialRequestController({frm: cur_frm}));

View File

@ -86,15 +86,15 @@ frappe.ui.form.on("Purchase Receipt", {
}
});
erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend({
setup: function(doc) {
erpnext.stock.PurchaseReceiptController = class PurchaseReceiptController extends erpnext.buying.BuyingController {
setup(doc) {
this.setup_posting_date_time_check();
this._super(doc);
},
super.setup(doc);
}
refresh: function() {
refresh() {
var me = this;
this._super();
super.refresh();
if(this.frm.doc.docstatus > 0) {
this.show_stock_ledger();
//removed for temporary
@ -173,31 +173,31 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend
}
this.frm.toggle_reqd("supplier_warehouse", this.frm.doc.is_subcontracted==="Yes");
},
}
make_purchase_invoice: function() {
make_purchase_invoice() {
frappe.model.open_mapped_doc({
method: "erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_purchase_invoice",
frm: cur_frm
})
},
}
make_purchase_return: function() {
make_purchase_return() {
frappe.model.open_mapped_doc({
method: "erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_purchase_return",
frm: cur_frm
})
},
}
close_purchase_receipt: function() {
close_purchase_receipt() {
cur_frm.cscript.update_status("Closed");
},
}
reopen_purchase_receipt: function() {
reopen_purchase_receipt() {
cur_frm.cscript.update_status("Submitted");
},
}
make_retention_stock_entry: function() {
make_retention_stock_entry() {
frappe.call({
method: "erpnext.stock.doctype.stock_entry.stock_entry.move_sample_to_retention_warehouse",
args:{
@ -214,13 +214,13 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend
}
}
});
},
}
apply_putaway_rule: function() {
apply_putaway_rule() {
if (this.frm.doc.apply_putaway_rule) erpnext.apply_putaway_rule(this.frm);
}
});
};
// for backward compatibility: combine new and previous states
$.extend(cur_frm.cscript, new erpnext.stock.PurchaseReceiptController({frm: cur_frm}));

View File

@ -777,8 +777,8 @@ frappe.ui.form.on('Landed Cost Taxes and Charges', {
}
});
erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
setup: function() {
erpnext.stock.StockEntry = class StockEntry extends erpnext.stock.StockController {
setup() {
var me = this;
this.setup_posting_date_time_check();
@ -825,9 +825,9 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
frappe.dynamic_link = { doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier' }
this.frm.set_query("supplier_address", erpnext.queries.address_query)
},
}
onload_post_render: function() {
onload_post_render() {
var me = this;
this.set_default_account(function() {
if(me.frm.doc.__islocal && me.frm.doc.company && !me.frm.doc.amended_from) {
@ -836,9 +836,9 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
});
this.frm.get_field("items").grid.set_multiple_add("item_code", "qty");
},
}
refresh: function() {
refresh() {
var me = this;
erpnext.toggle_naming_series();
this.toggle_related_fields(this.frm.doc);
@ -850,22 +850,22 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
erpnext.hide_company();
erpnext.utils.add_item(this.frm);
this.frm.trigger('add_to_transit');
},
}
scan_barcode: function() {
scan_barcode() {
let transaction_controller= new erpnext.TransactionController({frm:this.frm});
transaction_controller.scan_barcode();
},
}
on_submit: function() {
on_submit() {
this.clean_up();
},
}
after_cancel: function() {
after_cancel() {
this.clean_up();
},
}
set_default_account: function(callback) {
set_default_account(callback) {
var me = this;
if(this.frm.doc.company && erpnext.is_perpetual_inventory_enabled(this.frm.doc.company)) {
@ -885,9 +885,9 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
}
});
}
},
}
clean_up: function() {
clean_up() {
// Clear Work Order record from locals, because it is updated via Stock Entry
if(this.frm.doc.work_order &&
in_list(["Manufacture", "Material Transfer for Manufacture", "Material Consumption for Manufacture"],
@ -895,13 +895,13 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
frappe.model.remove_from_locals("Work Order",
this.frm.doc.work_order);
}
},
}
fg_completed_qty: function() {
fg_completed_qty() {
this.get_items();
},
}
get_items: function() {
get_items() {
var me = this;
if(!this.frm.doc.fg_completed_qty || !this.frm.doc.bom_no)
frappe.throw(__("BOM and Manufacturing Quantity are required"));
@ -917,9 +917,9 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
}
});
}
},
}
work_order: function() {
work_order() {
var me = this;
this.toggle_enable_bom();
if(!me.frm.doc.work_order || me.frm.doc.job_card) {
@ -952,13 +952,13 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
}
}
});
},
}
toggle_enable_bom: function() {
toggle_enable_bom() {
this.frm.toggle_enable("bom_no", !!!this.frm.doc.work_order);
},
}
add_excise_button: function() {
add_excise_button() {
if(frappe.boot.sysdefaults.country === "India")
this.frm.add_custom_button(__("Excise Invoice"), function() {
var excise = frappe.model.make_new_doc_and_get_name('Journal Entry');
@ -966,35 +966,35 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
excise.voucher_type = 'Excise Entry';
frappe.set_route('Form', 'Journal Entry', excise.name);
}, __('Create'));
},
}
items_add: function(doc, cdt, cdn) {
items_add(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
this.frm.script_manager.copy_from_first_row("items", row, ["expense_account", "cost_center"]);
if(!row.s_warehouse) row.s_warehouse = this.frm.doc.from_warehouse;
if(!row.t_warehouse) row.t_warehouse = this.frm.doc.to_warehouse;
},
}
from_warehouse: function(doc) {
from_warehouse(doc) {
this.frm.trigger('set_tansit_warehouse');
this.set_warehouse_in_children(doc.items, "s_warehouse", doc.from_warehouse);
},
}
to_warehouse: function(doc) {
to_warehouse(doc) {
this.set_warehouse_in_children(doc.items, "t_warehouse", doc.to_warehouse);
},
}
set_warehouse_in_children: function(child_table, warehouse_field, warehouse) {
set_warehouse_in_children(child_table, warehouse_field, warehouse) {
let transaction_controller = new erpnext.TransactionController();
transaction_controller.autofill_warehouse(child_table, warehouse_field, warehouse);
},
}
items_on_form_rendered: function(doc, grid_row) {
items_on_form_rendered(doc, grid_row) {
erpnext.setup_serial_no();
},
}
toggle_related_fields: function(doc) {
toggle_related_fields(doc) {
this.frm.toggle_enable("from_warehouse", doc.purpose!='Material Receipt');
this.frm.toggle_enable("to_warehouse", doc.purpose!='Material Issue');
@ -1021,12 +1021,12 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
doc.purpose!='Material Issue');
this.frm.fields_dict["items"].grid.set_column_disp("additional_cost", doc.purpose!='Material Issue');
},
}
supplier: function(doc) {
supplier(doc) {
erpnext.utils.get_party_details(this.frm, null, null, null);
}
});
};
erpnext.stock.select_batch_and_serial_no = (frm, item) => {
let get_warehouse_type_and_name = (item) => {

View File

@ -220,8 +220,8 @@ frappe.ui.form.on("Stock Reconciliation Item", {
});
erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({
setup: function() {
erpnext.stock.StockReconciliation = class StockReconciliation extends erpnext.stock.StockController {
setup() {
var me = this;
this.setup_posting_date_time_check();
@ -249,17 +249,17 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({
}
}
}
},
}
refresh: function() {
refresh() {
if(this.frm.doc.docstatus > 0) {
this.show_stock_ledger();
if (erpnext.is_perpetual_inventory_enabled(this.frm.doc.company)) {
this.show_general_ledger();
}
}
},
}
});
};
cur_frm.cscript = new erpnext.stock.StockReconciliation({frm: cur_frm});

View File

@ -36,8 +36,8 @@ frappe.ui.form.on("Warranty Claim", {
}
});
erpnext.support.WarrantyClaim = frappe.ui.form.Controller.extend({
refresh: function() {
erpnext.support.WarrantyClaim = class WarrantyClaim extends frappe.ui.form.Controller {
refresh() {
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
if(!cur_frm.doc.__islocal &&
@ -45,15 +45,15 @@ erpnext.support.WarrantyClaim = frappe.ui.form.Controller.extend({
cur_frm.add_custom_button(__('Maintenance Visit'),
this.make_maintenance_visit);
}
},
}
make_maintenance_visit: function() {
make_maintenance_visit() {
frappe.model.open_mapped_doc({
method: "erpnext.support.doctype.warranty_claim.warranty_claim.make_maintenance_visit",
frm: cur_frm
})
}
});
};
$.extend(cur_frm.cscript, new erpnext.support.WarrantyClaim({frm: cur_frm}));

View File

@ -11,23 +11,23 @@ $(document).ready(function() {
doc.buying_price_list = "{{ doc.buying_price_list }}"
});
rfq = Class.extend({
init: function(){
rfq = class rfq {
constructor(){
this.onfocus_select_all();
this.change_qty();
this.change_rate();
this.terms();
this.submit_rfq();
this.navigate_quotations();
},
}
onfocus_select_all: function(){
onfocus_select_all(){
$("input").click(function(){
$(this).select();
})
},
}
change_qty: function(){
change_qty(){
var me = this;
$('.rfq-items').on("change", ".rfq-qty", function(){
me.idx = parseFloat($(this).attr('data-idx'));
@ -36,9 +36,9 @@ rfq = Class.extend({
me.update_qty_rate();
$(this).val(format_number(me.qty, doc.number_format, 2));
})
},
}
change_rate: function(){
change_rate(){
var me = this;
$(".rfq-items").on("change", ".rfq-rate", function(){
me.idx = parseFloat($(this).attr('data-idx'));
@ -47,15 +47,15 @@ rfq = Class.extend({
me.update_qty_rate();
$(this).val(format_number(me.rate, doc.number_format, 2));
})
},
}
terms: function(){
terms(){
$(".terms").on("change", ".terms-feedback", function(){
doc.terms = $(this).val();
})
},
}
update_qty_rate: function(){
update_qty_rate(){
var me = this;
doc.grand_total = 0.0;
$.each(doc.items, function(idx, data){
@ -69,9 +69,9 @@ rfq = Class.extend({
doc.grand_total += flt(data.amount);
$('.tax-grand-total').text(format_number(doc.grand_total, doc.number_format, 2));
})
},
}
submit_rfq: function(){
submit_rfq(){
$('.btn-sm').click(function(){
frappe.freeze();
frappe.call({
@ -90,12 +90,12 @@ rfq = Class.extend({
}
})
})
},
}
navigate_quotations: function() {
navigate_quotations() {
$('.quotations').click(function(){
name = $(this).attr('idx')
window.location.href = "/quotations/" + encodeURIComponent(name);
})
}
})
}