diff --git a/erpnext/public/js/utils/sales_common.js b/erpnext/public/js/utils/sales_common.js index 7e636d7ba4ee1ab2b53cf3bd8a745117be9d23f1..0a4006ebe92846e5bd4025a190c6a7eaaacde9e2 100644 --- a/erpnext/public/js/utils/sales_common.js +++ b/erpnext/public/js/utils/sales_common.js @@ -460,7 +460,7 @@ erpnext.sales_common = { } gross_profit_percentage(doc, cdt, cdn) { - if (this.frm.fields_dict["items"].grid.fields_map["gross_profit_percentage"].read_only) { + if (this.frm.fields_dict["items"]?.grid.fields_map["gross_profit_percentage"]?.read_only) { return } @@ -480,13 +480,13 @@ erpnext.sales_common = { } markup_percentage(doc, cdt, cdn) { - if (this.frm.fields_dict["items"].grid.fields_map["markup_percentage"].read_only) { - return + if (this.frm.fields_dict["items"]?.grid.fields_map["markup_percentage"]?.read_only) { + return; } if (["Sales Order", "Quotation"].includes(this.frm.doc.doctype)) { const item = locals[cdt][cdn]; - if (item.markup_percentage && item.gross_profit_calculation_rule && !erpnext.selling.do_not_update_rate) { + if (item.unit_cost_price && item.markup_percentage > 0 && item.markup_percentage < 100 && item.gross_profit_calculation_rule && !erpnext.selling.do_not_update_rate) { const rate = item.unit_cost_price / (100 - item.markup_percentage) * 100 if (flt(item.rate, precision("rate", item)) != flt(rate, precision("rate", item))) {