minor fix: child table length
This commit is contained in:
parent
0a3e5653ba
commit
963393409e
@ -109,7 +109,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
on_submit: function() {
|
on_submit: function() {
|
||||||
$.each(this.frm.doc["items"], function(i, row) {
|
$.each(this.frm.doc["items"] || [], function(i, row) {
|
||||||
if(row.purchase_receipt) frappe.model.clear_doc("Purchase Receipt", row.purchase_receipt)
|
if(row.purchase_receipt) frappe.model.clear_doc("Purchase Receipt", row.purchase_receipt)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -154,7 +154,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
|||||||
project_name: function(doc, cdt, cdn) {
|
project_name: function(doc, cdt, cdn) {
|
||||||
var item = frappe.get_doc(cdt, cdn);
|
var item = frappe.get_doc(cdt, cdn);
|
||||||
if(item.project_name) {
|
if(item.project_name) {
|
||||||
$.each(this.frm.doc["items"],
|
$.each(this.frm.doc["items"] || [],
|
||||||
function(i, other_item) {
|
function(i, other_item) {
|
||||||
if(!other_item.project_name) {
|
if(!other_item.project_name) {
|
||||||
other_item.project_name = item.project_name;
|
other_item.project_name = item.project_name;
|
||||||
@ -180,7 +180,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
|||||||
calculate_item_values: function() {
|
calculate_item_values: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
|
|
||||||
$.each(this.frm.doc["items"], function(i, item) {
|
$.each(this.frm.doc["items"] || [], function(i, item) {
|
||||||
frappe.model.round_floats_in(item);
|
frappe.model.round_floats_in(item);
|
||||||
item.amount = flt(item.rate * item.qty, precision("amount", item));
|
item.amount = flt(item.rate * item.qty, precision("amount", item));
|
||||||
item.item_tax_amount = 0.0;
|
item.item_tax_amount = 0.0;
|
||||||
@ -196,7 +196,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
|||||||
var me = this;
|
var me = this;
|
||||||
|
|
||||||
this.frm.doc.net_total = this.frm.doc.net_total_import = 0.0;
|
this.frm.doc.net_total = this.frm.doc.net_total_import = 0.0;
|
||||||
$.each(this.frm.doc["items"], function(i, item) {
|
$.each(this.frm.doc["items"] || [], function(i, item) {
|
||||||
me.frm.doc.net_total += item.base_amount;
|
me.frm.doc.net_total += item.base_amount;
|
||||||
me.frm.doc.net_total_import += item.amount;
|
me.frm.doc.net_total_import += item.amount;
|
||||||
});
|
});
|
||||||
@ -205,7 +205,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
calculate_totals: function() {
|
calculate_totals: function() {
|
||||||
var tax_count = this.frm.doc["taxes"].length;
|
var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length : 0;
|
||||||
this.frm.doc.grand_total = flt(tax_count ?
|
this.frm.doc.grand_total = flt(tax_count ?
|
||||||
this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.net_total);
|
this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.net_total);
|
||||||
this.frm.doc.grand_total_import = flt(tax_count ?
|
this.frm.doc.grand_total_import = flt(tax_count ?
|
||||||
@ -255,7 +255,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
|||||||
|
|
||||||
if(this.frm.doc["items"].length) {
|
if(this.frm.doc["items"].length) {
|
||||||
if(!frappe.meta.get_docfield(this.frm.doc["items"][0].doctype, "item_tax_amount", this.frm.doctype)) {
|
if(!frappe.meta.get_docfield(this.frm.doc["items"][0].doctype, "item_tax_amount", this.frm.doctype)) {
|
||||||
$.each(this.frm.doc["items"], function(i, item) {
|
$.each(this.frm.doc["items"] || [], function(i, item) {
|
||||||
delete item["item_tax_amount"];
|
delete item["item_tax_amount"];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -263,7 +263,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
|||||||
|
|
||||||
if(this.frm.doc["taxes"].length) {
|
if(this.frm.doc["taxes"].length) {
|
||||||
if(!frappe.meta.get_docfield(this.frm.doc["taxes"][0].doctype, "tax_amount_after_discount_amount", this.frm.doctype)) {
|
if(!frappe.meta.get_docfield(this.frm.doc["taxes"][0].doctype, "tax_amount_after_discount_amount", this.frm.doctype)) {
|
||||||
$.each(this.frm.doc["taxes"], function(i, tax) {
|
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
|
||||||
delete tax["tax_amount_after_discount_amount"];
|
delete tax["tax_amount_after_discount_amount"];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -363,7 +363,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
|||||||
if (item) {
|
if (item) {
|
||||||
append_item(item);
|
append_item(item);
|
||||||
} else {
|
} else {
|
||||||
$.each(this.frm.doc["items"], function(i, d) {
|
$.each(this.frm.doc["items"] || [], function(i, d) {
|
||||||
append_item(d);
|
append_item(d);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -478,7 +478,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
|||||||
var tax_accounts = [];
|
var tax_accounts = [];
|
||||||
var company_currency = this.get_company_currency();
|
var company_currency = this.get_company_currency();
|
||||||
|
|
||||||
$.each(this.frm.doc["taxes"], function(i, tax) {
|
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
|
||||||
var tax_amount_precision = precision("tax_amount", tax);
|
var tax_amount_precision = precision("tax_amount", tax);
|
||||||
var tax_rate_precision = precision("rate", tax);
|
var tax_rate_precision = precision("rate", tax);
|
||||||
$.each(JSON.parse(tax.item_wise_tax_detail || '{}'),
|
$.each(JSON.parse(tax.item_wise_tax_detail || '{}'),
|
||||||
@ -507,7 +507,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
|||||||
|
|
||||||
var distinct_item_names = [];
|
var distinct_item_names = [];
|
||||||
var distinct_items = [];
|
var distinct_items = [];
|
||||||
$.each(this.frm.doc["items"], function(i, item) {
|
$.each(this.frm.doc["items"] || [], function(i, item) {
|
||||||
if(distinct_item_names.indexOf(item.item_code || item.item_name)===-1) {
|
if(distinct_item_names.indexOf(item.item_code || item.item_name)===-1) {
|
||||||
distinct_item_names.push(item.item_code || item.item_name);
|
distinct_item_names.push(item.item_code || item.item_name);
|
||||||
distinct_items.push(item);
|
distinct_items.push(item);
|
||||||
@ -592,7 +592,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
|||||||
initialize_taxes: function() {
|
initialize_taxes: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
|
|
||||||
$.each(this.frm.doc["taxes"], function(i, tax) {
|
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
|
||||||
tax.item_wise_tax_detail = {};
|
tax.item_wise_tax_detail = {};
|
||||||
tax_fields = ["total", "tax_amount_after_discount_amount",
|
tax_fields = ["total", "tax_amount_after_discount_amount",
|
||||||
"tax_amount_for_current_item", "grand_total_for_current_item",
|
"tax_amount_for_current_item", "grand_total_for_current_item",
|
||||||
@ -614,16 +614,16 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
|||||||
var actual_tax_dict = {};
|
var actual_tax_dict = {};
|
||||||
|
|
||||||
// maintain actual tax rate based on idx
|
// maintain actual tax rate based on idx
|
||||||
$.each(this.frm.doc["taxes"], function(i, tax) {
|
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
|
||||||
if (tax.charge_type == "Actual") {
|
if (tax.charge_type == "Actual") {
|
||||||
actual_tax_dict[tax.idx] = flt(tax.rate, precision("tax_amount", tax));
|
actual_tax_dict[tax.idx] = flt(tax.rate, precision("tax_amount", tax));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$.each(this.frm.doc["items"], function(n, item) {
|
$.each(this.frm.doc["items"] || [], function(n, item) {
|
||||||
var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
|
var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
|
||||||
|
|
||||||
$.each(me.frm.doc["taxes"], function(i, tax) {
|
$.each(me.frm.doc["taxes"] || [], function(i, tax) {
|
||||||
// tax_amount represents the amount of tax for the current step
|
// tax_amount represents the amount of tax for the current step
|
||||||
var current_tax_amount = me.get_current_tax_amount(item, tax, item_tax_map);
|
var current_tax_amount = me.get_current_tax_amount(item, tax, item_tax_map);
|
||||||
|
|
||||||
@ -726,7 +726,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_cleanup: function() {
|
_cleanup: function() {
|
||||||
$.each(this.frm.doc["taxes"], function(i, tax) {
|
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
|
||||||
$.each(["tax_amount_for_current_item", "grand_total_for_current_item",
|
$.each(["tax_amount_for_current_item", "grand_total_for_current_item",
|
||||||
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"],
|
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"],
|
||||||
function(i, fieldname) { delete tax[fieldname]; });
|
function(i, fieldname) { delete tax[fieldname]; });
|
||||||
|
|||||||
@ -248,7 +248,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
|||||||
var me = this;
|
var me = this;
|
||||||
|
|
||||||
if (!this.discount_amount_applied) {
|
if (!this.discount_amount_applied) {
|
||||||
$.each(this.frm.doc["items"], function(i, item) {
|
$.each(this.frm.doc["items"] || [], function(i, item) {
|
||||||
frappe.model.round_floats_in(item);
|
frappe.model.round_floats_in(item);
|
||||||
item.amount = flt(item.rate * item.qty, precision("amount", item));
|
item.amount = flt(item.rate * item.qty, precision("amount", item));
|
||||||
|
|
||||||
@ -261,11 +261,11 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
|||||||
|
|
||||||
determine_exclusive_rate: function() {
|
determine_exclusive_rate: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
$.each(me.frm.doc["items"], function(n, item) {
|
$.each(me.frm.doc["items"] || [], function(n, item) {
|
||||||
var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
|
var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
|
||||||
var cumulated_tax_fraction = 0.0;
|
var cumulated_tax_fraction = 0.0;
|
||||||
|
|
||||||
$.each(me.frm.doc["taxes"], function(i, tax) {
|
$.each(me.frm.doc["taxes"] || [], function(i, tax) {
|
||||||
tax.tax_fraction_for_current_item = me.get_current_tax_fraction(tax, item_tax_map);
|
tax.tax_fraction_for_current_item = me.get_current_tax_fraction(tax, item_tax_map);
|
||||||
|
|
||||||
if(i==0) {
|
if(i==0) {
|
||||||
@ -325,7 +325,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
|||||||
var me = this;
|
var me = this;
|
||||||
this.frm.doc.net_total = this.frm.doc.net_total_export = 0.0;
|
this.frm.doc.net_total = this.frm.doc.net_total_export = 0.0;
|
||||||
|
|
||||||
$.each(this.frm.doc["items"], function(i, item) {
|
$.each(this.frm.doc["items"] || [], function(i, item) {
|
||||||
me.frm.doc.net_total += item.base_amount;
|
me.frm.doc.net_total += item.base_amount;
|
||||||
me.frm.doc.net_total_export += item.amount;
|
me.frm.doc.net_total_export += item.amount;
|
||||||
});
|
});
|
||||||
@ -335,7 +335,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
|||||||
|
|
||||||
calculate_totals: function() {
|
calculate_totals: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
var tax_count = this.frm.doc["taxes"].length;
|
var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length: 0;
|
||||||
|
|
||||||
this.frm.doc.grand_total = flt(tax_count ? this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.net_total);
|
this.frm.doc.grand_total = flt(tax_count ? this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.net_total);
|
||||||
this.frm.doc.grand_total_export = flt(this.frm.doc.grand_total / this.frm.doc.conversion_rate);
|
this.frm.doc.grand_total_export = flt(this.frm.doc.grand_total / this.frm.doc.conversion_rate);
|
||||||
@ -364,7 +364,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
|||||||
var grand_total_for_discount_amount = this.get_grand_total_for_discount_amount();
|
var grand_total_for_discount_amount = this.get_grand_total_for_discount_amount();
|
||||||
// calculate item amount after Discount Amount
|
// calculate item amount after Discount Amount
|
||||||
if (grand_total_for_discount_amount) {
|
if (grand_total_for_discount_amount) {
|
||||||
$.each(this.frm.doc["items"], function(i, item) {
|
$.each(this.frm.doc["items"] || [], function(i, item) {
|
||||||
distributed_amount = flt(me.frm.doc.base_discount_amount) * item.base_amount / grand_total_for_discount_amount;
|
distributed_amount = flt(me.frm.doc.base_discount_amount) * item.base_amount / grand_total_for_discount_amount;
|
||||||
item.base_amount = flt(item.base_amount - distributed_amount, precision("base_amount", item));
|
item.base_amount = flt(item.base_amount - distributed_amount, precision("base_amount", item));
|
||||||
});
|
});
|
||||||
@ -382,7 +382,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
|||||||
var total_actual_tax = 0.0;
|
var total_actual_tax = 0.0;
|
||||||
var actual_taxes_dict = {};
|
var actual_taxes_dict = {};
|
||||||
|
|
||||||
$.each(this.frm.doc["taxes"], function(i, tax) {
|
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
|
||||||
if (tax.charge_type == "Actual")
|
if (tax.charge_type == "Actual")
|
||||||
actual_taxes_dict[tax.idx] = tax.tax_amount;
|
actual_taxes_dict[tax.idx] = tax.tax_amount;
|
||||||
else if (actual_taxes_dict[tax.row_id] !== null) {
|
else if (actual_taxes_dict[tax.row_id] !== null) {
|
||||||
|
|||||||
@ -73,7 +73,7 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({
|
|||||||
|
|
||||||
set_total_taxes_and_charges: function() {
|
set_total_taxes_and_charges: function() {
|
||||||
total_taxes_and_charges = 0.0;
|
total_taxes_and_charges = 0.0;
|
||||||
$.each(this.frm.doc.taxes, function(i, d) {
|
$.each(this.frm.doc.taxes || [], function(i, d) {
|
||||||
total_taxes_and_charges += flt(d.amount)
|
total_taxes_and_charges += flt(d.amount)
|
||||||
});
|
});
|
||||||
cur_frm.set_value("total_taxes_and_charges", total_taxes_and_charges);
|
cur_frm.set_value("total_taxes_and_charges", total_taxes_and_charges);
|
||||||
@ -83,11 +83,11 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({
|
|||||||
var me = this;
|
var me = this;
|
||||||
if(this.frm.doc.taxes.length) {
|
if(this.frm.doc.taxes.length) {
|
||||||
var total_item_cost = 0.0;
|
var total_item_cost = 0.0;
|
||||||
$.each(this.frm.doc.items, function(i, d) {
|
$.each(this.frm.doc.items || [], function(i, d) {
|
||||||
total_item_cost += flt(d.amount)
|
total_item_cost += flt(d.amount)
|
||||||
});
|
});
|
||||||
|
|
||||||
$.each(this.frm.doc.items, function(i, item) {
|
$.each(this.frm.doc.items || [], function(i, item) {
|
||||||
item.applicable_charges = flt(item.amount) * flt(me.frm.doc.total_taxes_and_charges) / flt(total_item_cost)
|
item.applicable_charges = flt(item.amount) * flt(me.frm.doc.total_taxes_and_charges) / flt(total_item_cost)
|
||||||
});
|
});
|
||||||
refresh_field("items");
|
refresh_field("items");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user