From d245165fdfe2dec4086c2c5ea4f4cf7a20c520ab Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Tue, 24 Oct 2023 19:10:23 +0530 Subject: [PATCH] chore: fixed test cases related to Internal Transfer (#37659) (cherry picked from commit 72d32a49012329d33fd4ecea70988fbfbfce566f) # Conflicts: # erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py # erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py --- .../sales_invoice/test_sales_invoice.py | 49 ++++++++ .../purchase_receipt/test_purchase_receipt.py | 118 ++++++++++++++++++ 2 files changed, 167 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 231b3bf7fe22..e1dfb3f17f98 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2537,7 +2537,42 @@ def test_inter_company_transaction_without_default_warehouse(self): # tear down frappe.local.enable_perpetual_inventory["_Test Company 1"] = old_perpetual_inventory +<<<<<<< HEAD frappe.db.set_single_value("Stock Settings", "allow_negative_stock", old_negative_stock) +======= + frappe.db.set_value("Stock Settings", None, "allow_negative_stock", old_negative_stock) + + def test_sle_for_target_warehouse(self): + se = make_stock_entry( + item_code="138-CMS Shoe", + target="Finished Goods - _TC", + company="_Test Company", + qty=1, + basic_rate=500, + ) + + si = frappe.copy_doc(test_records[0]) + si.customer = "_Test Internal Customer 3" + si.update_stock = 1 + si.set_warehouse = "Finished Goods - _TC" + si.set_target_warehouse = "Stores - _TC" + si.get("items")[0].warehouse = "Finished Goods - _TC" + si.get("items")[0].target_warehouse = "Stores - _TC" + si.insert() + si.submit() + + sles = frappe.get_all( + "Stock Ledger Entry", filters={"voucher_no": si.name}, fields=["name", "actual_qty"] + ) + + # check if both SLEs are created + self.assertEqual(len(sles), 2) + self.assertEqual(sum(d.actual_qty for d in sles), 0.0) + + # tear down + si.cancel() + se.cancel() +>>>>>>> 72d32a4901 (chore: fixed test cases related to Internal Transfer (#37659)) def test_internal_transfer_gl_entry(self): si = create_sales_invoice( @@ -3662,6 +3697,20 @@ def create_internal_parties(): allowed_to_interact_with="_Test Company with perpetual inventory", ) + create_internal_customer( + customer_name="_Test Internal Customer 3", + represents_company="_Test Company", + allowed_to_interact_with="_Test Company", + ) + + account = create_account( + account_name="Unrealized Profit", + parent_account="Current Liabilities - _TC", + company="_Test Company", + ) + + frappe.db.set_value("Company", "_Test Company", "unrealized_profit_loss_account", account) + create_internal_supplier( supplier_name="_Test Internal Supplier", represents_company="Wind Power LLC", diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index e998b842d13a..501ce5f967a3 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -957,6 +957,124 @@ def test_make_purchase_invoice_from_pr_with_returned_qty_duplicate_items(self): pr1.reload() pr1.cancel() +<<<<<<< HEAD +======= + def test_stock_transfer_from_purchase_receipt(self): + from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt + from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note + + prepare_data_for_internal_transfer() + + customer = "_Test Internal Customer 2" + company = "_Test Company with perpetual inventory" + + pr1 = make_purchase_receipt( + warehouse="Stores - TCP1", company="_Test Company with perpetual inventory" + ) + + dn1 = create_delivery_note( + item_code=pr1.items[0].item_code, + company=company, + customer=customer, + cost_center="Main - TCP1", + expense_account="Cost of Goods Sold - TCP1", + qty=5, + rate=500, + warehouse="Stores - TCP1", + target_warehouse="Work In Progress - TCP1", + ) + + pr = make_inter_company_purchase_receipt(dn1.name) + pr.items[0].from_warehouse = "Work In Progress - TCP1" + pr.items[0].warehouse = "Stores - TCP1" + pr.submit() + + gl_entries = get_gl_entries("Purchase Receipt", pr.name) + sl_entries = get_sl_entries("Purchase Receipt", pr.name) + + self.assertFalse(gl_entries) + + expected_sle = {"Work In Progress - TCP1": -5, "Stores - TCP1": 5} + + for sle in sl_entries: + self.assertEqual(expected_sle[sle.warehouse], sle.actual_qty) + + pr.cancel() + pr1.cancel() + + def test_stock_transfer_from_purchase_receipt_with_valuation(self): + from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt + from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note + + prepare_data_for_internal_transfer() + + create_warehouse( + "_Test Warehouse for Valuation", + company="_Test Company with perpetual inventory", + properties={"account": "_Test Account Stock In Hand - TCP1"}, + ) + + pr1 = make_purchase_receipt( + warehouse="Stores - TCP1", + company="_Test Company with perpetual inventory", + ) + + customer = "_Test Internal Customer 2" + company = "_Test Company with perpetual inventory" + + dn1 = create_delivery_note( + item_code=pr1.items[0].item_code, + company=company, + customer=customer, + cost_center="Main - TCP1", + expense_account="Cost of Goods Sold - TCP1", + qty=5, + rate=50, + warehouse="Stores - TCP1", + target_warehouse="_Test Warehouse for Valuation - TCP1", + ) + + pr = make_inter_company_purchase_receipt(dn1.name) + pr.items[0].from_warehouse = "_Test Warehouse for Valuation - TCP1" + pr.items[0].warehouse = "Stores - TCP1" + + pr.append( + "taxes", + { + "charge_type": "On Net Total", + "account_head": "_Test Account Shipping Charges - TCP1", + "category": "Valuation and Total", + "cost_center": "Main - TCP1", + "description": "Test", + "rate": 9, + }, + ) + + pr.submit() + + gl_entries = get_gl_entries("Purchase Receipt", pr.name) + sl_entries = get_sl_entries("Purchase Receipt", pr.name) + + expected_gle = [ + ["Stock In Hand - TCP1", 272.5, 0.0], + ["_Test Account Stock In Hand - TCP1", 0.0, 250.0], + ["_Test Account Shipping Charges - TCP1", 0.0, 22.5], + ] + + expected_sle = {"_Test Warehouse for Valuation - TCP1": -5, "Stores - TCP1": 5} + + for sle in sl_entries: + self.assertEqual(expected_sle[sle.warehouse], sle.actual_qty) + + for i, gle in enumerate(gl_entries): + self.assertEqual(gle.account, expected_gle[i][0]) + self.assertEqual(gle.debit, expected_gle[i][1]) + self.assertEqual(gle.credit, expected_gle[i][2]) + + pr.cancel() + pr1.cancel() + +>>>>>>> 72d32a4901 (chore: fixed test cases related to Internal Transfer (#37659)) def test_po_to_pi_and_po_to_pr_worflow_full(self): """Test following behaviour: - Create PO