refactor: use read_only_depends_on instead of code (#27008)

(cherry picked from commit 332ac105b5)

# Conflicts:
#	erpnext/accounts/doctype/pos_invoice/pos_invoice.js
#	erpnext/accounts/doctype/sales_invoice/sales_invoice.js
This commit is contained in:
Pruthvi Patel
2021-08-24 12:07:38 +05:30
committed by frappe-pr-bot
parent 352157c9fc
commit f08d7410be
4 changed files with 16 additions and 14 deletions

View File

@@ -110,17 +110,18 @@ erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend(
this.frm.refresh_field("base_paid_amount");
},
<<<<<<< HEAD
write_off_outstanding_amount_automatically: function() {
if(cint(this.frm.doc.write_off_outstanding_amount_automatically)) {
=======
write_off_outstanding_amount_automatically() {
if (cint(this.frm.doc.write_off_outstanding_amount_automatically)) {
>>>>>>> 332ac105b5 (refactor: use `read_only_depends_on` instead of code (#27008))
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "paid_amount"]);
// this will make outstanding amount 0
this.frm.set_value("write_off_amount",
flt(this.frm.doc.grand_total - this.frm.doc.paid_amount - this.frm.doc.total_advance, precision("write_off_amount"))
);
this.frm.toggle_enable("write_off_amount", false);
} else {
this.frm.toggle_enable("write_off_amount", true);
}
this.calculate_outstanding_amount(false);

View File

@@ -1183,7 +1183,8 @@
"label": "Write Off Amount",
"no_copy": 1,
"options": "currency",
"print_hide": 1
"print_hide": 1,
"read_only_depends_on": "eval: doc.write_off_outstanding_amount_automatically"
},
{
"fieldname": "base_write_off_amount",
@@ -1554,7 +1555,7 @@
"icon": "fa fa-file-text",
"is_submittable": 1,
"links": [],
"modified": "2021-08-17 20:13:44.255437",
"modified": "2021-08-18 16:13:52.080543",
"modified_by": "Administrator",
"module": "Accounts",
"name": "POS Invoice",

View File

@@ -323,17 +323,18 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
this.frm.refresh_fields();
},
<<<<<<< HEAD
write_off_outstanding_amount_automatically: function() {
if(cint(this.frm.doc.write_off_outstanding_amount_automatically)) {
=======
write_off_outstanding_amount_automatically() {
if (cint(this.frm.doc.write_off_outstanding_amount_automatically)) {
>>>>>>> 332ac105b5 (refactor: use `read_only_depends_on` instead of code (#27008))
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "paid_amount"]);
// this will make outstanding amount 0
this.frm.set_value("write_off_amount",
flt(this.frm.doc.grand_total - this.frm.doc.paid_amount - this.frm.doc.total_advance, precision("write_off_amount"))
);
this.frm.toggle_enable("write_off_amount", false);
} else {
this.frm.toggle_enable("write_off_amount", true);
}
this.calculate_outstanding_amount(false);
@@ -787,8 +788,6 @@ frappe.ui.form.on('Sales Invoice', {
if (frappe.boot.sysdefaults.country == 'India') unhide_field(['c_form_applicable', 'c_form_no']);
else hide_field(['c_form_applicable', 'c_form_no']);
frm.toggle_enable("write_off_amount", !!!cint(doc.write_off_outstanding_amount_automatically));
frm.refresh_fields();
},

View File

@@ -1444,7 +1444,8 @@
"label": "Write Off Amount",
"no_copy": 1,
"options": "currency",
"print_hide": 1
"print_hide": 1,
"read_only_depends_on": "eval:doc.write_off_outstanding_amount_automatically"
},
{
"fieldname": "base_write_off_amount",
@@ -2016,7 +2017,7 @@
"link_fieldname": "consolidated_invoice"
}
],
"modified": "2021-08-17 20:16:12.737743",
"modified": "2021-08-18 16:07:45.122570",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",