refactor(test): make purchase receipt deterministic

This commit is contained in:
ruthra kumar
2026-01-03 17:30:32 +05:30
parent 8dd9ab6475
commit 577be4f9ad
3 changed files with 45 additions and 18 deletions

View File

@@ -35,7 +35,7 @@ class TestPurchaseReceipt(ERPNextTestSuite):
cls.load_test_records("Purchase Receipt")
def setUp(self):
frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1)
frappe.local.future_sle = {}
def tearDown(self):
frappe.db.rollback()
@@ -2665,12 +2665,12 @@ class TestPurchaseReceipt(ERPNextTestSuite):
gl_entries = get_gl_entries("Purchase Receipt", pr.name, skip_cancelled=True, as_dict=False)
warehouse_account = get_warehouse_account_map("_Test Company")
expected_gle = (
("Stock Received But Not Billed - _TC", 0, 10000, "Main - _TC"),
("Freight and Forwarding Charges - _TC", 0, 2000, "Main - _TC"),
("Expenses Included In Valuation - _TC", 0, 2000, "Main - _TC"),
(warehouse_account[pr.items[0].warehouse]["account"], 14000, 0, "Main - _TC"),
("Stock Received But Not Billed - _TC", 0.0, 10000.0, "Main - _TC"),
("Freight and Forwarding Charges - _TC", 0.0, 2000.0, "Main - _TC"),
("Expenses Included In Valuation - _TC", 0.0, 2000.0, "Main - _TC"),
(warehouse_account[pr.items[0].warehouse]["account"], 14000.0, 0.0, "Main - _TC"),
)
self.assertSequenceEqual(expected_gle, gl_entries)
self.assertCountEqual(expected_gle, gl_entries)
frappe.local.enable_perpetual_inventory["_Test Company"] = old_perpetual_inventory
def test_purchase_receipt_with_use_serial_batch_field_for_rejected_qty(self):
@@ -4177,8 +4177,6 @@ class TestPurchaseReceipt(ERPNextTestSuite):
make_purchase_return,
)
frappe.flags.through_repost_item_valuation = False
sn_item_code = make_item(
"Test Serial No for Validation", {"has_serial_no": 1, "serial_no_series": "SN-TSNFVAL-.#####"}
).name
@@ -4211,8 +4209,6 @@ class TestPurchaseReceipt(ERPNextTestSuite):
make_purchase_return,
)
frappe.flags.through_repost_item_valuation = False
batch_item_code = make_item(
"Test Batch No for Validation",
{"has_batch_no": 1, "batch_number_series": "BT-TSNFVAL-.#####", "create_new_batch": 1},
@@ -4856,8 +4852,14 @@ class TestPurchaseReceipt(ERPNextTestSuite):
self.assertRaises(NegativeStockError, pr.cancel)
@ERPNextTestSuite.change_settings(
"Buying Settings", {"set_landed_cost_based_on_purchase_invoice_rate": 1, "maintain_same_rate": 0}
"Buying Settings",
{
"set_landed_cost_based_on_purchase_invoice_rate": 1,
"maintain_same_rate": 0,
"allow_multiple_items": 1,
},
)
@ERPNextTestSuite.change_settings("Accounts Settings", {"over_billing_allowance": 100})
def test_set_lcv_from_pi_created_against_po(self):
from erpnext.buying.doctype.purchase_order.purchase_order import (
make_purchase_invoice as make_pi_against_po,
@@ -4867,10 +4869,6 @@ class TestPurchaseReceipt(ERPNextTestSuite):
)
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
original_value = frappe.db.get_single_value("Accounts Settings", "over_billing_allowance")
frappe.db.set_single_value("Accounts Settings", "over_billing_allowance", 100)
item_code = create_item("Test Item for LCV from PI against PO").name
po = create_purchase_order(item_code=item_code, qty=10, rate=400)
@@ -4895,8 +4893,6 @@ class TestPurchaseReceipt(ERPNextTestSuite):
amt_diff = 5000 * (row.qty / 10) - row.amount
self.assertEqual(row.amount_difference_with_purchase_invoice, amt_diff)
frappe.db.set_single_value("Accounts Settings", "over_billing_allowance", original_value)
def test_purchase_return_with_and_without_return_against_rejected_qty(self):
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
make_purchase_return as _make_purchase_return,

View File

@@ -444,7 +444,7 @@ class SerialandBatchBundle(Document):
self.set_incoming_rate_for_inward_transaction(row, save, prev_sle=prev_sle)
def validate_returned_serial_batch_no(self, return_against, row, original_inv_details):
if frappe.flags.through_repost_item_valuation:
if frappe.flags.through_repost_item_valuation and not frappe.in_test:
return
if row.serial_no and row.serial_no not in original_inv_details["serial_nos"]:

View File

@@ -1186,6 +1186,15 @@ class ERPNextTestSuite(unittest.TestCase):
"supplier_group": "_Test Supplier Group",
"tax_category": "_Test Tax Category 1",
},
{
"doctype": "Supplier",
"supplier_name": "_Test Internal Supplier 2",
"supplier_group": "_Test Supplier Group",
"is_internal_supplier": 1,
"territory": "_Test Territory",
"represents_company": cls.companies[6].name,
"companies": [{"company": cls.companies[6].name}],
},
]
cls.suppliers = []
for x in records:
@@ -2218,6 +2227,18 @@ class ERPNextTestSuite(unittest.TestCase):
"batch_number_series": "BASR.#####",
"create_new_batch": 1,
},
{
"doctype": "Item",
"item_code": "Test Asset Item",
"item_name": "Test Asset Item",
"is_stock_item": 0,
"item_group": "All Item Groups",
"stock_uom": "Box",
"is_fixed_asset": 1,
"auto_create_assets": 1,
"asset_category": cls.asset_category[0].name,
"asset_naming_series": "ABC.###",
},
]
cls.item = []
for x in records:
@@ -2405,6 +2426,16 @@ class ERPNextTestSuite(unittest.TestCase):
"doctype": "Customer",
"territory": "_Test Territory",
},
{
"customer_group": "_Test Customer Group",
"customer_name": "_Test Internal Customer 2",
"customer_type": "Individual",
"doctype": "Customer",
"is_internal_customer": 1,
"territory": "_Test Territory",
"represents_company": cls.companies[6].name,
"companies": [{"company": cls.companies[6].name}],
},
]
cls.customer = []
for x in records: