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
This commit is contained in:
Shubh Doshi
2026-03-12 16:27:51 +05:30
committed by GitHub
parent 0e888cc86b
commit ad8c05426e
16 changed files with 48 additions and 39 deletions

View File

@@ -5,6 +5,7 @@
"doctype": "DocType", "doctype": "DocType",
"document_type": "Document", "document_type": "Document",
"engine": "InnoDB", "engine": "InnoDB",
"is_submittable": 1,
"field_order": [ "field_order": [
"closing_date", "closing_date",
"account", "account",

View File

@@ -4,6 +4,7 @@
"creation": "2024-10-16 16:57:12.085072", "creation": "2024-10-16 16:57:12.085072",
"doctype": "DocType", "doctype": "DocType",
"engine": "InnoDB", "engine": "InnoDB",
"is_submittable": 1,
"field_order": [ "field_order": [
"company", "company",
"voucher_type", "voucher_type",

View File

@@ -5,6 +5,7 @@
"doctype": "DocType", "doctype": "DocType",
"document_type": "Document", "document_type": "Document",
"engine": "InnoDB", "engine": "InnoDB",
"is_submittable": 1,
"field_order": [ "field_order": [
"dates_section", "dates_section",
"posting_date", "posting_date",

View File

@@ -5,6 +5,7 @@
"doctype": "DocType", "doctype": "DocType",
"editable_grid": 1, "editable_grid": 1,
"engine": "InnoDB", "engine": "InnoDB",
"is_submittable": 1,
"field_order": [ "field_order": [
"posting_date", "posting_date",
"company", "company",

View File

@@ -867,11 +867,16 @@ class POSInvoice(SalesInvoice):
idx = self.payments[-1].idx if self.payments else -1 idx = self.payments[-1].idx if self.payments else -1
self.reload()
self.flags.ignore_validate_update_after_submit = True
for d in payments: for d in payments:
idx += 1 idx += 1
payment = create_payments_on_invoice(self, idx, frappe._dict(d)) payment = create_payments_on_invoice(self, idx, frappe._dict(d))
paid_amount += flt(payment.amount) paid_amount += flt(payment.amount)
payment.submit() self.append("payments", payment)
self.save()
paid_amount = flt(flt(paid_amount), self.precision("paid_amount")) 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")) base_paid_amount = flt(flt(paid_amount * self.conversion_rate), self.precision("base_paid_amount"))

View File

@@ -85,5 +85,5 @@ def create_shipping_rule(shipping_rule_type, shipping_rule_name):
}, },
) )
sr.insert(ignore_permissions=True) sr.insert(ignore_permissions=True)
sr.submit()
return sr return sr

View File

@@ -197,6 +197,7 @@ class TaxWithholdingEntry(Document):
new_entry = frappe.copy_doc(old_entry) new_entry = frappe.copy_doc(old_entry)
new_entry.update(values_to_update) new_entry.update(values_to_update)
new_entry.skip_docstatus_validation = True
new_entry.insert() new_entry.insert()
docs_needing_reindex.add((old_entry.parenttype, old_entry.parent)) docs_needing_reindex.add((old_entry.parenttype, old_entry.parent))
@@ -335,6 +336,7 @@ class TaxWithholdingEntry(Document):
"withholding_date": None, "withholding_date": None,
} }
new_entry.update(values_to_update) new_entry.update(values_to_update)
new_entry.skip_docstatus_validation = True
new_entry.insert() new_entry.insert()
docs_needing_reindex.add((entry.parenttype, entry.parent)) docs_needing_reindex.add((entry.parenttype, entry.parent))

View File

@@ -429,6 +429,8 @@ def make_entry(args, adv_adj, update_outstanding, from_repost=False):
gle.flags.adv_adj = adv_adj gle.flags.adv_adj = adv_adj
gle.flags.update_outstanding = update_outstanding or "Yes" gle.flags.update_outstanding = update_outstanding or "Yes"
gle.flags.notify_update = False gle.flags.notify_update = False
if gle.is_cancelled:
gle.flags.ignore_links = True
gle.submit() gle.submit()
if ( if (

View File

@@ -692,11 +692,9 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase):
) )
def test_sales_person(self): def test_sales_person(self):
sales_person = ( sales_person = frappe.get_doc(
frappe.get_doc({"doctype": "Sales Person", "sales_person_name": "John Clark", "enabled": True}) {"doctype": "Sales Person", "sales_person_name": "John Clark", "enabled": True}
.insert() ).insert()
.submit()
)
si = self.create_sales_invoice(do_not_submit=True) si = self.create_sales_invoice(do_not_submit=True)
si.append("sales_team", {"sales_person": sales_person.name, "allocated_percentage": 100}) si.append("sales_team", {"sales_person": sales_person.name, "allocated_percentage": 100})
si.save().submit() si.save().submit()
@@ -772,18 +770,14 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase):
def test_party_account_filter(self): def test_party_account_filter(self):
si1 = self.create_sales_invoice() si1 = self.create_sales_invoice()
self.customer2 = ( self.customer2 = frappe.get_doc(
frappe.get_doc( {
{ "doctype": "Customer",
"doctype": "Customer", "customer_name": "Jane Doe",
"customer_name": "Jane Doe", "type": "Individual",
"type": "Individual", "default_currency": "USD",
"default_currency": "USD", }
} ).insert()
)
.insert()
.submit()
)
si2 = self.create_sales_invoice(do_not_submit=True) si2 = self.create_sales_invoice(do_not_submit=True)
si2.posting_date = add_days(today(), -1) si2.posting_date = add_days(today(), -1)
@@ -995,18 +989,14 @@ class TestAccountsReceivable(AccountsTestMixin, IntegrationTestCase):
self.assertEqual(expected_data, report_output) self.assertEqual(expected_data, report_output)
def test_future_payments_on_foreign_currency(self): def test_future_payments_on_foreign_currency(self):
self.customer2 = ( self.customer2 = frappe.get_doc(
frappe.get_doc( {
{ "doctype": "Customer",
"doctype": "Customer", "customer_name": "Jane Doe",
"customer_name": "Jane Doe", "type": "Individual",
"type": "Individual", "default_currency": "USD",
"default_currency": "USD", }
} ).insert()
)
.insert()
.submit()
)
si = self.create_sales_invoice(do_not_submit=True) si = self.create_sales_invoice(do_not_submit=True)
si.posting_date = add_days(today(), -1) si.posting_date = add_days(today(), -1)

View File

@@ -2142,6 +2142,7 @@ def create_payment_ledger_entry(
if is_immutable_ledger_enabled(): if is_immutable_ledger_enabled():
ple.delinked = 0 ple.delinked = 0
ple.posting_date = frappe.form_dict.get("posting_date") or getdate() ple.posting_date = frappe.form_dict.get("posting_date") or getdate()
ple.flags.ignore_links = True
ple.flags.ignore_permissions = 1 ple.flags.ignore_permissions = 1
ple.flags.adv_adj = adv_adj ple.flags.adv_adj = adv_adj

View File

@@ -721,6 +721,7 @@ class SubcontractingInwardController:
"Subcontracting Inward Order Item", item.against_fg, "item_code" "Subcontracting Inward Order Item", item.against_fg, "item_code"
), ),
) )
scio_rm.skip_docstatus_validation = True
scio_rm.insert() scio_rm.insert()
scio_rm.submit() scio_rm.submit()
item.db_set("scio_detail", scio_rm.name) item.db_set("scio_detail", scio_rm.name)
@@ -867,6 +868,7 @@ class SubcontractingInwardController:
warehouse=extra_item.s_warehouse, warehouse=extra_item.s_warehouse,
is_additional_item=True, is_additional_item=True,
) )
doc.skip_docstatus_validation = True
doc.insert() doc.insert()
doc.submit() doc.submit()
@@ -954,6 +956,7 @@ class SubcontractingInwardController:
"Work Order", self.work_order, "subcontracting_inward_order_item" "Work Order", self.work_order, "subcontracting_inward_order_item"
), ),
) )
doc.skip_docstatus_validation = True
doc.insert() doc.insert()
doc.submit() doc.submit()

View File

@@ -2483,7 +2483,7 @@ class TestAccountsController(IntegrationTestCase):
def test_document_naming_rule_based_on_posting_date(self): def test_document_naming_rule_based_on_posting_date(self):
frappe.new_doc( frappe.new_doc(
"Document Naming Rule", document_type="Sales Invoice", prefix="SI-.MM.-.YYYY.-" "Document Naming Rule", document_type="Sales Invoice", prefix="SI-.MM.-.YYYY.-"
).submit() ).insert()
si = create_sales_invoice(do_not_save=True) si = create_sales_invoice(do_not_save=True)
si.set_posting_time = 1 si.set_posting_time = 1

View File

@@ -2068,9 +2068,11 @@ class WorkOrder(Document):
if row.item_code not in required_items: if row.item_code not in required_items:
additional_items.setdefault(row.item_code, []).append(row) 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 item_code, rows in additional_items.items():
for row in rows: for row in rows:
child_row = self.append( self.append(
"required_items", "required_items",
{ {
"item_code": item_code, "item_code": item_code,
@@ -2081,15 +2083,13 @@ class WorkOrder(Document):
"rate": row.basic_rate, "rate": row.basic_rate,
"amount": row.amount, "amount": row.amount,
"description": row.description, "description": row.description,
"docstatus": 1,
"is_additional_item": 1, "is_additional_item": 1,
"voucher_detail_reference": row.name, "voucher_detail_reference": row.name,
}, },
) )
child_row.insert() self.save()
stock_entry.reload()
stock_entry.reload()
@frappe.whitelist() @frappe.whitelist()

View File

@@ -4278,8 +4278,7 @@ class TestPurchaseReceipt(IntegrationTestCase):
self.assertTrue(sles) self.assertTrue(sles)
for row in sles: for row in sles:
doc = frappe.get_doc("Stock Ledger Entry", row) frappe.db.delete("Stock Ledger Entry", {"name": row})
doc.delete()
sles = frappe.get_all( sles = frappe.get_all(
"Stock Ledger Entry", "Stock Ledger Entry",

View File

@@ -6,6 +6,7 @@
"doctype": "DocType", "doctype": "DocType",
"document_type": "Other", "document_type": "Other",
"engine": "InnoDB", "engine": "InnoDB",
"is_submittable": 1,
"field_order": [ "field_order": [
"item_code", "item_code",
"warehouse", "warehouse",

View File

@@ -230,6 +230,8 @@ def make_entry(args, allow_negative_stock=False, via_landed_cost_voucher=False):
sle.flags.ignore_permissions = 1 sle.flags.ignore_permissions = 1
sle.allow_negative_stock = allow_negative_stock sle.allow_negative_stock = allow_negative_stock
sle.via_landed_cost_voucher = via_landed_cost_voucher sle.via_landed_cost_voucher = via_landed_cost_voucher
if args.get("is_cancelled"):
sle.flags.ignore_links = True
sle.submit() sle.submit()
# Added to handle the case when the stock ledger entry is created from the repostig # Added to handle the case when the stock ledger entry is created from the repostig