コード例 #1
0
ファイル: invoice.py プロジェクト: plastboks/Pyrtos
    def invoices(self):
        """ Get a paginated list of active invoices for current
        or given month."""

        paid_result = {}
        unpaid_result = {}
        year = int(self.request.params.get('year',
                                           datetime.now().strftime('%Y')))
        month = int(self.request.params.get('month',
                                            datetime.now().strftime('%m')))

        categories = Category.all_active(self.request).all()
        for c in categories:
            paid_invoices = Invoice.with_category_paid(c.id,
                                                       year,
                                                       month)
            if paid_invoices:
                total = Invoice.with_category_paid(c.id,
                                                   year,
                                                   month,
                                                   total_only=True)
                paid_result[c.title] = [paid_invoices, total]

            unpaid_invoices = Invoice.with_category_all_unpaid(c.id)
            if unpaid_invoices:
                total = Invoice.with_category_all_unpaid(c.id, total_only=True)
                unpaid_result[c.title] = [unpaid_invoices, total]

        return {'paiditems': paid_result,
                'unpaiditems': unpaid_result,
                'title': 'Invoices',
                'month': month,
                'year': year,
                'nextmonth': self.month_switcher(year, month, next=True),
                'prevmonth': self.month_switcher(year, month)}