コード例 #1
0
ファイル: ComboDelegate.py プロジェクト: wiz21b/koi
    def get_displayed_data(self, index):
        d = index.model().data(index, Qt.UserRole)
        # mainlog.debug("DurationDelegate.get_displayed_data : ({}-{}) {} ({})".format(index.row(), index.column(), d, type(d)))
        if d:
            if self.format_as_float:
                return duration_to_s(d)
            else:
                return duration_to_hm(d, short_unit=True)

        else:
            return None
コード例 #2
0
ファイル: monthly_report.py プロジェクト: wiz21b/koi
def print_monthly_report(dao, month_date):

    strip_style = ParagraphStyle(name="regular",
                                 fontName='Helvetica-Bold',
                                 fontSize=16,
                                 spaceAfter=0,
                                 spaceBefore=0)
    s = ParagraphStyle(name="regular", fontName='Courrier', fontSize=7)
    order_style = ParagraphStyle(name="regular",
                                 fontName='Helvetica-Bold',
                                 fontSize=14,
                                 spaceAfter=6,
                                 spaceBefore=12)
    small = ParagraphStyle(name="regular", fontName='Helvetica', fontSize=8)
    small_right = ParagraphStyle(name="regular",
                                 fontName='Helvetica',
                                 fontSize=8,
                                 alignment=TA_RIGHT)
    client = ParagraphStyle(name="regular",
                            fontName='Helvetica-Bold',
                            fontSize=9)
    right_align = ParagraphStyle(name="right_align",
                                 fontName='Courier',
                                 fontSize=8,
                                 alignment=TA_RIGHT)
    right_align_bold = ParagraphStyle(name="right_align",
                                      fontName='Courier-Bold',
                                      fontSize=8,
                                      alignment=TA_RIGHT)
    complete_document = []
    spacer = platypus.Spacer(1, 50)

    ts_begin = _first_moment_of_month(month_date)
    ts_end = _last_moment_of_month(month_date)

    # mainlog.debug("Turnover from {} to {} ({})".format(ts_begin, ts_end, month_date))

    # data_ops = [[crlf_to_br(h) for h in [_('Ord.'),_('Description'),_('Hours'),_('Qties'),_('Sell\nprice'),_('To bill\nthis month'),_('Encours')]]]
    data_ops = [[
        _('Ord.'),
        _('Description'),
        _('Hours'),
        _('Qties'),
        _('Sell\nprice'),
        _('To bill\nthis month'),
        _('Encours')
    ]]

    ts = platypus.TableStyle([('FONT', (0, 0), (-1, -1), 'Courier', 8)])

    last_order_id = None

    total_sell_price = 0
    total_encours = 0
    total_to_facture = 0

    sub_total_sell_price = 0
    sub_total_encours = 0
    sub_total_h_done = sub_total_h_planned = 0
    sub_total_to_facture = 0

    row = 1
    first_row = True
    row_in_order = 0

    mainlog.debug("dao.order_dao.order_parts_for_monthly_report(month_date):")
    for part_data in dao.order_dao.order_parts_for_monthly_report(month_date):

        if last_order_id != part_data.order_id:

            last_order_id = part_data.order_id

            if not first_row and row_in_order >= 2:
                # Display sums only if there is more than one row
                # for the order (if only one row, then showing a
                # sum doesn't add any information to the user)

                ts.add('LINEABOVE', (5, row), (-1, row), 0.5, colors.black)
                ts.add('LINEABOVE', (2, row), (2, row), 0.5, colors.black)
                data_ops.append([
                    '',
                    '',
                    Paragraph(
                        '{} / {}'.format(duration_to_s(sub_total_h_done),
                                         duration_to_s(sub_total_h_planned)),
                        small_right),
                    '',
                    '',  # Paragraph(amount_to_short_s(sub_total_sell_price) or "0,00" ,right_align),
                    Paragraph(
                        amount_to_short_s(sub_total_to_facture) or "0,00",
                        right_align_bold),
                    Paragraph(
                        amount_to_short_s(sub_total_encours) or "0,00",
                        right_align)
                ])
                row += 1

            sub_total_sell_price = 0
            sub_total_encours = 0
            sub_total_h_done = sub_total_h_planned = 0
            sub_total_to_facture = 0
            row_in_order = 0

            ts.add('LINEABOVE', (0, row), (-1, row), 0.5, colors.black)
            data_ops.append([
                '',
                Paragraph(part_data.customer_name, client), '', '', '', '', ''
            ])
            row += 1

        facture_explain = ""
        q_out_this_month = part_data.part_qty_out - part_data.q_out_last_month
        # Only give an explanation if all the qty were not done
        # together
        if part_data.q_out_last_month > 0 and q_out_this_month > 0 and q_out_this_month < part_data.qty:
            facture_explain = "({}) ".format(q_out_this_month)

        if part_data.total_estimated_time > 0:
            qty_work = "{} / {}".format(
                duration_to_s(part_data.part_worked_hours) or "0,00",
                duration_to_s(part_data.total_estimated_time))
        else:
            qty_work = "-"

        if part_data.qty > 0:
            qty_str = "{} / {}".format(part_data.part_qty_out, part_data.qty)
        else:
            qty_str = "-"

        data_ops.append([
            Paragraph(part_data.human_identifier, small),
            Paragraph(part_data.description, small),
            Paragraph(qty_work, small_right),
            Paragraph(qty_str, small_right),
            Paragraph(amount_to_short_s(part_data.total_sell_price),
                      right_align),
            Paragraph(
                facture_explain + amount_to_short_s(part_data.bill_this_month),
                right_align_bold),
            Paragraph(amount_to_short_s(part_data.encours), right_align)
        ])

        # if part_data.bill_this_month or True:
        #     print("{} {} {}".format(part_data.human_identifier, part_data.part_qty_out, amount_to_short_s(part_data.bill_this_month)))

        row_in_order += 1
        row += 1

        sub_total_sell_price += total_sell_price
        sub_total_to_facture += part_data.bill_this_month
        sub_total_encours += part_data.encours

        sub_total_h_done += part_data.part_worked_hours or 0
        sub_total_h_planned += part_data.total_estimated_time or 0

        total_to_facture += part_data.bill_this_month
        total_encours += part_data.encours

        first_row = False

    data_ops.append([
        '',
        '',
        '',
        '',
        '',  # Removed total_sell_price because it is misleading
        Paragraph(amount_to_short_s(total_to_facture), right_align_bold),
        Paragraph(amount_to_short_s(total_encours), right_align)
    ])

    ts.add('LINEABOVE', (0, len(data_ops) - 1), (-1, len(data_ops) - 1), 1,
           colors.black)

    ts.add('FONT', (0, 0), (-1, 0), 'Helvetica-Bold', 9)
    ts.add('LINEBELOW', (0, 0), (-1, 0), 1, colors.black)

    t = platypus.Table(data_ops,
                       repeatRows=1,
                       colWidths=[
                           1.50 * cm, 6 * cm, 2.5 * cm, 1.75 * cm, 2.25 * cm,
                           2.25 * cm
                       ])

    t.setStyle(ts)
    t.hAlign = "LEFT"
    complete_document.append(t)
    complete_document.append(platypus.Spacer(0, 10))

    filename = make_pdf_filename("MonthlyOverview_")
    ladderDoc = basic_PDF(filename)

    ladderDoc.subject = _("Monthly financial report")
    ladderDoc.title = date_to_my(month_date, True)

    ladderDoc.build(complete_document, canvasmaker=NumberedCanvas)
    open_pdf(filename)
    return True
コード例 #3
0
ファイル: test_date_parsing.py プロジェクト: wiz21b/koi
    def test_accuracy_transfer(self):
        # Test convertion from string to string back and forth
        parser = DurationParser()

        # Had rounding issues here
        self.assertEqual('2.1', duration_to_s(parser.parse('2.1')))
        self.assertEqual('2.11', duration_to_s(parser.parse('2.11')))
        self.assertEqual('2.19', duration_to_s(parser.parse('2.19')))

        self.assertEqual('2.2', duration_to_s(parser.parse('2.2')))
        self.assertEqual('2.21', duration_to_s(parser.parse('2.21')))
        self.assertEqual('2.22', duration_to_s(parser.parse('2.22')))
        self.assertEqual('2.23', duration_to_s(parser.parse('2.23')))

        self.assertEqual('', duration_to_s(parser.parse('0')))
        self.assertEqual('', duration_to_s(parser.parse('0.0')))
        self.assertEqual('0', duration_to_s(parser.parse('0.001')))
        self.assertEqual('0.01', duration_to_s(parser.parse('0.009')))
        self.assertEqual('0.01', duration_to_s(parser.parse('0.014999999')))
        self.assertEqual('0.33', duration_to_s(1.0 / 3.0))
        self.assertEqual('0.67', duration_to_s(2.0 / 3.0))

        # So the duration can be expressed in a nice way
        # but they're always rendered as hours

        self.assertEqual('50.4', duration_to_s(parser.parse('2.1j')))
        self.assertEqual('0.04', duration_to_s(parser.parse('2.1m')))
