def test_create_object_single_sale_passes(self):

        test_dump = 'value\tdate\ttype\tgst_total\t[10-0100]\r\n3054.6\tJan. 23, 2016\tSale\t277.69\t2776.91'  # noqa

        test_create_object = convert_import_to_objects(test_dump,
                                                       user=self.user,
                                                       object_name='Sale')

        test_transaction = Transaction.objects.get(
            value=utils.make_decimal('3054.6'),
            date=dateparser.parse('23-Jan-2016'),
            source='subledgers.sales.models.Sale',
            user=self.user)

        test_lines = [
            Line.objects.get(transaction=test_transaction,
                             account=self.SALES_CLEARING_ACCOUNT,
                             value=utils.set_DR('3054.6')),
            Line.objects.get(transaction=test_transaction,
                             account=self.a1,
                             value=utils.set_CR('2776.91')),
            Line.objects.get(transaction=test_transaction,
                             account=self.account_DR_GST,
                             value=utils.set_CR('277.69')),
        ]
        test_result = [Sale.objects.get(transaction=test_transaction, )]

        self.assertEqual(test_create_object, test_result)
        self.assertEqual(set(list(test_result[0].transaction.lines.all())),
                         set(test_lines))
    def test_create_object_single_expense_no_entity_passes(self):

        test_dump = 'value\tdate\tnote\ttype\trelation\tgst_total\t[15-1420]\t[15-0715]\t[15-0605]\t[15-0150]\t[15-0500]\t[15-0650]\t[15-0705]\t[15-0710]\t[15-1010]\t[15-1400]\t[15-1430]\t[15-0620]\t[15-1470]\r\n53.47\t11-Dec-2015\t7-ELEVEN 2296 ERINDALE CENT\tExpense\t\t4.86\t\t\t\t48.61\t\t\t\t\t\t\t\t\t'  # noqa

        test_create_object = convert_import_to_objects(test_dump,
                                                       user=self.user,
                                                       object_name='Expense')

        # `.get(..` MUST BE BELOW `test_create_object`
        # get the objects that look exactly correct
        test_transaction = Transaction.objects.get(
            value=utils.make_decimal('53.47'),
            date=dateparser.parse('11-Dec-2015'),
            source='subledgers.expenses.models.Expense',
            note='7-ELEVEN 2296 ERINDALE CENT',
            user=self.user)
        test_lines = [
            Line.objects.get(transaction=test_transaction,
                             account=self.a1,
                             value=utils.set_DR('48.61')),
            Line.objects.get(transaction=test_transaction,
                             account=self.EXPENSE_CLEARING_ACCOUNT,
                             value=utils.set_CR('53.47')),
            Line.objects.get(transaction=test_transaction,
                             account=self.account_CR_GST,
                             value=utils.set_DR('4.86')),
        ]
        test_result = [Expense.objects.get(transaction=test_transaction, )]

        self.assertEqual(test_create_object, test_result)
        self.assertEqual(set(list(test_result[0].transaction.lines.all())),
                         set(test_lines))
    def test_create_object_single_journalentry_passes(self):

        test_dump = 'value\tdate\ttype\t[03-0450]\t[03-0709]\t[15-1905]\t[15-1903]\t[15-1910]\t[15-1901]\t[15-1900]\t[03-0600]\t[15-1950]\r\n23,017.03\tJan. 31, 2016\tJournalEntry\t-17,817.96\t-3,447.00\t2,385.02\t6,991.98\t730.77\t8,255.34\t2,901.85\t-1,752.07\t1,752.07'  # noqa

        test_create_object = convert_import_to_objects(
            test_dump, user=self.user, object_name='JournalEntry')

        test_transaction = Transaction.objects.get(
            value=utils.make_decimal('23017.03'),
            date=dateparser.parse('31-Jan-2016'),
            source='subledgers.journals.models.JournalEntry',
            user=self.user)
        test_lines = [
            Line.objects.get(transaction=test_transaction,
                             account=self.ac,
                             value=utils.make_decimal(-17817.96)),
            Line.objects.get(transaction=test_transaction,
                             account=self.ap,
                             value=utils.make_decimal(-3447)),
            Line.objects.get(transaction=test_transaction,
                             account=self.ab,
                             value=utils.make_decimal(2385.02)),
            Line.objects.get(transaction=test_transaction,
                             account=self.af,
                             value=utils.make_decimal(6991.98)),
            Line.objects.get(transaction=test_transaction,
                             account=self.ag,
                             value=utils.make_decimal(730.77)),
            Line.objects.get(transaction=test_transaction,
                             account=self.ak,
                             value=utils.make_decimal(8255.34)),
            Line.objects.get(transaction=test_transaction,
                             account=self.ast,
                             value=utils.make_decimal(2901.85)),
            Line.objects.get(transaction=test_transaction,
                             account=self.asl,
                             value=utils.make_decimal(-1752.07)),
            Line.objects.get(transaction=test_transaction,
                             account=self.asu,
                             value=utils.make_decimal(1752.07)),
        ]
        test_result = [
            JournalEntry.objects.get(transaction=test_transaction, )
        ]

        self.assertEqual(test_create_object, test_result)
        self.assertEqual(set(list(test_result[0].transaction.lines.all())),
                         set(test_lines))
    def test_create_object_single_creditor_invoice_using_creditor_invoice(
            self):  # noqa

        test_dump = "creditor\tdate\tinvoice_number\treference\tvalue\tgst_total\torder_number\t[15-0608]\t[15-0151]\t[15-0155]\t[15-0301]\t[15-0305]\r\nBIDVES\t02-Jun-2017\tI38731476\tO37696095\t485.27\t0.65\tguild house\t6.5\t478.12\t\t\t"  # NOQA
        test_create_object = convert_import_to_objects(
            test_dump, user=self.user, object_name='CreditorInvoice')

        # `.get(..` MUST BE BELOW `test_create_object`
        # get the objects that look exactly correct
        test_transaction = Transaction.objects.get(
            value=utils.make_decimal('485.27'),
            date=dateparser.parse('02-Jun-2017'),
            source='subledgers.creditors.models.CreditorInvoice',
            user=self.user)
        test_lines = [
            Line.objects.get(transaction=test_transaction,
                             account=self.a1,
                             value=utils.set_DR('478.12')),
            Line.objects.get(transaction=test_transaction,
                             account=self.a2,
                             value=utils.set_DR('6.5')),
            Line.objects.get(transaction=test_transaction,
                             account=self.account_creditors,
                             value=utils.set_CR('485.27')),
            Line.objects.get(transaction=test_transaction,
                             account=self.account_CR_GST,
                             value=utils.set_DR('0.65')),
        ]
        test_result = [
            CreditorInvoice.objects.get(
                transaction=test_transaction,
                relation=self.creditor0,
                gst_total=utils.make_decimal('0.65'),
                invoice_number='I38731476',
                order_number='guild house',
                reference='O37696095',
            )
        ]

        self.assertEqual(test_create_object, test_result)
        self.assertEqual(set(list(test_result[0].transaction.lines.all())),
                         set(test_lines))
    def test_create_object_single_expense_using_entity_GST_variation_passes(
            self):  # noqa

        # GST allocated, not using `gst_total` field.
        test_dump = 'value\tdate\tnote\ttype\trelation\t[03-0733]\t[15-1420]\t[15-0715]\t[15-0605]\t[15-0150]\t[15-0500]\t[15-0650]\t[15-0705]\t[15-0710]\t[15-1010]\t[15-1400]\t[15-1430]\t[15-0620]\t[15-1470]\r\n53.47\t11-Dec-2015\t7-ELEVEN 2296 ERINDALE CENT\tExpense\t7ELEVE\t4.86\t\t\t\t48.61\t\t\t\t\t\t\t\t\t'  # noqa

        test_create_object = convert_import_to_objects(test_dump,
                                                       user=self.user,
                                                       object_name='Expense')

        test_transaction = Transaction.objects.get(
            value=utils.make_decimal('53.47'),
            date=dateparser.parse('11-Dec-2015'),
            source='subledgers.expenses.models.Expense',
            note='7-ELEVEN 2296 ERINDALE CENT',
            user=self.user)
        test_lines = [
            Line.objects.get(transaction=test_transaction,
                             account=self.a1,
                             value=utils.set_DR('48.61')),
            Line.objects.get(transaction=test_transaction,
                             account=self.EXPENSE_CLEARING_ACCOUNT,
                             value=utils.set_CR('53.47')),
            Line.objects.get(transaction=test_transaction,
                             account=self.account_CR_GST,
                             value=utils.set_DR('4.86')),
        ]
        test_result = [
            Expense.objects.get(
                transaction=test_transaction,
                relation=self.entity0,
            )
        ]

        self.assertEqual(test_create_object, test_result)
        self.assertEqual(set(list(test_result[0].transaction.lines.all())),
                         set(test_lines))