fix: Add test case
This commit is contained in:
parent
d82c0f3bea
commit
4bd52b4842
@ -11,37 +11,7 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import d
|
||||
|
||||
class TestAccountingDimension(unittest.TestCase):
|
||||
def setUp(self):
|
||||
frappe.set_user("Administrator")
|
||||
|
||||
if not frappe.db.exists("Accounting Dimension", {"document_type": "Department"}):
|
||||
dimension = frappe.get_doc({
|
||||
"doctype": "Accounting Dimension",
|
||||
"document_type": "Department",
|
||||
}).insert()
|
||||
else:
|
||||
dimension1 = frappe.get_doc("Accounting Dimension", "Department")
|
||||
dimension1.disabled = 0
|
||||
dimension1.save()
|
||||
|
||||
if not frappe.db.exists("Accounting Dimension", {"document_type": "Location"}):
|
||||
dimension1 = frappe.get_doc({
|
||||
"doctype": "Accounting Dimension",
|
||||
"document_type": "Location",
|
||||
})
|
||||
|
||||
dimension1.append("dimension_defaults", {
|
||||
"company": "_Test Company",
|
||||
"reference_document": "Location",
|
||||
"default_dimension": "Block 1",
|
||||
"mandatory_for_bs": 1
|
||||
})
|
||||
|
||||
dimension1.insert()
|
||||
dimension1.save()
|
||||
else:
|
||||
dimension1 = frappe.get_doc("Accounting Dimension", "Location")
|
||||
dimension1.disabled = 0
|
||||
dimension1.save()
|
||||
create_dimension()
|
||||
|
||||
def test_dimension_against_sales_invoice(self):
|
||||
si = create_sales_invoice(do_not_save=1)
|
||||
@ -101,6 +71,38 @@ class TestAccountingDimension(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
disable_dimension()
|
||||
|
||||
def create_dimension():
|
||||
frappe.set_user("Administrator")
|
||||
|
||||
if not frappe.db.exists("Accounting Dimension", {"document_type": "Department"}):
|
||||
dimension = frappe.get_doc({
|
||||
"doctype": "Accounting Dimension",
|
||||
"document_type": "Department",
|
||||
}).insert()
|
||||
else:
|
||||
dimension1 = frappe.get_doc("Accounting Dimension", "Department")
|
||||
dimension1.disabled = 0
|
||||
dimension1.save()
|
||||
|
||||
if not frappe.db.exists("Accounting Dimension", {"document_type": "Location"}):
|
||||
dimension1 = frappe.get_doc({
|
||||
"doctype": "Accounting Dimension",
|
||||
"document_type": "Location",
|
||||
})
|
||||
|
||||
dimension1.append("dimension_defaults", {
|
||||
"company": "_Test Company",
|
||||
"reference_document": "Location",
|
||||
"default_dimension": "Block 1",
|
||||
"mandatory_for_bs": 1
|
||||
})
|
||||
|
||||
dimension1.insert()
|
||||
dimension1.save()
|
||||
else:
|
||||
dimension1 = frappe.get_doc("Accounting Dimension", "Location")
|
||||
dimension1.disabled = 0
|
||||
dimension1.save()
|
||||
|
||||
def disable_dimension():
|
||||
dimension1 = frappe.get_doc("Accounting Dimension", "Department")
|
||||
|
@ -32,23 +32,21 @@ def get_dimension_filter_map():
|
||||
filters = frappe.db.sql(
|
||||
""" SELECT
|
||||
a.applicable_on_account, d.dimension_value, p.accounting_dimension,
|
||||
p.allow_or_restrict, ad.fieldname, a.is_mandatory
|
||||
p.allow_or_restrict, a.is_mandatory
|
||||
FROM
|
||||
`tabApplicable On Account` a, `tabAllowed Dimension` d,
|
||||
`tabAccounting Dimension Filter` p, `tabAccounting Dimension` ad
|
||||
`tabAccounting Dimension Filter` p
|
||||
WHERE
|
||||
p.name = a.parent
|
||||
AND p.disabled = 0
|
||||
AND p.name = d.parent
|
||||
AND (p.accounting_dimension = ad.name
|
||||
OR p.accounting_dimension in ('Cost Center', 'Project'))
|
||||
|
||||
""", as_dict=1)
|
||||
|
||||
dimension_filter_map = {}
|
||||
|
||||
for f in filters:
|
||||
if f.accounting_dimension in ('Cost Center', 'Project'):
|
||||
f.fieldname = scrub(f.accounting_dimension)
|
||||
f.fieldname = scrub(f.accounting_dimension)
|
||||
|
||||
build_map(dimension_filter_map, f.fieldname, f.applicable_on_account, f.dimension_value,
|
||||
f.allow_or_restrict, f.is_mandatory)
|
||||
|
@ -3,8 +3,79 @@
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# import frappe
|
||||
import frappe
|
||||
import unittest
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import create_dimension
|
||||
|
||||
class TestAccountingDimensionFilter(unittest.TestCase):
|
||||
pass
|
||||
def setUp(self):
|
||||
create_accounting_dimension_filter()
|
||||
|
||||
def test_allowed_dimension_validation(self):
|
||||
si = create_sales_invoice(do_not_save=1)
|
||||
si.items[0].cost_center = 'Main - _TC'
|
||||
si.save()
|
||||
|
||||
self.assertRaises(frappe.ValidationError, si.submit)
|
||||
|
||||
def test_mandatory_dimension_validation(self):
|
||||
si = create_sales_invoice(do_not_save=1)
|
||||
si.items[0].location = ''
|
||||
si.save()
|
||||
|
||||
self.assertRaises(frappe.ValidationError, si.submit)
|
||||
|
||||
def tearDown(self):
|
||||
disable_dimension_filter()
|
||||
|
||||
def create_accounting_dimension_filter():
|
||||
if not frappe.db.get_value('Accounting Dimension Filter',
|
||||
{'accounting_dimension': 'Cost Center'}):
|
||||
frappe.get_doc({
|
||||
'doctype': 'Accounting Dimension Filter',
|
||||
'accounting_dimension': 'Cost Center',
|
||||
'allow_or_restrict': 'Allow',
|
||||
'company': '_Test Company',
|
||||
'accounts': [{
|
||||
'applicable_on_account': 'Sales - _TC',
|
||||
}],
|
||||
'dimensions': [{
|
||||
'accounting_dimension': 'Cost Center',
|
||||
'dimension_value': '_Test Cost Center 3 - _TC'
|
||||
}]
|
||||
}).insert()
|
||||
else:
|
||||
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Cost Center'})
|
||||
doc.disabled = 0
|
||||
doc.save()
|
||||
|
||||
if not frappe.db.get_value('Accounting Dimension Filter',
|
||||
{'accounting_dimension': 'Location'}):
|
||||
frappe.get_doc({
|
||||
'doctype': 'Accounting Dimension Filter',
|
||||
'accounting_dimension': 'Location',
|
||||
'allow_or_restrict': 'Allow',
|
||||
'company': '_Test Company',
|
||||
'accounts': [{
|
||||
'applicable_on_account': 'Sales - _TC',
|
||||
'is_mandatory': 1
|
||||
}],
|
||||
'dimensions': [{
|
||||
'accounting_dimension': 'Location',
|
||||
'dimension_value': 'Block 1'
|
||||
}]
|
||||
}).insert()
|
||||
else:
|
||||
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Location'})
|
||||
doc.disabled = 0
|
||||
doc.save()
|
||||
|
||||
def disable_dimension_filter():
|
||||
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Cost Center'})
|
||||
doc.disabled = 0
|
||||
doc.save()
|
||||
|
||||
doc = frappe.get_doc('Accounting Dimension Filter', {'accounting_dimension': 'Location'})
|
||||
doc.disabled = 0
|
||||
doc.save()
|
||||
|
Loading…
x
Reference in New Issue
Block a user