コード例 #4
0
ファイル: TimeTracksOverview.py プロジェクト: mobidian/koi
    def refresh_action(self):
        global dao

        self.title_box.set_title(_("Time Records Overview - {}").format(date_to_my(self.base_date,True)))


        self.employees = dao.employee_dao.all()
        day_max = calendar.monthrange(self.base_date.year,self.base_date.month)[1]
        t_start = datetime(self.base_date.year,self.base_date.month,1)
        t_end   = datetime(self.base_date.year,self.base_date.month,day_max,23,59,59,999999)


        self._table_model.setRowCount( len(self.employees))
        self._table_model.setColumnCount( 1+day_max)

        headers = QStandardItemModel(1, 1+day_max)
        headers.setHeaderData(0, Qt.Orientation.Horizontal, _("Employee"))
        for i in range(day_max):
            headers.setHeaderData(i+1, Qt.Orientation.Horizontal, "{}".format(i+1))
        self.headers_view.setModel(headers) # qt's doc : The view does *not* take ownership
        self.header_model = headers

        row = 0
        for employee in self.employees:
            # mainlog.debug(u"refresh action employee {}".format(employee))

            self._table_model.setData(self._table_model.index(row,0),employee.fullname,Qt.DisplayRole) # FIXME Use a delegate
            self._table_model.setData(self._table_model.index(row,0),employee,Qt.UserRole) # FIXME Use a delegate

            tracks = session().query(TimeTrack).filter(and_(TimeTrack.employee_id == employee.employee_id, TimeTrack.start_time >= t_start,TimeTrack.start_time <= t_end)).all()

            # One bucket per day
            buckets = [0] * day_max
            for t in tracks:
                mainlog.debug("Bucket {}".format(t))
                buckets[t.start_time.day - 1] += t.duration

            for b in range(len(buckets)):
                if buckets[b] != 0:
                    self._table_model.setData(self._table_model.index(row,b+1),duration_to_s(buckets[b]),Qt.DisplayRole)
                else:
                    self._table_model.setData(self._table_model.index(row,b+1),None,Qt.DisplayRole)

                if buckets[b] >= 0:
                    # Clear the background
                    self._table_model.setData(self._table_model.index(row,b+1),None,Qt.BackgroundRole)
                else:
                    self._table_model.setData(self._table_model.index(row,b+1),QBrush(QColor(255,128,128)),Qt.TextColorRole)

                self._table_model.setData(self._table_model.index(row,b+1),Qt.AlignRight,Qt.TextAlignmentRole)
            row += 1


        # Compute all mondays indices
        monday = 0
        if t_start.weekday() > 0:
            monday = 7 - t_start.weekday()
        all_mondays = []

        while monday < day_max:
            all_mondays.append(monday)
            monday += 7

        today = date.today()

        for row in range(len(self.employees)):
            # Mark mondays
            for col in all_mondays:
                # col + 1 to account for the employee column
                self._table_model.setData(self._table_model.index(row,col + 1),QBrush(QColor(230,230,255)),Qt.BackgroundRole)

            # Mark today
            if today.month == self.base_date.month and today.year == self.base_date.year:
                self._table_model.setData(self._table_model.index(row,today.day),QBrush(QColor(255,255,128)),Qt.BackgroundRole)

        #for i in range(len(all_mondays)):
        self.table_view.resizeColumnsToContents()

        # mainlog.debug("Reset selection")
        ndx = self.table_view.currentIndex()

        self.table_view.selectionModel().clear()
        # self.table_view.selectionModel().clearSelection()
        # self.table_view.selectionModel().select( self.table_view.model().index(ndx.row(),ndx.column()), QItemSelectionModel.Select)
        # self.table_view.selectionModel().select( self.table_view.model().index(ndx.row(),ndx.column()), QItemSelectionModel.Select)
        self.table_view.selectionModel().setCurrentIndex( self.table_view.model().index(ndx.row(),ndx.column()), QItemSelectionModel.Select)