Example #1
0
 def setUp(self):
     self.object = TimeBasedModel("TimeBasedModelA",
                                  description="TimeBasedModel A",
                                  start_datetime=datetime(2016, 2, 1),
                                  period_duration=TimePeriod.day,
                                  period_count=200)
     # Set up the needed objects
     self.gl_structure = GeneralLedgerStructure(
         "NameA",
         description="DescriptionA")
     entity = self.object.create_entity(
         "EntityA",
         self.gl_structure,
         description="DescriptionA")
     # Set up the needed objects
     comp1 = entity.create_component("ComponentA1", description="ca1")
     basic_activity = BasicActivity("BasicActivityA",
                                    description="DescriptionA",
                                    dt_account="Bank",
                                    cr_account="Sales",
                                    amount=5000,
                                    start=datetime(2016, 2, 1),
                                    end=datetime(2016, 2, 14),
                                    interval=1)
     comp1.activities.append(basic_activity)
Example #2
0
 def setUp(self):
     self.object = TimeBasedModel("TimeBasedModelA",
                                  description="TimeBasedModel A",
                                  start_datetime=datetime(2016, 2, 1),
                                  period_duration=TimePeriod.day,
                                  period_count=200)
     # Set up the needed objects
     self.gl_structure = GeneralLedgerStructure("NameA",
                                                description="DescriptionA")
     entity = self.object.create_entity("EntityA",
                                        self.gl_structure,
                                        description="DescriptionA")
     # Set up the needed objects
     comp1 = entity.create_component("ComponentA1", description="ca1")
     basic_activity = BasicActivity("BasicActivityA",
                                    description="DescriptionA",
                                    dt_account="Bank",
                                    cr_account="Sales",
                                    amount=5000,
                                    start=datetime(2016, 2, 1),
                                    end=datetime(2016, 2, 14),
                                    interval=1)
     comp1.activities.append(basic_activity)
Example #3
0
class TimeBasedModelUnitTester(unittest.TestCase):
    """
    Tester for the auxi.modelling.business.models.TimeBasedModel class.
    """

    def setUp(self):
        self.object = TimeBasedModel("TimeBasedModelA",
                                     description="TimeBasedModel A",
                                     start_datetime=datetime(2016, 2, 1),
                                     period_duration=TimePeriod.day,
                                     period_count=200)
        # Set up the needed objects
        self.gl_structure = GeneralLedgerStructure(
            "NameA",
            description="DescriptionA")
        entity = self.object.create_entity(
            "EntityA",
            self.gl_structure,
            description="DescriptionA")
        # Set up the needed objects
        comp1 = entity.create_component("ComponentA1", description="ca1")
        basic_activity = BasicActivity("BasicActivityA",
                                       description="DescriptionA",
                                       dt_account="Bank",
                                       cr_account="Sales",
                                       amount=5000,
                                       start=datetime(2016, 2, 1),
                                       end=datetime(2016, 2, 14),
                                       interval=1)
        comp1.activities.append(basic_activity)

    def test_constructor(self):
        self.assertEqual(self.object.name, "TimeBasedModelA")
        self.assertEqual(self.object.description, "TimeBasedModel A")
        self.assertEqual(self.object.clock.start_datetime,
                         datetime(2016, 2, 1))
        self.assertEqual(self.object.clock.timestep_period_duration,
                         TimePeriod.day)
        self.assertEqual(self.object.period_count, 200)

    def test_set_name(self):
        """
        Test wether the name changes when it is set, that the model's path is
        updated and that the model's children's paths are updated correctly.
        """
        self.object.name = "NameAt"
        self.assertEqual(self.object.name, "NameAt")
        self.assertEqual(
            self.object.entities[0].components[0].path,
            "NameAt/EntityA/ComponentA1")
        self.assertEqual(
            self.object.entities[0].components[0].activities[0].path,
            "NameAt/EntityA/ComponentA1/BasicActivityA")

    def test_create_entity(self):
        new_entity = self.object.create_entity(
            "EntityTestCreate",
            self.gl_structure,
            description="ec")
        self.assertEqual(new_entity.name, "EntityTestCreate")
        self.assertEqual(new_entity.description, "ec")

        self.assertEqual(new_entity, self.object.entities[1])

    def test_remove_entity(self):
        self.object.create_entity(
            "EntityTestRemove",
            self.gl_structure,
            description="er")
        self.object.remove_entity("EntityTestRemove")
        self.assertEqual(len(self.object.entities), 1)

    def test_prepare_to_run(self):
        """
        Test that the model's entities prepare_to_run is called when the
        model's prepare_to_run is called.
        """
        self.object.prepare_to_run()
        self.assertEqual(
            self.object.entities[0].components[0].activities[0].end_period_ix,
            14)

    def test_run(self):
        """
        Test that the model's entities run is called when the
        model's run is called. Also test that the model was run for the
        expected timeperiod.
        """
        self.object.run()
        # Test that the business entity has run for 13 days only
        # (as configured).
        self.assertEqual(len(self.object.entities[0].gl.transactions), 13)
Example #4
0
# Create general ledger structure and accounts.
gl_structure = GeneralLedgerStructure("Courier GL Structure")

gl_structure["Long Term Borrowing"].create_account("Loan", "0000")
gl_structure["Expense"].create_account("Interest Expense", "0000")
gl_structure["Fixed Assets"].create_account("Vehicle Asset", "0000")
gl_structure["Sales"].create_account("Sales Delivery", "0000")
gl_structure["Cost of Sales"].create_account("Fuel", "0000")
gl_structure["Expense"].create_account("Wages", "0000")

# Create the business model, entity and components.
start_datetime = datetime(2016, 2, 1)
end_datetime = datetime(2021, 1, 1)

model = TimeBasedModel("Business Model", start_datetime=start_datetime,
                       period_duration=TimePeriod.month, period_count=61)

courier_company = model.create_entity("CourierZA", gl_structure=gl_structure)
ops = courier_company.create_component("Operations")
hr = courier_company.create_component("HR")

# Create activities
loan = BasicLoanActivity("Loan",
    bank_account="Bank/Default", loan_account="Long Term Borrowing/Loan",
    interest_account="Expense/Interest Expense",
    amount=200000, interest_rate=0.15, start=start_datetime, duration=36,
    interval=1)
ops.add_activity(loan)

purchase_vehicle = BasicActivity("Purchase Vehicle",
    dt_account="Fixed Assets/Vehicle Asset", cr_account="Bank/Default",
Example #5
0
class TimeBasedModelUnitTester(unittest.TestCase):
    """
    Tester for the auxi.modelling.business.models.TimeBasedModel class.
    """
    def setUp(self):
        self.object = TimeBasedModel("TimeBasedModelA",
                                     description="TimeBasedModel A",
                                     start_datetime=datetime(2016, 2, 1),
                                     period_duration=TimePeriod.day,
                                     period_count=200)
        # Set up the needed objects
        self.gl_structure = GeneralLedgerStructure("NameA",
                                                   description="DescriptionA")
        entity = self.object.create_entity("EntityA",
                                           self.gl_structure,
                                           description="DescriptionA")
        # Set up the needed objects
        comp1 = entity.create_component("ComponentA1", description="ca1")
        basic_activity = BasicActivity("BasicActivityA",
                                       description="DescriptionA",
                                       dt_account="Bank",
                                       cr_account="Sales",
                                       amount=5000,
                                       start=datetime(2016, 2, 1),
                                       end=datetime(2016, 2, 14),
                                       interval=1)
        comp1.activities.append(basic_activity)

    def test_constructor(self):
        self.assertEqual(self.object.name, "TimeBasedModelA")
        self.assertEqual(self.object.description, "TimeBasedModel A")
        self.assertEqual(self.object.clock.start_datetime,
                         datetime(2016, 2, 1))
        self.assertEqual(self.object.clock.timestep_period_duration,
                         TimePeriod.day)
        self.assertEqual(self.object.period_count, 200)

    def test_set_name(self):
        """
        Test whether the name changes when it is set, that the model's path is
        updated and that the model's children's paths are updated correctly.
        """
        self.object.name = "NameAt"
        self.assertEqual(self.object.name, "NameAt")
        self.assertEqual(self.object.entities[0].components[0].path,
                         "NameAt/EntityA/ComponentA1")
        self.assertEqual(
            self.object.entities[0].components[0].activities[0].path,
            "NameAt/EntityA/ComponentA1/BasicActivityA")

    def test_create_entity(self):
        new_entity = self.object.create_entity("EntityTestCreate",
                                               self.gl_structure,
                                               description="ec")
        self.assertEqual(new_entity.name, "EntityTestCreate")
        self.assertEqual(new_entity.description, "ec")

        self.assertEqual(new_entity, self.object.entities[1])

    def test_remove_entity(self):
        self.object.create_entity("EntityTestRemove",
                                  self.gl_structure,
                                  description="er")
        self.object.remove_entity("EntityTestRemove")
        self.assertEqual(len(self.object.entities), 1)

    def test_prepare_to_run(self):
        """
        Test that the model's entities prepare_to_run is called when the
        model's prepare_to_run is called.
        """
        self.object.prepare_to_run()
        self.assertEqual(
            self.object.entities[0].components[0].activities[0].end_period_ix,
            14)

    def test_run(self):
        """
        Test that the model's entities run is called when the
        model's run is called. Also test that the model was run for the
        expected time period.
        """
        self.object.run()
        # Test that the business entity has run for 13 days only
        # (as configured).
        self.assertEqual(len(self.object.entities[0].gl.transactions), 13)