mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-18 12:39:18 +00:00
test: add new unit test for company validation in accounting dimension
(cherry picked from commit c94091d68f)
This commit is contained in:
@@ -17,6 +17,7 @@ from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make
|
|||||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||||
from erpnext.accounts.party import get_party_account
|
from erpnext.accounts.party import get_party_account
|
||||||
from erpnext.buying.doctype.purchase_order.test_purchase_order import prepare_data_for_internal_transfer
|
from erpnext.buying.doctype.purchase_order.test_purchase_order import prepare_data_for_internal_transfer
|
||||||
|
from erpnext.projects.doctype.project.test_project import make_project
|
||||||
from erpnext.stock.doctype.item.test_item import create_item
|
from erpnext.stock.doctype.item.test_item import create_item
|
||||||
|
|
||||||
|
|
||||||
@@ -1532,32 +1533,32 @@ class TestAccountsController(FrappeTestCase):
|
|||||||
|
|
||||||
# Invoices
|
# Invoices
|
||||||
si1 = self.create_sales_invoice(qty=1, rate=rate_in_account_currency, do_not_submit=True)
|
si1 = self.create_sales_invoice(qty=1, rate=rate_in_account_currency, do_not_submit=True)
|
||||||
si1.department = "Management"
|
si1.department = "Management - _TC"
|
||||||
si1.save().submit()
|
si1.save().submit()
|
||||||
|
|
||||||
si2 = self.create_sales_invoice(qty=1, rate=rate_in_account_currency, do_not_submit=True)
|
si2 = self.create_sales_invoice(qty=1, rate=rate_in_account_currency, do_not_submit=True)
|
||||||
si2.department = "Operations"
|
si2.department = "Operations - _TC"
|
||||||
si2.save().submit()
|
si2.save().submit()
|
||||||
|
|
||||||
# Payments
|
# Payments
|
||||||
cr_note1 = self.create_sales_invoice(qty=-1, conversion_rate=75, rate=1, do_not_save=True)
|
cr_note1 = self.create_sales_invoice(qty=-1, conversion_rate=75, rate=1, do_not_save=True)
|
||||||
cr_note1.department = "Management"
|
cr_note1.department = "Management - _TC"
|
||||||
cr_note1.is_return = 1
|
cr_note1.is_return = 1
|
||||||
cr_note1.save().submit()
|
cr_note1.save().submit()
|
||||||
|
|
||||||
cr_note2 = self.create_sales_invoice(qty=-1, conversion_rate=75, rate=1, do_not_save=True)
|
cr_note2 = self.create_sales_invoice(qty=-1, conversion_rate=75, rate=1, do_not_save=True)
|
||||||
cr_note2.department = "Legal"
|
cr_note2.department = "Legal - _TC"
|
||||||
cr_note2.is_return = 1
|
cr_note2.is_return = 1
|
||||||
cr_note2.save().submit()
|
cr_note2.save().submit()
|
||||||
|
|
||||||
pe1 = get_payment_entry(si1.doctype, si1.name)
|
pe1 = get_payment_entry(si1.doctype, si1.name)
|
||||||
pe1.references = []
|
pe1.references = []
|
||||||
pe1.department = "Research & Development"
|
pe1.department = "Research & Development - _TC"
|
||||||
pe1.save().submit()
|
pe1.save().submit()
|
||||||
|
|
||||||
pe2 = get_payment_entry(si1.doctype, si1.name)
|
pe2 = get_payment_entry(si1.doctype, si1.name)
|
||||||
pe2.references = []
|
pe2.references = []
|
||||||
pe2.department = "Management"
|
pe2.department = "Management - _TC"
|
||||||
pe2.save().submit()
|
pe2.save().submit()
|
||||||
|
|
||||||
je1 = self.create_journal_entry(
|
je1 = self.create_journal_entry(
|
||||||
@@ -1570,7 +1571,7 @@ class TestAccountsController(FrappeTestCase):
|
|||||||
)
|
)
|
||||||
je1.accounts[0].party_type = "Customer"
|
je1.accounts[0].party_type = "Customer"
|
||||||
je1.accounts[0].party = self.customer
|
je1.accounts[0].party = self.customer
|
||||||
je1.accounts[0].department = "Management"
|
je1.accounts[0].department = "Management - _TC"
|
||||||
je1.save().submit()
|
je1.save().submit()
|
||||||
|
|
||||||
# assert dimension filter's result
|
# assert dimension filter's result
|
||||||
@@ -1579,17 +1580,17 @@ class TestAccountsController(FrappeTestCase):
|
|||||||
self.assertEqual(len(pr.invoices), 2)
|
self.assertEqual(len(pr.invoices), 2)
|
||||||
self.assertEqual(len(pr.payments), 5)
|
self.assertEqual(len(pr.payments), 5)
|
||||||
|
|
||||||
pr.department = "Legal"
|
pr.department = "Legal - _TC"
|
||||||
pr.get_unreconciled_entries()
|
pr.get_unreconciled_entries()
|
||||||
self.assertEqual(len(pr.invoices), 0)
|
self.assertEqual(len(pr.invoices), 0)
|
||||||
self.assertEqual(len(pr.payments), 1)
|
self.assertEqual(len(pr.payments), 1)
|
||||||
|
|
||||||
pr.department = "Management"
|
pr.department = "Management - _TC"
|
||||||
pr.get_unreconciled_entries()
|
pr.get_unreconciled_entries()
|
||||||
self.assertEqual(len(pr.invoices), 1)
|
self.assertEqual(len(pr.invoices), 1)
|
||||||
self.assertEqual(len(pr.payments), 3)
|
self.assertEqual(len(pr.payments), 3)
|
||||||
|
|
||||||
pr.department = "Research & Development"
|
pr.department = "Research & Development - _TC"
|
||||||
pr.get_unreconciled_entries()
|
pr.get_unreconciled_entries()
|
||||||
self.assertEqual(len(pr.invoices), 0)
|
self.assertEqual(len(pr.invoices), 0)
|
||||||
self.assertEqual(len(pr.payments), 1)
|
self.assertEqual(len(pr.payments), 1)
|
||||||
@@ -1600,17 +1601,17 @@ class TestAccountsController(FrappeTestCase):
|
|||||||
|
|
||||||
# Invoice
|
# Invoice
|
||||||
si = self.create_sales_invoice(qty=1, rate=rate_in_account_currency, do_not_submit=True)
|
si = self.create_sales_invoice(qty=1, rate=rate_in_account_currency, do_not_submit=True)
|
||||||
si.department = "Management"
|
si.department = "Management - _TC"
|
||||||
si.save().submit()
|
si.save().submit()
|
||||||
|
|
||||||
# Payment
|
# Payment
|
||||||
cr_note = self.create_sales_invoice(qty=-1, conversion_rate=75, rate=1, do_not_save=True)
|
cr_note = self.create_sales_invoice(qty=-1, conversion_rate=75, rate=1, do_not_save=True)
|
||||||
cr_note.department = "Management"
|
cr_note.department = "Management - _TC"
|
||||||
cr_note.is_return = 1
|
cr_note.is_return = 1
|
||||||
cr_note.save().submit()
|
cr_note.save().submit()
|
||||||
|
|
||||||
pr = self.create_payment_reconciliation()
|
pr = self.create_payment_reconciliation()
|
||||||
pr.department = "Management"
|
pr.department = "Management - _TC"
|
||||||
pr.get_unreconciled_entries()
|
pr.get_unreconciled_entries()
|
||||||
self.assertEqual(len(pr.invoices), 1)
|
self.assertEqual(len(pr.invoices), 1)
|
||||||
self.assertEqual(len(pr.payments), 1)
|
self.assertEqual(len(pr.payments), 1)
|
||||||
@@ -1642,7 +1643,7 @@ class TestAccountsController(FrappeTestCase):
|
|||||||
# Sales Invoice in Foreign Currency
|
# Sales Invoice in Foreign Currency
|
||||||
self.setup_dimensions()
|
self.setup_dimensions()
|
||||||
rate_in_account_currency = 1
|
rate_in_account_currency = 1
|
||||||
dpt = "Research & Development"
|
dpt = "Research & Development - _TC"
|
||||||
|
|
||||||
si = self.create_sales_invoice(qty=1, rate=rate_in_account_currency, do_not_save=True)
|
si = self.create_sales_invoice(qty=1, rate=rate_in_account_currency, do_not_save=True)
|
||||||
si.department = dpt
|
si.department = dpt
|
||||||
@@ -1677,7 +1678,7 @@ class TestAccountsController(FrappeTestCase):
|
|||||||
|
|
||||||
def test_93_dimension_inheritance_on_advance(self):
|
def test_93_dimension_inheritance_on_advance(self):
|
||||||
self.setup_dimensions()
|
self.setup_dimensions()
|
||||||
dpt = "Research & Development"
|
dpt = "Research & Development - _TC"
|
||||||
|
|
||||||
adv = self.create_payment_entry(amount=1, source_exc_rate=85)
|
adv = self.create_payment_entry(amount=1, source_exc_rate=85)
|
||||||
adv.department = dpt
|
adv.department = dpt
|
||||||
@@ -2135,3 +2136,13 @@ class TestAccountsController(FrappeTestCase):
|
|||||||
journal_voucher = frappe.get_doc("Journal Entry", exc_je_for_pi[0].parent)
|
journal_voucher = frappe.get_doc("Journal Entry", exc_je_for_pi[0].parent)
|
||||||
purchase_invoice = frappe.get_doc("Purchase Invoice", pi.name)
|
purchase_invoice = frappe.get_doc("Purchase Invoice", pi.name)
|
||||||
self.assertEqual(purchase_invoice.advances[0].difference_posting_date, journal_voucher.posting_date)
|
self.assertEqual(purchase_invoice.advances[0].difference_posting_date, journal_voucher.posting_date)
|
||||||
|
|
||||||
|
def test_company_validation_in_dimension(self):
|
||||||
|
si = create_sales_invoice(do_not_submit=True)
|
||||||
|
project = make_project({"project_name": "_Test Demo Project1", "company": "_Test Company 1"})
|
||||||
|
si.project = project.name
|
||||||
|
self.assertRaises(frappe.ValidationError, si.save)
|
||||||
|
|
||||||
|
si_1 = create_sales_invoice(do_not_submit=True)
|
||||||
|
si_1.items[0].project = project.name
|
||||||
|
self.assertRaises(frappe.ValidationError, si_1.save)
|
||||||
|
|||||||
Reference in New Issue
Block a user