mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-15 15:38:39 +00:00
fix: add docstrings and unify update_stock visibility in JS
This commit is contained in:
@@ -567,7 +567,8 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends (
|
||||
set_dynamic_labels() {
|
||||
super.set_dynamic_labels();
|
||||
this.frm.events.hide_fields(this.frm);
|
||||
this.frm.set_df_property("update_stock", "hidden", cint(this.frm.doc.is_debit_note));
|
||||
const hide_update_stock = cint(this.frm.doc.is_debit_note) || cint(this.frm.doc.has_subcontracted);
|
||||
this.frm.set_df_property("update_stock", "hidden", hide_update_stock);
|
||||
}
|
||||
|
||||
items_on_form_rendered() {
|
||||
@@ -1160,8 +1161,8 @@ frappe.ui.form.on("Sales Invoice", {
|
||||
if (frm.doc.is_debit_note) {
|
||||
frm.set_value("update_stock", 0);
|
||||
}
|
||||
frm.set_df_property("update_stock", "hidden", cint(frm.doc.is_debit_note));
|
||||
frm.refresh_field("update_stock");
|
||||
// visibility handled by set_dynamic_labels()
|
||||
frm.cscript.set_dynamic_labels();
|
||||
},
|
||||
|
||||
refresh: function (frm) {
|
||||
@@ -1170,7 +1171,6 @@ frappe.ui.form.on("Sales Invoice", {
|
||||
}
|
||||
|
||||
frm.set_df_property("update_stock", "read_only", frm.doc.has_subcontracted);
|
||||
frm.toggle_display("update_stock", !frm.doc.has_subcontracted);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1286,6 +1286,7 @@ class SalesInvoice(SellingController):
|
||||
msgprint(_("Please enter Account for Change Amount"), raise_exception=1)
|
||||
|
||||
def validate_debit_note_with_update_stock(self):
|
||||
"""Prevent stock update when Sales Invoice is marked as Debit Note."""
|
||||
if self.is_debit_note and cint(self.update_stock):
|
||||
frappe.throw(
|
||||
_(
|
||||
|
||||
@@ -4863,6 +4863,7 @@ class TestSalesInvoice(ERPNextTestSuite):
|
||||
frappe.db.set_value("Company", "_Test Company 1", "cost_center", cost_center)
|
||||
|
||||
def test_debit_note_with_update_stock_validation(self):
|
||||
"""Test that saving a Debit Note with Update Stock enabled raises ValidationError."""
|
||||
si = create_sales_invoice(do_not_save=True)
|
||||
si.is_debit_note = 1
|
||||
si.update_stock = 1
|
||||
|
||||
Reference in New Issue
Block a user