<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry

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()

	def test_dimension_against_sales_invoice(self):
		si = create_sales_invoice(do_not_save=1)
		si.append("items", {
			"item_code": "_Test Item",
			"warehouse": "_Test Warehouse - _TC",
			"qty": 1,
			"rate": 100,
			"income_account": "Sales - _TC",
			"expense_account": "Cost of Goods Sold - _TC",
			"cost_center": "_Test Cost Center - _TC",
			"department": "_Test Department - _TC"
		})

		si.save()
		si.submit()

		gle = frappe.get_doc("GL Entry", {"voucher_no": si.name, "account": "Sales - _TC"})

		self.assertEqual(gle.department, "_Test Department - _TC")

	def test_dimension_against_journal_entry(self):
		je = make_journal_entry("Sales - _TC", "Sales Expenses - _TC", 500, save=False)
		je.accounts[0].update({"department": "_Test Department - _TC"})
		je.accounts[1].update({"department": "_Test Department - _TC"})

		je.save()
		je.submit()

		gle = frappe.get_doc("GL Entry", {"voucher_no": je.name, "account": "Sales - _TC"})
		gle1 = frappe.get_doc("GL Entry", {"voucher_no": je.name, "account": "Sales Expenses - _TC"})
		self.assertEqual(gle.department, "_Test Department - _TC")
		self.assertEqual(gle1.department, "_Test Department - _TC")


<commit_msg>fix: Updated test cases for accounting dimensions<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry

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()

			dimension1 = frappe.get_doc({
				"doctype": "Accounting Dimension",
				"document_type": "Location",
				"mandatory_for_pl": 1
			}).insert()

	def tearDown(self):
		delete_dimension()

	def test_dimension_against_sales_invoice(self):
		si = create_sales_invoice(do_not_save=1)
		si.append("items", {
			"item_code": "_Test Item",
			"warehouse": "_Test Warehouse - _TC",
			"qty": 1,
			"rate": 100,
			"income_account": "Sales - _TC",
			"expense_account": "Cost of Goods Sold - _TC",
			"cost_center": "_Test Cost Center - _TC",
			"department": "_Test Department - _TC"
		})

		si.save()
		si.submit()

		gle = frappe.get_doc("GL Entry", {"voucher_no": si.name, "account": "Sales - _TC"})

		self.assertEqual(gle.department, "_Test Department - _TC")

	def test_dimension_against_journal_entry(self):
		je = make_journal_entry("Sales - _TC", "Sales Expenses - _TC", 500, save=False)
		je.accounts[0].update({"department": "_Test Department - _TC"})
		je.accounts[1].update({"department": "_Test Department - _TC"})

		je.save()
		je.submit()

		gle = frappe.get_doc("GL Entry", {"voucher_no": je.name, "account": "Sales - _TC"})
		gle1 = frappe.get_doc("GL Entry", {"voucher_no": je.name, "account": "Sales Expenses - _TC"})
		self.assertEqual(gle.department, "_Test Department - _TC")
		self.assertEqual(gle1.department, "_Test Department - _TC")

	def test_mandatory(self):
		si = create_sales_invoice(do_not_save=1)
		si.append("items", {
			"item_code": "_Test Item",
			"warehouse": "_Test Warehouse - _TC",
			"qty": 1,
			"rate": 100,
			"income_account": "Sales - _TC",
			"expense_account": "Cost of Goods Sold - _TC",
			"cost_center": "_Test Cost Center - _TC",
			"location": ""
		})

		si.save()
		self.assertRaises(frappe.ValidationError, si.submit())


def delete_dimension():
	dimension1 = frappe.delete_doc("Accounting Diemnsion", "Department")
	dimension2 = frappe.delete_doc("Accounting Diemnsion", "Location")


{'fraction_non_alphanumeric': 0.15012106537530268, 'fraction_numerical': 0.009465111160026414, 'mean_word_length': 4.803320561941252, 'pattern_counts': {'":': 49, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3022607', 'n_tokens_mistral': 1805, 'n_tokens_neox': 1566, 'n_words': 347}