purchase_vehicle = BasicActivity("Purchase Vehicle", dt_account="Fixed Assets/Vehicle Asset", cr_account="Bank/Default", amount=177000, start=start_datetime, end=start_datetime + relativedelta(months=1), interval=1) ops.add_activity(purchase_vehicle) make_delivery_sale = BasicActivity("Make Delivery", dt_account="Bank/Default", cr_account="Sales/Sales Delivery", amount=15000, start=start_datetime, end=end_datetime, interval=1) ops.add_activity(make_delivery_sale) pay_delivery_costs = BasicActivity("Pay for Fuel", dt_account="Cost of Sales/Fuel", cr_account="Bank/Default", amount=1000, start=start_datetime, end=end_datetime, interval=1) ops.add_activity(pay_delivery_costs) pay_wages = BasicActivity("Pay Wages", dt_account="Expense/Wages", cr_account="Bank/Default", amount=10000, start=start_datetime, end=end_datetime, interval=1) hr.add_activity(pay_wages) # Run the model model.run() # Print the reports. #courier_company.gl.balance_sheet(format=ReportFormat.latex, output_path="balance_sheet.tex") #courier_company.gl.income_statement(format=ReportFormat.latex, output_path="income_statement.tex") courier_company.gl.transaction_list(component_path=ops.path) courier_company.gl.balance_sheet() courier_company.gl.income_statement(component_path=hr.path)
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)
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)