From 0e807f3ef180539935e4e00bd30dd641f89b1d7d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 2 May 2026 17:32:22 +0000 Subject: [PATCH] fix: replace frappe.get_doc with frappe.new_doc in new tests, fix RUF003 comment Agent-Logs-Url: https://github.com/frappe/erpnext/sessions/b87be10b-3c3e-4f96-a102-a0206d727bd1 Co-authored-by: mihir-kandoi <8833206+mihir-kandoi@users.noreply.github.com> --- .../tests/test_taxes_and_totals.py | 2 +- .../tests/test_transaction_base.py | 56 +++++++++---------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/erpnext/controllers/tests/test_taxes_and_totals.py b/erpnext/controllers/tests/test_taxes_and_totals.py index 2bb639d0e1e..00466c15a1a 100644 --- a/erpnext/controllers/tests/test_taxes_and_totals.py +++ b/erpnext/controllers/tests/test_taxes_and_totals.py @@ -113,7 +113,7 @@ class TestTaxesAndTotals(ERPNextTestSuite): calculate_taxes_and_totals(qo) - # Only the first (non-alternative) item should contribute: 5 × 100 = 500 + # Only the first (non-alternative) item should contribute: 5 x 100 = 500 self.assertEqual(qo.net_total, 500.0) self.assertEqual(qo.grand_total, 500.0) diff --git a/erpnext/controllers/tests/test_transaction_base.py b/erpnext/controllers/tests/test_transaction_base.py index e2ed9f3fca5..8dd27bdbaa9 100644 --- a/erpnext/controllers/tests/test_transaction_base.py +++ b/erpnext/controllers/tests/test_transaction_base.py @@ -96,7 +96,7 @@ class TestUtils(ERPNextTestSuite): def test_validate_posting_time_invalid(self): """An invalid posting_time string must raise a ValidationError.""" - doc = frappe.get_doc({"doctype": "Stock Entry"}) + doc = frappe.new_doc("Stock Entry") doc.set_posting_time = 1 doc.posting_time = "not-a-time" @@ -104,9 +104,9 @@ class TestUtils(ERPNextTestSuite): def test_validate_posting_time_auto_set(self): """When set_posting_time is falsy, posting_date and posting_time are replaced with now.""" - from frappe.utils import getdate, nowdate + from frappe.utils import nowdate - doc = frappe.get_doc({"doctype": "Stock Entry"}) + doc = frappe.new_doc("Stock Entry") doc.set_posting_time = 0 doc.posting_date = "2000-01-01" doc.posting_time = "00:00:00" @@ -123,42 +123,36 @@ class TestUtils(ERPNextTestSuite): from erpnext.utilities.transaction_base import UOMMustBeIntegerError # Nos is seeded as a whole-number UOM in test fixtures - se = frappe.get_doc( + se = frappe.new_doc("Stock Entry") + se.purpose = "Material Receipt" + se.company = "_Test Company" + se.append( + "items", { - "doctype": "Stock Entry", - "purpose": "Material Receipt", - "company": "_Test Company", - "items": [ - { - "item_code": "_Test Item", - "uom": "Nos", - "qty": 1.5, - "t_warehouse": "_Test Warehouse - _TC", - "basic_rate": 100, - } - ], - } + "item_code": "_Test Item", + "uom": "Nos", + "qty": 1.5, + "t_warehouse": "_Test Warehouse - _TC", + "basic_rate": 100, + }, ) self.assertRaises(UOMMustBeIntegerError, validate_uom_is_integer, se, "uom", "qty") def test_validate_uom_is_integer_passes_for_whole_number(self): """Integer qty in a whole-number UOM must NOT raise any error.""" - se = frappe.get_doc( + se = frappe.new_doc("Stock Entry") + se.purpose = "Material Receipt" + se.company = "_Test Company" + se.append( + "items", { - "doctype": "Stock Entry", - "purpose": "Material Receipt", - "company": "_Test Company", - "items": [ - { - "item_code": "_Test Item", - "uom": "Nos", - "qty": 3, - "t_warehouse": "_Test Warehouse - _TC", - "basic_rate": 100, - } - ], - } + "item_code": "_Test Item", + "uom": "Nos", + "qty": 3, + "t_warehouse": "_Test Warehouse - _TC", + "basic_rate": 100, + }, ) # Should complete without raising