From 8ee9a46d96a68f8b30af0dd33aa3b4bb49e7c5a2 Mon Sep 17 00:00:00 2001 From: Bhavan23 Date: Mon, 12 May 2025 12:48:27 +0530 Subject: [PATCH] test: add test case to validate inter-company transaction address links (cherry picked from commit 0caa757dd6cb92b583a39b585af5706b80532ad2) --- .../sales_invoice/test_sales_invoice.py | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index a1b42624592..5e9c799fb86 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2581,6 +2581,62 @@ class TestSalesInvoice(FrappeTestCase): acc_settings.book_deferred_entries_based_on = "Days" acc_settings.save() + def test_validate_inter_company_transaction_address_links(self): + def _validate_address_link(address, link_doctype, link_name): + return frappe.db.get_value( + "Dynamic Link", + { + "parent": address, + "parenttype": "Address", + "link_doctype": link_doctype, + "link_name": link_name, + }, + "parent", + ) + + si = create_sales_invoice( + company="Wind Power LLC", + customer="_Test Internal Customer", + debit_to="Debtors - WP", + warehouse="Stores - WP", + income_account="Sales - WP", + expense_account="Cost of Goods Sold - WP", + cost_center="Main - WP", + currency="USD", + do_not_save=1, + ) + + si.selling_price_list = "_Test Price List Rest of the World" + si.submit() + + target_doc = make_inter_company_transaction("Sales Invoice", si.name) + target_doc.items[0].update( + { + "expense_account": "Cost of Goods Sold - _TC1", + "cost_center": "Main - _TC1", + "warehouse": "Stores - _TC1", + } + ) + target_doc.save() + + if target_doc.doctype in ["Purchase Invoice", "Purchase Order"]: + for details in [ + ("supplier_address", "Supplier", target_doc.supplier), + ("dispatch_address", "Company", target_doc.company), + ("shipping_address", "Company", target_doc.company), + ("billing_address", "Company", target_doc.company), + ]: + if address := target_doc.get(details[0]): + self.assertEqual(address, _validate_address_link(address, details[1], details[2])) + else: + for details in [ + ("company_address", "Company", target_doc.company), + ("shipping_address_name", "Customer", target_doc.customer), + ("customer_address", "Customer", target_doc.customer), + ]: + if address := target_doc.get(details[0]): + self.assertEqual(address, _validate_address_link(address, details[1], details[2])) + def test_inter_company_transaction(self): si = create_sales_invoice( company="Wind Power LLC",