refactor: Replace Class.extend with native class
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user