diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 5f3b398fdfd..ca3091fb79a 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -3096,6 +3096,84 @@ class TestSalesInvoice(FrappeTestCase): party_link.delete() frappe.db.set_single_value("Accounts Settings", "enable_common_party_accounting", 0) + def test_sales_invoice_against_supplier_usd_with_dimensions(self): + from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import ( + make_customer, + ) + from erpnext.accounts.doctype.party_link.party_link import create_party_link + from erpnext.buying.doctype.supplier.test_supplier import create_supplier + + # create a customer + customer = make_customer(customer="_Test Common Supplier USD") + cust_doc = frappe.get_doc("Customer", customer) + cust_doc.default_currency = "USD" + cust_doc.save() + # create a supplier + supplier = create_supplier(supplier_name="_Test Common Supplier USD").name + supp_doc = frappe.get_doc("Supplier", supplier) + supp_doc.default_currency = "USD" + supp_doc.save() + + # create a party link between customer & supplier + party_link = create_party_link("Supplier", supplier, customer) + + # enable common party accounting + frappe.db.set_single_value("Accounts Settings", "enable_common_party_accounting", 1) + + # create a dimension and make it mandatory + if not frappe.get_all("Accounting Dimension", filters={"document_type": "Department"}): + dim = frappe.get_doc( + { + "doctype": "Accounting Dimension", + "document_type": "Department", + "dimension_defaults": [{"company": "_Test Company", "mandatory_for_bs": True}], + } + ) + dim.save() + else: + dim = frappe.get_doc( + "Accounting Dimension", + frappe.get_all("Accounting Dimension", filters={"document_type": "Department"})[0], + ) + dim.disabled = False + dim.dimension_defaults = [] + dim.append("dimension_defaults", {"company": "_Test Company", "mandatory_for_bs": True}) + dim.save() + + # create a sales invoice + si = create_sales_invoice( + customer=customer, parent_cost_center="_Test Cost Center - _TC", do_not_submit=True + ) + si.department = "All Departments" + si.save().submit() + + # check outstanding of sales invoice + si.reload() + self.assertEqual(si.status, "Paid") + self.assertEqual(flt(si.outstanding_amount), 0.0) + + # check creation of journal entry + jv = frappe.get_all( + "Journal Entry Account", + { + "account": si.debit_to, + "party_type": "Customer", + "party": si.customer, + "reference_type": si.doctype, + "reference_name": si.name, + "department": "All Departments", + }, + pluck="credit_in_account_currency", + ) + + self.assertTrue(jv) + self.assertEqual(jv[0], si.grand_total) + + dim.disabled = True + dim.save() + party_link.delete() + frappe.db.set_single_value("Accounts Settings", "enable_common_party_accounting", 0) + def test_payment_statuses(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry