Exemplo n.º 1
0
    def test_account_daily(self):
        fromDate, tillDate = rangeDateFromTillByInterval(
            self.dates[0], self.dates[0], INTERVAL_DAILY)
        report = Report(self._db, fromDate, tillDate)
        report += self._db["Root/Test"]
        items = [i.descr for i in report.items]
        self.assertSetEqual(set(), set(items))

        fromDate, tillDate = rangeDateFromTillByInterval(
            self.dates[0], self.dates[0], INTERVAL_DAILY)
        report = Report(self._db, fromDate, tillDate)
        report += self._db["Root/Foo"]
        items = [i.descr for i in report.items]
        self.assertSetEqual({'AAA'}, set(items))

        fromDate, tillDate = rangeDateFromTillByInterval(
            self.dates[1], self.dates[2], INTERVAL_DAILY)
        report = Report(self._db, fromDate, tillDate)
        report += self._db["Root/Foo"]
        items = [i.descr for i in report.items]
        self.assertSetEqual({'EEE', 'GGG'}, set(items))

        fromDate, tillDate = rangeDateFromTillByInterval(
            self.dates[0], self.dates[3], INTERVAL_DAILY)
        report = Report(self._db, fromDate, tillDate)
        report += self._db["Root/Foo"]
        report += self._db["Root/Bar"]
        items = [i.descr for i in report.items]
        self.assertSetEqual({'AAA', 'BBB', 'EEE', 'FFF', 'GGG', 'HHH', 'III'},
                            set(items))
Exemplo n.º 2
0
    def test_06_accounts_by_year(self):
        fromDate, tillDate = rangeDateFromTillByInterval(
            self.dates[0], self.dates[0], INTERVAL_ANUALY)
        self.assertEqual(datetime.timedelta(days=364), tillDate - fromDate)

        report = Report(self._db, fromDate, tillDate)
        report += self._db["Root/Bar"]
        items = [i.descr for i in report.items]
        self.assertSetEqual({'BBB', 'FFF', 'HHH', 'LLL', 'NNN', 'PPP'},
                            set(items))

        grp = ItemGroupingByDateRange(fromDate, tillDate, INTERVAL_ANUALY)
        grp += report

        date_ranges = list(grp.groups())
        self.assertEqual(1, len(date_ranges))
        items_per_data_ranges = [
            list(grp.groupItems(date_range)) for date_range in date_ranges
        ]
        items_per_data_ranges = [[i.descr for i in items]
                                 for items in items_per_data_ranges]
        self.assertSetEqual({'BBB', 'FFF', 'HHH', 'LLL', 'NNN', 'PPP'},
                            set(items_per_data_ranges[0]))

        fromDate, tillDate = rangeDateFromTillByInterval(
            self.dates[0], self.dates[6], INTERVAL_ANUALY)
        self.assertEqual(datetime.timedelta(days=729), tillDate - fromDate)

        report = Report(self._db, fromDate, tillDate)
        report += self._db["Root/Bar"]
        items = [i.descr for i in report.items]
        self.assertSetEqual({'BBB', 'FFF', 'HHH', 'LLL', 'NNN', 'PPP', 'RRR'},
                            set(items))

        grp = ItemGroupingByDateRange(fromDate, tillDate, INTERVAL_ANUALY)
        grp += report

        date_ranges = list(grp.groups())
        self.assertEqual(2, len(date_ranges))
        items_per_data_ranges = [
            list(grp.groupItems(date_range)) for date_range in date_ranges
        ]
        items_per_data_ranges = [[i.descr for i in items]
                                 for items in items_per_data_ranges]
        self.assertSetEqual({'BBB', 'FFF', 'HHH', 'LLL', 'NNN', 'PPP'},
                            set(items_per_data_ranges[0]))
        self.assertSetEqual({'RRR'}, set(items_per_data_ranges[1]))
Exemplo n.º 3
0
    def test_05_accounts_by_month(self):
        fromDate, tillDate = rangeDateFromTillByInterval(
            self.dates[0], self.dates[0], INTERVAL_MONTHLY)
        self.assertEqual(datetime.timedelta(days=30), tillDate - fromDate)

        report = Report(self._db, fromDate, tillDate)
        report += self._db["Root/Foo"]
        items = [i.descr for i in report.items]
        self.assertSetEqual({'AAA', 'EEE', 'GGG'}, set(items))

        grp = ItemGroupingByDateRange(fromDate, tillDate, INTERVAL_MONTHLY)
        grp += report

        date_ranges = list(grp.groups())
        self.assertEqual(1, len(date_ranges))
        items_per_data_ranges = [
            list(grp.groupItems(date_range)) for date_range in date_ranges
        ]
        items_per_data_ranges = [[i.descr for i in items]
                                 for items in items_per_data_ranges]
        self.assertSetEqual({'AAA', 'EEE', 'GGG'},
                            set(items_per_data_ranges[0]))

        fromDate, tillDate = rangeDateFromTillByInterval(
            self.dates[0], self.dates[3], INTERVAL_MONTHLY)
        self.assertEqual(datetime.timedelta(days=60), tillDate - fromDate)

        report = Report(self._db, fromDate, tillDate)
        report += self._db["Root/Foo"]
        items = [i.descr for i in report.items]
        self.assertSetEqual({'AAA', 'EEE', 'GGG', 'III'}, set(items))

        grp = ItemGroupingByDateRange(fromDate, tillDate, INTERVAL_MONTHLY)
        grp += report

        date_ranges = list(grp.groups())
        self.assertEqual(2, len(date_ranges))
        items_per_data_ranges = [
            list(grp.groupItems(date_range)) for date_range in date_ranges
        ]
        items_per_data_ranges = [[i.descr for i in items]
                                 for items in items_per_data_ranges]
        self.assertSetEqual({'AAA', 'EEE', 'GGG'},
                            set(items_per_data_ranges[0]))
        self.assertSetEqual({'III'}, set(items_per_data_ranges[1]))
Exemplo n.º 4
0
    def __init__(self, accounts):
        """Construct view for given template to show account(s) report."""
        super().__init__()

        self._template = None

        today = datetime.date.today()
        startofmonth, endofmonth = rangeDateFromTillByInterval(
            today, today, INTERVAL_MONTHLY)
        self._report = Report(accounts[0].db, startofmonth, endofmonth)
        for acc in accounts:
            self._report += acc

        hbox = QtWidgets.QHBoxLayout()
        hbox.setContentsMargins(0, 0, 0, 0)

        vbox = QtWidgets.QVBoxLayout()
        vbox.setSpacing(4)
        vbox.setContentsMargins(0, 0, 0, 0)
        hbox.addLayout(vbox)

        hbox2 = QtWidgets.QHBoxLayout()
        hbox2.setContentsMargins(4, 0, 4, 4)
        self._fromDate = QtWidgets.QDateEdit()
        self._fromDate.setCalendarPopup(True)
        self._fromDate.setDate(startofmonth)
        self._fromDate.dateChanged.connect(self._rangeChanged)
        hbox2.addWidget(QtWidgets.QLabel("From"),
                        alignment=QtCore.Qt.AlignRight)
        hbox2.addWidget(self._fromDate)
        hbox2.addSpacing(40)
        hbox2.addWidget(QtWidgets.QLabel("to"), alignment=QtCore.Qt.AlignRight)
        self._tillDate = QtWidgets.QDateEdit()
        self._tillDate.setCalendarPopup(True)
        self._tillDate.setDate(endofmonth)
        self._tillDate.dateChanged.connect(self._rangeChanged)
        hbox2.addWidget(self._tillDate)
        hbox2.addSpacing(40)
        self._selectBtn = QtWidgets.QPushButton("Select")
        self._selectBtn.clicked.connect(self.selectTemplate)
        hbox2.addWidget(self._selectBtn, 1)
        self._createBtn = QtWidgets.QPushButton("Create")
        self._createBtn.clicked.connect(self.refreshReport)
        hbox2.addWidget(self._createBtn, 1)
        # self._printBtn = QtWidgets.QPushButton("Print")
        # self._printBtn.clicked.connect(self.printReport)
        # hbox2.addWidget(self._printBtn, 1)

        vbox.addLayout(hbox2)

        # self._browser = QtWebKitWidgets.QWebView(self)
        # vbox.addWidget(self._browser)

        self.setLayout(hbox)
Exemplo n.º 5
0
    def test_account_and_children_daily(self):
        fromDate, tillDate = rangeDateFromTillByInterval(
            self.dates[0], self.dates[2], INTERVAL_DAILY)
        report = Report(self._db, fromDate, tillDate)
        report += self._db["Root"]
        items = [i.descr for i in report.items]
        self.assertSetEqual(
            {'AAA', 'BBB', 'CCC', 'DDD', 'EEE', 'FFF', 'GGG', 'HHH'},
            set(items))

        fromDate, tillDate = rangeDateFromTillByInterval(
            self.dates[0], self.dates[3], INTERVAL_DAILY)
        report = Report(self._db, fromDate,
                        tillDate + datetime.timedelta(days=1))
        report += self._db["Root"]
        items = [i.descr for i in report.items]
        self.assertSetEqual(
            {
                'AAA', 'BBB', 'CCC', 'DDD', 'EEE', 'FFF', 'GGG', 'HHH', 'III',
                'JJJ'
            }, set(items))
Exemplo n.º 6
0
 def test_08_pie_template(self):
     fromDate, tillDate = rangeDateFromTillByInterval(
         self.dates[0], self.dates[0], INTERVAL_MONTHLY)
     report = Report(self._db, fromDate, tillDate)
     report += self._db["Root/Bar"]
     report_template_dir = os.path.normpath(
         os.path.join(os.path.dirname(__file__), "..", "accounting",
                      "templates"))
     report_template_name = "report_monthly_list_grouped_pct.accrep"
     template = ReportTemplate(report_template_dir, report_template_name)
     html = template.render(report)
     html_path = os.path.join(
         report_template_dir,
         os.path.splitext(report_template_name)[0] + ".html")
     with open(html_path, "w", encoding="utf-8") as f:
         f.write(html)
Exemplo n.º 7
0
 def __init__(self, fromDate, tillDate, interval):
     self._interval = interval
     self._fromDate, self._tillDate = rangeDateFromTillByInterval(fromDate, tillDate, self._interval)