示例#1
0
 def setUp(self):
     self.object = GeneralLedgerStructure("NameA",
                                          description="DescriptionA")
示例#2
0
class GeneralLedgerStructureUnitTester(unittest.TestCase):
    """
      Tester for the auxi.modelling.financial.des.generalledgerstructure class.
    """

    def setUp(self):
        self.object = GeneralLedgerStructure("NameA",
                                             description="DescriptionA")

    def test_constructor(self):
        """
        Test the the variables has been initialised and that the default
        accounts has been created.
        """
        self.assertEqual(self.object.name, "NameA")
        self.assertEqual(self.object.description, "DescriptionA")
        self.assertNotEqual(self.object["Bank"], None)
        self.assertEqual(
            self.object['Unallocated Income Statement'].account_type,
            AccountType.revenue)
        self.assertEqual(self.object["Sales"].number, "I10")
        self.assertEqual(
            self.object["Sales"].account_type,
            AccountType.revenue)
        self.assertEqual(self.object["Cost of Sales"].number, "I15")
        self.assertEqual(
            self.object["Cost of Sales"].account_type,
            AccountType.expense)
        self.assertEqual(self.object["Other Income"].number, "I20")
        self.assertEqual(
            self.object["Other Income"].account_type,
            AccountType.revenue)
        self.assertEqual(self.object["Expense"].number, "I25")
        self.assertEqual(
            self.object["Expense"].account_type,
            AccountType.expense)
        self.assertEqual(self.object["Tax"].number, "I30")
        self.assertEqual(
            self.object["Tax"].account_type,
            AccountType.expense)
        self.assertEqual(self.object["Dividends"].number, "I35")
        self.assertEqual(
            self.object["Dividends"].account_type,
            AccountType.expense)
        self.assertEqual(self.object["Share Capital"].number, "B10")
        self.assertEqual(
            self.object["Share Capital"].account_type,
            AccountType.asset)
        self.assertEqual(self.object["Retained Income"].number, "B15")
        self.assertEqual(
            self.object["Retained Income"].account_type,
            AccountType.equity)
        self.assertEqual(self.object["Shareholders Loan"].number, "B20")
        self.assertEqual(
            self.object["Shareholders Loan"].account_type,
            AccountType.liability)
        self.assertEqual(self.object["Long Term Borrowing"].number, "B25")
        self.assertEqual(
            self.object["Long Term Borrowing"].account_type,
            AccountType.liability)
        self.assertEqual(
            self.object["Other Long Term Liabilities"].number,
            "B30")
        self.assertEqual(
            self.object["Other Long Term Liabilities"].account_type,
            AccountType.liability)
        self.assertEqual(self.object["Fixed Assets"].number, "B35")
        self.assertEqual(
            self.object["Fixed Assets"].account_type,
            AccountType.asset)
        self.assertEqual(self.object["Investments"].number, "B40")
        self.assertEqual(
            self.object["Investments"].account_type,
            AccountType.asset)
        self.assertEqual(self.object["Other Fixed Assets"].number, "B45")
        self.assertEqual(
            self.object["Other Fixed Assets"].account_type,
            AccountType.asset)
        self.assertEqual(self.object["Inventory"].number, "B50")
        self.assertEqual(
            self.object["Inventory"].account_type,
            AccountType.asset)
        self.assertEqual(self.object["Accounts Receivable"].number, "B55")
        self.assertEqual(
            self.object["Accounts Receivable"].account_type,
            AccountType.asset)
        self.assertEqual(self.object["Bank"].number, "B60")
        self.assertEqual(
            self.object["Bank"].account_type,
            AccountType.asset)
        self.assertEqual(self.object["Bank"]["Default"].number, "0000")
        self.assertEqual(
            self.object["Bank"]["Default"].account_type,
            AccountType.asset)
        self.assertEqual(self.object["Other Current Assets"].number, "B65")
        self.assertEqual(
            self.object["Other Current Assets"].account_type,
            AccountType.asset)
        self.assertEqual(self.object["Account Payable"].number, "B70")
        self.assertEqual(
            self.object["Account Payable"].account_type,
            AccountType.liability)
        self.assertEqual(self.object["Taxation"].number, "B75")
        self.assertEqual(
            self.object["Taxation"].account_type,
            AccountType.liability)
        self.assertEqual(
            self.object["Other Current Liabilities"].number,
            "B80")
        self.assertEqual(
            self.object["Other Current Liabilities"].account_type,
            AccountType.liability)

        self.assertEqual(
            self.object['Unallocated Income Statement']["Gross Profit"].number,
            "0000")
        self.assertEqual(
            self.object['Unallocated Income Statement']
            ["Gross Profit"].account_type,
            AccountType.revenue)
        self.assertEqual(
            self.object['Unallocated Income Statement']
            ["Income Summary"].number,
            "0010")
        self.assertEqual(
            self.object['Unallocated Income Statement']
            ["Income Summary"].account_type,
            AccountType.revenue)
        self.assertEqual(
            self.object['Retained Income']
            ["Retained Earnings"].number,
            "0000")
        self.assertEqual(
            self.object['Retained Income']
            ["Retained Earnings"].account_type,
            AccountType.equity)
        self.assertEqual(
            self.object['Tax']
            ["Income Tax Expense"].number,
            "0000")
        self.assertEqual(
            self.object['Tax']
            ["Income Tax Expense"].account_type,
            AccountType.expense)

        self.assertEqual(self.object.tax_payment_account, "Bank/Default")

    def test_get_account(self):
        self.object["Retained Income"].create_account(
            "TestA",
            number="010")
        acc = self.object["Bank"].create_account(
            "TestB",
            number="020")
        sub_acc = acc.create_account(
            "TestB1",
            description="TestB1_Desc",
            number="010")
        sub_acc.create_account(
            "TestB1.1",
            description="TestB1.1_Desc",
            number="010")
        orig = sub_acc.create_account(
            "TestB1.2",
            description="TestB1.1_Desc",
            number="011")
        result = self.object.get_account("Bank/TestB/TestB1/TestB1.2")

        self.assertEqual(result.name, orig.name)
        self.assertEqual(result.description, orig.description)
        self.assertEqual(result.number, orig.number)

    def test_get_account_decendants(self):
        # Set up this test.
        self.sales_fish_acc = self.object["Sales"].create_account(
            "SalesFish",
            description="Sales of Fish",
            number="010")
        self.sales_barracuda_acc = self.sales_fish_acc.create_account(
            "SalesBarracuda",
            description="Sales of Barracudas",
            number="010")
        self.sales_nemo_acc = self.sales_fish_acc.create_account(
            "SalesNemo",
            description="Sales of Nemos",
            number="020")
        # perform the test.
        result = self.object.get_account_decendants(self.object["Sales"])
        self.assertEqual(len(result), 3)
        self.assertEqual(result[0], self.sales_fish_acc)
        self.assertEqual(result[1], self.sales_barracuda_acc)
        self.assertEqual(result[2], self.sales_nemo_acc)

    def test_validate_account_name_valid(self):
        self.object.validate_account_names(
            ["Bank/Default", "Retained Income/Retained Earnings"])

    def test_validate_account_name_invalid(self):
        self.assertRaises(
            ValueError,
            self.object.validate_account_names,
            ["invalid_acc_name_a", "invalid_acc_name_b"])

    def test_report(self):
        report = self.object.report(ReportFormat.string)
        line1 = report.split("\n")[0]
        self.assertEqual(line1.replace(" ", ""), "TypeNumberNameDescription")