From ad8c05426e5f97e27246667ff1dce791a64881b5 Mon Sep 17 00:00:00 2001 From: Shubh Doshi <124681920+shubhdoshi21@users.noreply.github.com> Date: Thu, 12 Mar 2026 16:27:51 +0530 Subject: [PATCH] fix: make ledger entries submittable and cleanup invalid test submissions (#52921) * fix: enable submittability for ledger entries and cleanup invalid test submissions * fix: reverted child table submittability * fix: added ignore_links flag for back gl entry * fix: add ignore_links for reconcile,cancelled PLE,cancelled SLE * fix: update test_recreate_stock_ledgers to use db.delete instead of doc.delete * chore: temporary test against frappe PR 37009 * fix: make Advance Payment Ledger Entry submittable * refactor: add extra line for create_shipping_rule * chore: revert temporary test against frappe PR 37009 * fix: use parent doc save with ignore_validate_update_after_submit for child table updates * chore: temporary test against frappe PR 37009 * chore: revert temporary test against frappe PR 37009 * fix: use skip_docstatus_validation --- .../account_closing_balance.json | 1 + .../advance_payment_ledger_entry.json | 1 + .../accounts/doctype/gl_entry/gl_entry.json | 1 + .../payment_ledger_entry.json | 1 + .../doctype/pos_invoice/pos_invoice.py | 7 ++- .../shipping_rule/test_shipping_rule.py | 2 +- .../tax_withholding_entry.py | 2 + erpnext/accounts/general_ledger.py | 2 + .../test_accounts_receivable.py | 48 ++++++++----------- erpnext/accounts/utils.py | 1 + .../subcontracting_inward_controller.py | 3 ++ .../tests/test_accounts_controller.py | 2 +- .../doctype/work_order/work_order.py | 10 ++-- .../purchase_receipt/test_purchase_receipt.py | 3 +- .../stock_ledger_entry.json | 1 + erpnext/stock/stock_ledger.py | 2 + 16 files changed, 48 insertions(+), 39 deletions(-) diff --git a/erpnext/accounts/doctype/account_closing_balance/account_closing_balance.json b/erpnext/accounts/doctype/account_closing_balance/account_closing_balance.json index b980a8378a9..c17a79642dd 100644 --- a/erpnext/accounts/doctype/account_closing_balance/account_closing_balance.json +++ b/erpnext/accounts/doctype/account_closing_balance/account_closing_balance.json @@ -5,6 +5,7 @@ "doctype": "DocType", "document_type": "Document", "engine": "InnoDB", + "is_submittable": 1, "field_order": [ "closing_date", "account", diff --git a/erpnext/accounts/doctype/advance_payment_ledger_entry/advance_payment_ledger_entry.json b/erpnext/accounts/doctype/advance_payment_ledger_entry/advance_payment_ledger_entry.json index 1bf909117a8..2783cb1bda4 100644 --- a/erpnext/accounts/doctype/advance_payment_ledger_entry/advance_payment_ledger_entry.json +++ b/erpnext/accounts/doctype/advance_payment_ledger_entry/advance_payment_ledger_entry.json @@ -4,6 +4,7 @@ "creation": "2024-10-16 16:57:12.085072", "doctype": "DocType", "engine": "InnoDB", + "is_submittable": 1, "field_order": [ "company", "voucher_type", diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.json b/erpnext/accounts/doctype/gl_entry/gl_entry.json index b3afb906c6b..a8815a7d19a 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.json +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.json @@ -5,6 +5,7 @@ "doctype": "DocType", "document_type": "Document", "engine": "InnoDB", + "is_submittable": 1, "field_order": [ "dates_section", "posting_date", diff --git a/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.json b/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.json index fcc3a15206a..de4bc9d98ef 100644 --- a/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.json +++ b/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.json @@ -5,6 +5,7 @@ "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", + "is_submittable": 1, "field_order": [ "posting_date", "company", diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index 53c1d75db4e..c9b35a27c29 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -867,11 +867,16 @@ class POSInvoice(SalesInvoice): idx = self.payments[-1].idx if self.payments else -1 + self.reload() + self.flags.ignore_validate_update_after_submit = True + for d in payments: idx += 1 payment = create_payments_on_invoice(self, idx, frappe._dict(d)) paid_amount += flt(payment.amount) - payment.submit() + self.append("payments", payment) + + self.save() paid_amount = flt(flt(paid_amount), self.precision("paid_amount")) base_paid_amount = flt(flt(paid_amount * self.conversion_rate), self.precision("base_paid_amount")) diff --git a/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py b/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py index 57099aae6a3..b9dd0d8dbb1 100644 --- a/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py +++ b/erpnext/accounts/doctype/shipping_rule/test_shipping_rule.py @@ -85,5 +85,5 @@ def create_shipping_rule(shipping_rule_type, shipping_rule_name): }, ) sr.insert(ignore_permissions=True) - sr.submit() + return sr diff --git a/erpnext/accounts/doctype/tax_withholding_entry/tax_withholding_entry.py b/erpnext/accounts/doctype/tax_withholding_entry/tax_withholding_entry.py index 6aff1116935..589ff28ace8 100644 --- a/erpnext/accounts/doctype/tax_withholding_entry/tax_withholding_entry.py +++ b/erpnext/accounts/doctype/tax_withholding_entry/tax_withholding_entry.py @@ -197,6 +197,7 @@ class TaxWithholdingEntry(Document): new_entry = frappe.copy_doc(old_entry) new_entry.update(values_to_update) + new_entry.skip_docstatus_validation = True new_entry.insert() docs_needing_reindex.add((old_entry.parenttype, old_entry.parent)) @@ -335,6 +336,7 @@ class TaxWithholdingEntry(Document): "withholding_date": None, } new_entry.update(values_to_update) + new_entry.skip_docstatus_validation = True new_entry.insert() docs_needing_reindex.add((entry.parenttype, entry.parent)) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 97008d0b057..a04511f0c40 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -429,6 +429,8 @@ def make_entry(args, adv_adj, update_outstanding, from_repost=False): gle.flags.adv_adj = adv_adj gle.flags.update_outstanding = update_outstanding or "Yes" gle.flags.notify_update = False + if gle.is_cancelled: + gle.flags.ignore_links = True gle.submit() if ( diff --git a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py index 907840e8ff4..6b9f49dcba8 100644 --- a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py @@ -692,11 +692,9 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): ) def test_sales_person(self): - sales_person = ( - frappe.get_doc({"doctype": "Sales Person", "sales_person_name": "John Clark", "enabled": True}) - .insert() - .submit() - ) + sales_person = frappe.get_doc( + {"doctype": "Sales Person", "sales_person_name": "John Clark", "enabled": True} + ).insert() si = self.create_sales_invoice(do_not_submit=True) si.append("sales_team", {"sales_person": sales_person.name, "allocated_percentage": 100}) si.save().submit() @@ -772,18 +770,14 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): def test_party_account_filter(self): si1 = self.create_sales_invoice() - self.customer2 = ( - frappe.get_doc( - { - "doctype": "Customer", - "customer_name": "Jane Doe", - "type": "Individual", - "default_currency": "USD", - } - ) - .insert() - .submit() - ) + self.customer2 = frappe.get_doc( + { + "doctype": "Customer", + "customer_name": "Jane Doe", + "type": "Individual", + "default_currency": "USD", + } + ).insert() si2 = self.create_sales_invoice(do_not_submit=True) si2.posting_date = add_days(today(), -1) @@ -995,18 +989,14 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase): self.assertEqual(expected_data, report_output) def test_future_payments_on_foreign_currency(self): - self.customer2 = ( - frappe.get_doc( - { - "doctype": "Customer", - "customer_name": "Jane Doe", - "type": "Individual", - "default_currency": "USD", - } - ) - .insert() - .submit() - ) + self.customer2 = frappe.get_doc( + { + "doctype": "Customer", + "customer_name": "Jane Doe", + "type": "Individual", + "default_currency": "USD", + } + ).insert() si = self.create_sales_invoice(do_not_submit=True) si.posting_date = add_days(today(), -1) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index c251bde15fc..d0707438745 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -2142,6 +2142,7 @@ def create_payment_ledger_entry( if is_immutable_ledger_enabled(): ple.delinked = 0 ple.posting_date = frappe.form_dict.get("posting_date") or getdate() + ple.flags.ignore_links = True ple.flags.ignore_permissions = 1 ple.flags.adv_adj = adv_adj diff --git a/erpnext/controllers/subcontracting_inward_controller.py b/erpnext/controllers/subcontracting_inward_controller.py index 77a9dfa89fd..876f25c51fd 100644 --- a/erpnext/controllers/subcontracting_inward_controller.py +++ b/erpnext/controllers/subcontracting_inward_controller.py @@ -721,6 +721,7 @@ class SubcontractingInwardController: "Subcontracting Inward Order Item", item.against_fg, "item_code" ), ) + scio_rm.skip_docstatus_validation = True scio_rm.insert() scio_rm.submit() item.db_set("scio_detail", scio_rm.name) @@ -867,6 +868,7 @@ class SubcontractingInwardController: warehouse=extra_item.s_warehouse, is_additional_item=True, ) + doc.skip_docstatus_validation = True doc.insert() doc.submit() @@ -954,6 +956,7 @@ class SubcontractingInwardController: "Work Order", self.work_order, "subcontracting_inward_order_item" ), ) + doc.skip_docstatus_validation = True doc.insert() doc.submit() diff --git a/erpnext/controllers/tests/test_accounts_controller.py b/erpnext/controllers/tests/test_accounts_controller.py index 553a7246fea..e3ad14693c0 100644 --- a/erpnext/controllers/tests/test_accounts_controller.py +++ b/erpnext/controllers/tests/test_accounts_controller.py @@ -2483,7 +2483,7 @@ class TestAccountsController(IntegrationTestCase): def test_document_naming_rule_based_on_posting_date(self): frappe.new_doc( "Document Naming Rule", document_type="Sales Invoice", prefix="SI-.MM.-.YYYY.-" - ).submit() + ).insert() si = create_sales_invoice(do_not_save=True) si.set_posting_time = 1 diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index c5860e2e08b..a4e418d08aa 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -2068,9 +2068,11 @@ class WorkOrder(Document): if row.item_code not in required_items: additional_items.setdefault(row.item_code, []).append(row) + self.flags.ignore_validate_update_after_submit = True + for item_code, rows in additional_items.items(): for row in rows: - child_row = self.append( + self.append( "required_items", { "item_code": item_code, @@ -2081,15 +2083,13 @@ class WorkOrder(Document): "rate": row.basic_rate, "amount": row.amount, "description": row.description, - "docstatus": 1, "is_additional_item": 1, "voucher_detail_reference": row.name, }, ) - child_row.insert() - - stock_entry.reload() + self.save() + stock_entry.reload() @frappe.whitelist() diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 8401d363745..8b99ea609ce 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -4278,8 +4278,7 @@ class TestPurchaseReceipt(IntegrationTestCase): self.assertTrue(sles) for row in sles: - doc = frappe.get_doc("Stock Ledger Entry", row) - doc.delete() + frappe.db.delete("Stock Ledger Entry", {"name": row}) sles = frappe.get_all( "Stock Ledger Entry", diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json index d5a50a51677..936dcd13650 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json +++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json @@ -6,6 +6,7 @@ "doctype": "DocType", "document_type": "Other", "engine": "InnoDB", + "is_submittable": 1, "field_order": [ "item_code", "warehouse", diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index c943caeea02..44ade731f37 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -230,6 +230,8 @@ def make_entry(args, allow_negative_stock=False, via_landed_cost_voucher=False): sle.flags.ignore_permissions = 1 sle.allow_negative_stock = allow_negative_stock sle.via_landed_cost_voucher = via_landed_cost_voucher + if args.get("is_cancelled"): + sle.flags.ignore_links = True sle.submit() # Added to handle the case when the stock ledger entry is created from the repostig