Ejemplo n.º 1
0
 def draw_page_number(self, page_count):
     self.setFont("Helvetica", 7)
     self.drawRightString(
         A4[0] - 1 * cm, 0.5 * cm,
         _("Page {} of {}, printed on {} by {}").format(
             self._pageNumber, page_count,
             date_to_dmy(datetime.today(), full_month=True),
             user_session.name or '-'))
Ejemplo n.º 2
0
    def set_event_on_days(self, day_event: DayEvent, days_duration: list):
        """ Set an event on several days each time with a specific duration.

        :param day_event:
        :param days_duration: An array of pairs. Each pair is (date, duration). Each date
         must be unique.
        :return:
        """

        day_max = date(1980, 1, 1)
        day_min = date(2050, 12, 31)

        mainlog.debug("set_event_on_days")
        mainlog.debug(days_duration)

        for day, duration in days_duration:
            day_min = min(day_min, day)
            day_max = max(day_max, day)

        db_events = session().query(DayEvent).filter(
            and_(DayEvent.employee_id == day_event.employee_id,
                 DayEvent.event_type == day_event.event_type,
                 DayEvent.date.between(day_min, day_max))).all()

        db_events_dates = dict(zip([e.date for e in db_events], db_events))

        other_db_events = session().query(DayEvent.date,
                                          func.sum(DayEvent.duration).label("duration_sum")).\
            filter( and_( DayEvent.employee_id == day_event.employee_id,
                          DayEvent.event_type != day_event.event_type,
                          DayEvent.date.between(day_min, day_max))).\
            group_by(DayEvent.date).all()

        other_db_events_dates = dict([(e.date, e.duration_sum)
                                      for e in other_db_events])

        for day, duration in days_duration:
            if day in other_db_events_dates and other_db_events_dates[
                    day] + duration > 1:
                raise ServerException(ServerErrors.too_much_off_time_on_a_day,
                                      date_to_dmy(day))

            if day in db_events_dates:
                # Replace the old duration
                db_event = db_events_dates[day]
                db_event.duration = duration
            else:
                nu_event = DayEvent()
                nu_event.date = day
                nu_event.duration = duration
                nu_event.event_type = day_event.event_type
                nu_event.employee_id = day_event.employee_id
                session().add(nu_event)

        session().commit()
Ejemplo n.º 3
0
    def _fill_view_with_order_data(self, order_id):
        sorder, sorder_parts = supply_order_service.find_by_id(order_id)

        self.edit_comment_widget.setText(sorder.description)
        self.delivery_date_widget.set_value(sorder.expected_delivery_date)
        self.creation_date_widget.setText(date_to_dmy(sorder.creation_date))
        self.supplier_reference_widget.setText(sorder.supplier_reference)
        self.current_supplier = supplier_service.find_by_id(sorder.supplier_id)
        self.current_supply_order_id = sorder.supply_order_id
        self.model._buildModelFromObjects(sorder_parts)
        self.accounting_label = sorder.accounting_label
Ejemplo n.º 4
0
    def cell_entered(self, ndx):
        employee_id = self._employee_id_on_row(ndx)

        if not employee_id:
            self._show_totals_day_off(None)

        elif employee_id:
            chrono.chrono_start()

            employee = None
            for i in self.employees:
                if i.employee_id == employee_id:
                    employee = i
                    break

            self.detail_subframe.set_title(employee.fullname)
            self._show_totals_day_off(employee_id)

            d = date(
                self.base_date.year, self.base_date.month,
                min(
                    calendar.monthrange(self.base_date.year,
                                        self.base_date.month)[1],
                    max(1, ndx.column())))

            chrono.chrono_click("Retrieveing data")
            tars = dao.task_action_report_dao.get_reports_for_employee_id_on_date(
                employee_id, d)
            work_timetracks = dao.timetrack_dao.all_work_for_employee_date_manual(
                employee_id, d)
            presence_timetracks = dao.timetrack_dao.all_presence_for_employee_date_managed_by_code_full(
                employee_id, d)
            # employee = dao.employee_dao.find_by_id(employee_id)
            special_activities = dao.special_activity_dao.find_on_day(
                employee_id, d)

            chrono.chrono_click("Redrawing")
            self.time_report_view.redraw(datetime(d.year, d.month, d.day, 6,
                                                  0),
                                         tars,
                                         employee_id,
                                         work_timetracks,
                                         presence_timetracks,
                                         special_activities,
                                         view_title=_("Work on {}").format(
                                             date_to_dmy(d, full_month=True)))
            session().close(
            )  # FIXME Put his one line above; but that's tough ! SQLA doesn't help us much here !
            chrono.chrono_click("Session closed")

            # for event_type, duration in self.day_event_totals[employee_id].items():
            #     mainlog.debug("{}{}".format(event_type, duration))

        self._toggle_days_off_actions()
Ejemplo n.º 5
0
    def _operation_hoover_description(self, op):
        # order_part = op.production_file.order_part

        txt = [
            u"{} {}".format(op.order_part_human_identifier,
                            date_to_dmy(op.deadline)),  # order_part.deadline
            op.order_part_description or "",
            op.description or "",
            _("{}x{}={}h, rest:{}h").format(
                op.qty, nice_round(op.planned_hours),
                nice_round(op.qty * op.planned_hours),
                nice_round(op.planned_hours * op.qty - op.done_hours))
        ]
        return txt
Ejemplo n.º 6
0
def append_header_block(complete_document, title, ddate):
    # Header frame

    data_ops = [[
        Paragraph(title, header_fnt),
        Paragraph(date_to_dmy(ddate, full_month=True), header_small_fnt)
    ]]

    t = MyTable(data_ops, colWidths=[A4[0] - 5 * cm - 2 * cm, 5 * cm])
    t.spaceAfter = 1 * cm

    ts = platypus.TableStyle([('BACKGROUND', (0, 0), (-1, -1),
                               colors.Color(0.8, 0.8, 0.8))])
    ts.add('BOX', (0, 0), (-1, -1), 1, colors.black)
    ts.add('ALIGN', (0, 0), (0, 0), 'LEFT')
    ts.add('ALIGN', (1, 0), (1, 0), 'RIGHT')
    t.setStyle(ts)
    complete_document.append(t)
Ejemplo n.º 7
0
    def _redraw(self):

        self.view.redraw(self.base_time,
                         self.all_tars + self.added_tars,
                         self.employee.employee_id, [], [],
                         view_title=_("Time records for {} on {}").format(
                             self.employee.fullname,
                             date_to_dmy(self.base_time)))

        # self.view.redraw(self.base_time,
        #                  self._merge_all(self.all_tars + self.added_tars),
        #                  self.employee,
        #                  self._merge_all(self.manual_work_timetracks),
        #                  self._merge_all(self.manual_presence_timetracks))

        # This to make sure that we maintain no lock in the transaction
        # after having completed the drawing

        session().commit()
Ejemplo n.º 8
0
def _make_preorder_report(preorder,filename):

    # Session open !

    s = ParagraphStyle(name = "regular", fontName = 'Helvetica', fontSize=11, spaceAfter=6)
    money = ParagraphStyle(name = "money", fontName = 'DejaVuSansMono', fontSize=11, spaceAfter=6,alignment=TA_RIGHT)

    right_align = ParagraphStyle(name = "right_align", fontName = 'Helvetica', fontSize=11,alignment=TA_RIGHT)
    complete_document = []
    spacer = platypus.Spacer(1,1*cm)

    c = preorder.customer

    # Address frame

    p = Paragraph(escape_html(c.fullname),s)
    complete_document.append(p)
    p = Paragraph(escape_html(c.address1),s)
    complete_document.append(p)
    p = Paragraph(escape_html(c.address2),s)
    complete_document.append(p)
    p = Paragraph(escape_html(c.country),s)
    complete_document.append(p)

    complete_document.append(FrameBreak())

    # Header frame

    title = ""
    if preorder.customer_order_name:
        title = _("Preorder {}, your ref. : {}").format(preorder.preorder_label or "-",
                                                        escape_html(preorder.customer_order_name))
    else:
        title = _("Preorder {}").format(preorder.preorder_label or "-")

    append_header_block(complete_document, title, date.today())

    # Introduction text

    intro = preorder.preorder_print_note or ""
    p = Paragraph(escape_html(intro),s)
    complete_document.append(p)
    complete_document.append(spacer)




    # Well, by combining a MIDDLE VALIGN and a leading=20, I can get the
    # paragraph to be right in the middle of the cell (vertically speaking)
    # It doesn't make sense to me, it's pure trial and error...

    subtitle = ParagraphStyle(name = "subtitle", fontName = 'Helvetica', fontSize=16, leading=20)


    data_ops = [ [_(u'Reference'), '', _(u'Designation'),'',_('Deadline'),'',_('Quantity'),'',_('Unit Price'),'',_('Price')] ]

    # getcontext().prec = 2

    with localcontext() as ctx: # decimal context
        ctx.prec = 10+2
        qtize = Decimal(10)**-2

        total = Decimal(0)

        for part in preorder.parts:

            price = Decimal(int(part.qty) * part.sell_price).quantize(qtize)
            total += price

            s_qty = ''
            if part.qty > 0:
                s_qty = str(int(part.qty))

            s_price = ''
            if part.sell_price > 0 and part.qty > 0:
                s_price = moneyfmt(price)

            dl = "-"
            if part.deadline:
                dl = date_to_dmy(part.deadline)

            data_ops.append([Paragraph(u"<b>{}</b>".format(part.human_identifier),s),
                             None,
                             Paragraph(escape_html(part.description),s),
                             None,
                             Paragraph(dl,right_align),
                             None,
                             Paragraph(u"{}".format(s_qty),money),
                             None,
                             Paragraph(u"{}".format(moneyfmt(Decimal(part.sell_price).quantize(qtize))),money),
                             None,
                             Paragraph(u"{}".format(s_price),money)])

    # data_ops.append([None,
    #                  None,
    #                  None,
    #                  None,
    #                  Paragraph(_("Total"),s),
    #                  None,
    #                  Paragraph(moneyfmt(total),money)])

    t = MyTable(data_ops, repeatRows=1, colWidths=[2*cm,0.2*cm,6*cm,0.2*cm,2*cm,0.2*cm,1*cm,0.2*cm,3*cm,0.2*cm,3*cm]) # Repeat the table header
    t.spaceAfter = 1*cm

    ts = platypus.TableStyle([('FONT', (0, 0), (-1, -1), 'Helvetica-Bold', 12)])
    ts.add('ALIGN', (0, 0), (-1, -1), 'LEFT')
    ts.add('VALIGN', (0, 0), (-1, -1), 'TOP')

    ts.add("LEFTPADDING", (0, 0), (-1, -1), 0)
    ts.add("RIGHTPADDING", (0, 0), (-1, -1), 0)

    # This is the header row
    ts.add('LINEBELOW', (0, 0), (0, 0), 0.5, colors.black)
    ts.add('LINEBELOW', (2, 0), (2, 0), 0.5, colors.black)
    ts.add('LINEBELOW', (4, 0), (4, 0), 0.5, colors.black)
    ts.add('LINEBELOW', (6, 0), (6, 0), 0.5, colors.black)
    ts.add('LINEBELOW', (8, 0), (8, 0), 0.5, colors.black)
    ts.add('LINEBELOW', (10, 0), (10, 0), 0.5, colors.black)
    #ts.add('LINEBELOW', (6, -2), (6, -2), 0.5, colors.black) # subtotal line
    ts.add('VALIGN', (0, 0), (-1, 0), 'MIDDLE')

    # for row in titles_row:
    #     ts.add('FONT', (0, row), (-1, row), 'Helvetica', 10)

    t.setStyle(ts)
    complete_document.append(t)

    footer = preorder.preorder_print_note_footer or ""
    p = Paragraph(escape_html(footer),s)
    complete_document.append(p)

    # complete_document.append(spacer)
    # p = Paragraph(_("This is a preorder."),s)
    # complete_document.append(p)

    data_ops = [ [ "", Paragraph(_("Signature"),s)] ]
    t = platypus.Table(data_ops, repeatRows=1, colWidths=[8*cm,8*cm]) # Repeat the table header
    complete_document.append(t)

    append_general_conditions(complete_document)

    ladderDoc = customer_PDF(filename)
    ladderDoc.subject = date_to_dmy(datetime.today(),full_month=True) # or preorder.creation_date ?
    ladderDoc.build(complete_document,canvasmaker=NumberedCanvas)
Ejemplo n.º 9
0
def _make_iso_status(dao, order_id):

    global header_text, sub_header_text

    strip_style = ParagraphStyle(name="regular",
                                 fontName='Helvetica-Bold',
                                 fontSize=16,
                                 spaceAfter=0,
                                 spaceBefore=0)
    s = ParagraphStyle(name="regular",
                       fontName='Helvetica',
                       fontSize=12,
                       spaceAfter=6)

    # s = getSampleStyleSheet()['BodyText']

    title_style = ParagraphStyle(name="regular",
                                 fontName='Helvetica-Bold',
                                 fontSize=16,
                                 spaceAfter=24,
                                 spaceBefore=24)
    order_style = ParagraphStyle(name="regular",
                                 fontName='Helvetica-Bold',
                                 fontSize=14,
                                 spaceAfter=6,
                                 spaceBefore=12)
    small = ParagraphStyle(name="regular", fontName='Helvetica', fontSize=8)
    right_align = ParagraphStyle(name="right_align",
                                 fontName='Helvetica',
                                 fontSize=12,
                                 alignment=TA_RIGHT)

    complete_document = []
    spacer = platypus.Spacer(1, 50)

    metadata, timetracks = dao.order_dao.load_order_timetracks(order_id)
    issues = dao.quality_dao.find_by_order_id(order_id)

    header_text = u"{} [{}]".format(metadata['customer_name'],
                                    metadata['customer_order_name'])
    sub_header_text = _("Order activity report")

    # complete_document.append(Paragraph(_("Order information"),title_style))

    complete_document.append(
        Paragraph(_("Customer : {}").format(metadata['customer_name']), s))
    complete_document.append(
        Paragraph(
            _("Order number : {} (Horse ID:{})").format(
                metadata['accounting_label'] or "-",
                metadata['horse_order_id']), s))
    complete_document.append(
        Paragraph(
            _("Preorder number : {}").format(metadata['preorder_label']
                                             or "-"), s))
    complete_document.append(
        Paragraph(
            _("Customer number : {}").format(metadata['customer_order_name']),
            s))
    complete_document.append(
        Paragraph(
            _("Creation date : {}").format(
                date_to_dmy(metadata['creation_date'])), s))
    complete_document.append(
        Paragraph(
            _("Completion : {}").format(date_to_dmy(
                metadata['completed_date'])), s))
    complete_document.append(
        Paragraph(
            _("Current state : {}").format(metadata['state'].description), s))

    complete_document.append(Paragraph(_("Activity synthesis"), title_style))

    ts = platypus.TableStyle([('FONT', (0, 0), (-1, -1), 'Helvetica', 12)])
    tdata = []
    # tdata.append([None, _("Order part")])

    for part_id, part_desc, part_state, part_completed_date, employee_timetracks, order_part_id in timetracks:

        row = [
            part_id,
            Paragraph(
                "<b>{}</b>".format(
                    escape_html(
                        split_long_string(part_desc) + " (" + smart_join([
                            part_state.description,
                            date_to_dmy(part_completed_date)
                        ]) + ")")), s)
        ]
        tdata.append(row)
        row_ndx = len(tdata) - 1
        ts.add('BOX', (0, row_ndx), (-1, row_ndx), 1, colors.black)
        ts.add('BACKGROUND', (0, row_ndx), (-1, row_ndx),
               colors.Color(0.8, 0.8, 0.8))

        if employee_timetracks:
            # dunno why, ordered dicts are not ordered anymore when iterated over their '.items()'
            for employee in sorted(employee_timetracks.keys()):
                tt = employee_timetracks[employee]

                # mainlog.debug("employee : {}".format(employee))
                # mainlog.debug(timetracks[0])

                row = [None, None]
                row[1] = Paragraph(
                    u"{} : {}".format(
                        employee, u"; ".join(
                            map(
                                lambda z: u"{} {} <b>{}</b>".format(
                                    z[0], date_to_dmy(z[1]),
                                    duration_to_hm(z[2])), tt))), s)
                tdata.append(row)
        else:
            tdata.append(["", _("No work reported")])

        for issue in issues:
            if issue.order_part_id == order_part_id:
                name = "?"
                if issue.who:
                    name = issue.who.fullname

                row = [
                    Paragraph(_("<b>QUAL !</b>"), s),
                    Paragraph(
                        _("<b>{}</b> on {} by {} : {}").format(
                            issue.human_identifier, date_to_dmy(issue.when),
                            escape_html(name), escape_html(issue.description)),
                        s)
                ]
                tdata.append(row)

    # ts.add('FONT', (0, 0), (-1, 0), 'Helvetica-Bold', 12)

    # ts.add('INNERGRID', (0, 0), (-1, -1), 0.5, colors.black)
    ts.add('BOX', (0, 0), (-1, -1), 0.25, colors.black)

    ts.add('ALIGN', (0, 0), (-1, -1), 'LEFT')
    ts.add('VALIGN', (0, 0), (-1, -1), 'TOP')

    ts.add("LEFTPADDING", (0, 0), (0, -1), 0)
    ts.add("RIGHTPADDING", (1, 0), (-1, -1), 0)

    if tdata:
        t = platypus.Table(tdata, repeatRows=0, colWidths=[2 * cm, 17.5 * cm])
        t.setStyle(ts)
        complete_document.append(t)

    complete_document.append(Paragraph(_("Delivery slips"), title_style))

    slips = dao.order_dao.find_by_id(order_id).delivery_slips()
    if not slips:
        complete_document.append(Paragraph(_("There are no delivery slip"), s))

    for slip in slips:

        if slip.active:
            complete_document.append(
                Paragraph(
                    _("Delivery slip {} created on {}").format(
                        slip.delivery_slip_id, date_to_dmy(slip.creation)), s))

            for ds_part in sorted(slip.delivery_slip_parts,
                                  key=lambda p: p.order_part.label):
                complete_document.append(
                    Paragraph(
                        _("{} : {} unit(s)").format(ds_part.order_part.label,
                                                    ds_part.quantity_out), s))
        else:
            complete_document.append(
                Paragraph(
                    _("Delivery slip {} DESACTIVATED").format(
                        slip.delivery_slip_id), s))

    complete_document.append(Paragraph(_("Quality"), title_style))

    if not issues:
        complete_document.append(Paragraph(_("There are no quality issues"),
                                           s))
    else:
        for issue in issues:
            name = "?"
            if issue.who:
                name = issue.who.fullname
            complete_document.append(
                Paragraph(
                    _("Issue <b>{}</b> created on {} by {} : {}").format(
                        issue.human_identifier, date_to_dmy(issue.when),
                        escape_html(name), escape_html(issue.description)), s))

    def order_number_title(preorder_number, order_number, customer_number):
        t = []

        if order_number:
            t.append(str(order_number))

        if preorder_number:
            t.append(_("Preorder {}").format(preorder_number))

        # Would' be nice but takes way too much width on the paper
        # if customer_number:
        #     t.append(str(customer_number) + "lkjlkj  lkj  ///SDFSF")

        return u" / ".join(t)

    return order_number_title(
        metadata['preorder_label'], metadata['accounting_label'],
        metadata['customer_order_name']), complete_document
Ejemplo n.º 10
0
    def __init__(self, parent, dao):
        super(ReprintDeliverySlipDialog, self).__init__(parent)
        self.dao = dao

        title = _("Print a delivery slip")
        self.setWindowTitle(title)
        top_layout = QVBoxLayout()
        self.title_widget = TitleWidget(title, None)

        self.buttons = QDialogButtonBox()
        self.buttons.addButton(QDialogButtonBox.StandardButton.Cancel)
        self.buttons.addButton(QDialogButtonBox.Ok)

        hlayout = QHBoxLayout()
        hlayout.addWidget(QLabel(_("Slip number")))
        self.slip_number = QLineEdit()
        hlayout.addWidget(self.slip_number)
        hlayout.addStretch()

        self.search_results_view = QTableView()
        self.search_results_model = QStandardItemModel()
        self.search_results_model.setHorizontalHeaderLabels(
            [_("Slip Nr"), _("Date"),
             _("Customer"), _("Order")])

        self.search_results_view.setModel(self.search_results_model)
        # self.search_results_view.setHorizontalHeader(self.headers_view)
        self.search_results_view.setEditTriggers(
            QAbstractItemView.NoEditTriggers)

        self.search_results_view.horizontalHeader().setResizeMode(
            1, QHeaderView.ResizeToContents)
        self.search_results_view.horizontalHeader().setResizeMode(
            2, QHeaderView.Stretch)
        self.search_results_view.verticalHeader().hide()

        self.slip_part_view = DeliverySlipViewWidget(self)

        hlayout_results = QHBoxLayout()
        hlayout_results.addWidget(self.search_results_view)
        hlayout_results.addWidget(self.slip_part_view)

        self.search_results_model.removeRows(
            0, self.search_results_model.rowCount())
        delivery_slips = self.dao.delivery_slip_part_dao.find_recent()
        for slip in delivery_slips:
            self.search_results_model.appendRow([
                QStandardItem(str(slip[0])),
                QStandardItem(date_to_dmy(slip[1])),
                QStandardItem(slip[2]),
                QStandardItem(slip[3])
            ])

        top_layout.addWidget(self.title_widget)
        top_layout.addLayout(hlayout)
        top_layout.addLayout(hlayout_results)
        top_layout.addWidget(self.buttons)
        top_layout.setStretch(2, 100)
        self.setLayout(top_layout)

        self.search_results_view.setSelectionBehavior(
            QAbstractItemView.SelectRows)
        self.search_results_view.setSelectionMode(
            QAbstractItemView.SingleSelection)

        self.buttons.accepted.connect(self.accept)
        self.buttons.rejected.connect(self.reject)
        self.search_results_view.activated.connect(self.row_activated)
        self.search_results_view.selectionModel().currentRowChanged.connect(
            self.row_selected)
Ejemplo n.º 11
0
def _make_order_confirmation_report(preorder, filename):

    s = ParagraphStyle(name="regular",
                       fontName='Helvetica',
                       fontSize=11,
                       spaceAfter=6)

    horsedoc = HorseDocument()
    horsedoc.add_paragraph(preorder.customer.fullname, s)
    horsedoc.add_paragraph(preorder.customer.address1, s)
    horsedoc.add_paragraph(preorder.customer.address2, s)
    horsedoc.add_paragraph(preorder.customer.country, s)
    horsedoc.next_frame()

    horsedoc.add_paragraph(
        _("We have well received your order {} and thank you heartily."))

    # Header frame

    title = ""
    if preorder.customer_order_name:
        title = _("Confirmation of order {}, your ref. : {}").format(
            preorder.preorder_label or "-",
            escape_html(preorder.customer_order_name))
    else:
        title = _("Confirmation of order {}").format(preorder.preorder_label
                                                     or "-")

    horsedoc.append_header_block(title)

    # Introduction text

    # intro = preorder.preorder_print_note or ""
    # horsedoc.add_paragraph(intro,s)
    # horsedoc.add_vertical_spacer()

    # Well, by combining a MIDDLE VALIGN and a leading=20, I can get the
    # paragraph to be right in the middle of the cell (vertically speaking)
    # It doesn't make sense to me, it's pure trial and error...

    data_ops = []

    # getcontext().prec = 2

    for part in preorder.parts:

        data_ops.append([
            part.human_identifier, part.description, part.qty, part.sell_price,
            part.qty * part.sell_price
        ])

    horsedoc.add_table([
        _(u'Reference'),
        _(u'Designation'),
        _('Quantity'),
        _('Unit Price'),
        _('Price')
    ], data_ops, [2 * cm, 8 * cm, 2 * cm, 3 * cm, 3 * cm], [
        NoFormatter(),
        NoFormatter(),
        IntegerFormatter(),
        MoneyFormatter(),
        MoneyFormatter()
    ])

    # footer = preorder.preorder_print_note_footer or ""
    # horsedoc.add_paragraph(footer,s)

    # complete_document.append(spacer)
    # p = Paragraph(_("This is a preorder."),s)
    # complete_document.append(p)

    horsedoc.add_signature()
    horsedoc.add_general_conditions()

    ladderDoc = customer_PDF(filename)
    ladderDoc.subject = date_to_dmy(
        datetime.today(), full_month=True)  # or preorder.creation_date ?
    ladderDoc.build(horsedoc.complete_document, canvasmaker=NumberedCanvas)
Ejemplo n.º 12
0
 def format(self, d):
     return Paragraph(date_to_dmy(d), self.column_style)
Ejemplo n.º 13
0
def print_order_report(dao, order_id, test_mode=False):
    global header_text,sub_header_text

    mainlog.debug('print_order_report order_id={}'.format(order_id))

    o = dao.order_dao.find_by_id(order_id)

    header_text = u"{} [{}]".format(o.customer.fullname, o.customer_order_name)
    sub_header_text = u"Mode op\u00E9ratoire"

    big_order_nr = ParagraphStyle(name = "subtitle", fontName = 'Helvetica-Bold', fontSize=24, leading=26)

    topstyle = ParagraphStyle(name = "zou", fontName = 'Helvetica', fontSize=16)

    p = platypus.Paragraph(u"<b>Client {}, commande #{}</b>".format(o.customer.customer_id,o.accounting_label),topstyle)
    spacer = platypus.Spacer(1,50)

    centered = ParagraphStyle(name = "zou", fontName = 'Helvetica-bold', alignment=TA_CENTER, fontSize=14) #, borderWidth=1, borderColor=colors.black)
    s = ParagraphStyle(name = "zou", fontName = 'Helvetica', fontSize=14, leading=16) #, borderWidth=1, borderColor=colors.black)
    page_number_style = ParagraphStyle(name = "page_number_style", fontName = 'Helvetica', alignment=TA_RIGHT, fontSize=12, leading=12) #, borderWidth=1, borderColor=colors.black)
    opNumberStyle = ParagraphStyle(name = "zou", fontName = 'Helvetica-bold', alignment=TA_CENTER, fontSize=28,leading=28) #, borderWidth=1, borderColor=colors.black)
    complete_document = []

    global satisfied
    satisfied = False
    sections.clear()
    headings_frame = HeadingsFrame(*basic_frame_dimensions)
    # complete_document.append(DocAssign("i",0))

    for part in o.parts:

        # Build up a table with accompanying style

        # data_ops = [ ['Poste',None,u'Op\u00E9ration',None] ]

        # We build up a data model and the appropriate styling information

        titles_row = []

        if part.production_file and len(part.production_file[0].operations) > 0:

            data_ops = [[Paragraph(part.human_identifier,big_order_nr),
                         Paragraph(escape_html(part.description),subtitle_style)],
                        [SubSectionNumber(part.human_identifier, page_number_style),
                         Paragraph(_("Quantity : {} - Deadline: {}").format(part.qty, date_to_dmy(part.deadline)),subtitle_style)]]

            ts = platypus.TableStyle()
            ts.add('GRID',(0,0),(-1,-1),0.5,colors.black)
            ts.add('VALIGN', (0, 0), (-1, -1), 'TOP')
            ts.add('ALIGN', (0, 1), (-1, 1), 'RIGHT')


            start_mark = PageMarker()
            complete_document.append( start_mark)

            header_maker = HeaderMaker(data_ops, ts, col_widths=compute_strut([3.8*cm, None], A4[0]-1*cm))
            complete_document.append(HeaderSetter( header_maker))

            operation_ndx = 1
            for op in part.production_file[0].operations:
                complete_document.append(
                    KeepTogether( [
                        make_boxes(operation_ndx, op, test_mode),
                        platypus.Spacer(1,0.1*cm) ] ))

                operation_ndx += 1

            end_mark = PageMarker()
            complete_document.append( end_mark)
            sections[part.human_identifier] = (start_mark, end_mark)

            complete_document.append(HeaderSetter(None))
            complete_document.append(PageBreak())
            # complete_document.append(platypus.Spacer(1,30))

    session().close() # FIXME Dirty

    if len(complete_document) > 0:
        filename = make_pdf_filename("OrderAndParts_{}_".format(order_id))
        ladderDoc = basic_PDF(filename,body_frame=headings_frame)
        ladderDoc.subject = u"Mode op\u00E9ratoire"
        ladderDoc.title = u"Client {}".format(o.customer.customer_id)

        ladderDoc.multiBuild(complete_document,canvasmaker=NumberedCanvas)
        open_pdf(filename)
        return True
    else:
        raise ServerException( ServerErrors.printing_an_empty_report)
Ejemplo n.º 14
0
def print_one_part(part,complete_document):
    # Build up a table with accompanying style

    # data_ops = [ ['Poste',None,u'Op\u00E9ration',None] ]

    # We build up a data model and the appropriate styling information

    big_order_nr = ParagraphStyle(name = "subtitle", fontName = 'Helvetica-Bold', fontSize=24, leading=26)
    subtitle = ParagraphStyle(name = "subtitle", fontName = 'Helvetica-Bold', fontSize=18, leading=20)
    s = ParagraphStyle(name = "zou", fontName = 'Helvetica', fontSize=14, leading=16) #, borderWidth=1, borderColor=colors.black)
    opNumberStyle = ParagraphStyle(name = "zou", fontName = 'Helvetica-bold', alignment=TA_CENTER, fontSize=28,leading=28) #, borderWidth=1, borderColor=colors.black)
    centered = ParagraphStyle(name = "zou", fontName = 'Helvetica-bold', alignment=TA_CENTER, fontSize=14) #, borderWidth=1, borderColor=colors.black)

    titles_row = []

    if part.production_file and len(part.production_file[0].operations) > 0:

        # print part.description
        # print len(part.production_file[0].operations)

        data_ops = [[Paragraph(part.human_identifier,big_order_nr),
                     Paragraph(crlf_to_br(part.description),subtitle)],
                    [None,
                     Paragraph(_("Quantity : {} - Deadline: {}").format(part.qty, date_to_dmy(part.deadline)),subtitle)]]
        t = platypus.Table(data_ops, repeatRows=0, colWidths=[3*cm, 19.5*cm - 3*cm])
        ts = platypus.TableStyle()
        ts.add('GRID',(0,0),(-1,-1),0.5,colors.black)
        ts.add('VALIGN', (0, 0), (-1, -1), 'TOP')
        ts.add('ALIGN', (0, 0), (1, -1), 'RIGHT')
        t.setStyle(ts)
        complete_document.append(t)

        # desc = u"<u>{}</u> {}".format(part.human_identifier,crlf_to_br(part.description))
        # complete_document.append(Paragraph(desc,subtitle))
        complete_document.append(platypus.Spacer(1,30))

        data_ops = [ ]
        ts = platypus.TableStyle()
        operation_ndx = 1
        for op in part.production_file[0].operations:

            if op.operation_model and op.operation_model.description:
                model = Paragraph(op.operation_model.short_id,centered)
            else:
                model = None

            if op.operation_model and op.operation_model.imputable:
                code = BarCodeIdentifier.code_for(op)
                barcode = createBarcodeDrawing('EAN13',value=str(code),width=6*cm,barHeight=2*cm)
                mainlog.debug("Barcode for {} is {}".format(op, code))
                graphic = GraphicalAnnotation(code,1*cm)
            else:
                barcode = None
                graphic = None

            full_desc = ""
            if op.description:
                full_desc = u"<b>{}</b> {}".format(escape_html(op.description), op.assignee.fullname)
            else:
                full_desc = "---"

            data_ops.append([Paragraph("{}".format(operation_ndx), opNumberStyle),
                             model,
                             None,
                             Paragraph(full_desc,s),
                             barcode, # barcode, graphic
                             graphic ])
            ts.add('LINEABOVE', (0, len(data_ops)-1), (-1, len(data_ops)-1), 0.5, colors.black)

            # if op.note and len(op.note) > 0:
            #     note = u"<b>Note:</b>{}".format(op.note.replace("\n","<br/>"))
            #     data_ops.append([None,None,Paragraph(note,s),None,None ])
            #     y = len(data_ops)-2
            #     ts.add('SPAN', (3,y), (4, y+1))
            operation_ndx += 1

        ts.add('GRID',(0,0),(1,-1),0.5,colors.black)
        ts.add('BOX',(0,0),(-1,-1),0.5,colors.black)
        ts.add('ALIGN', (0, 0), (1, -1), 'RIGHT')
        ts.add('ALIGN', (2, 0), (-1, -1), 'RIGHT')
        ts.add('VALIGN', (0, 0), (-1, -1), 'TOP')
        # ts.add('VALIGN', (0, 0), (0, -1), 'MIDDLE')

        ts.add('VALIGN', (4, 0), (4, -1), 'MIDDLE')
        ts.add('ALIGN',  (3, 0), (4, -1), 'RIGHT')

        ts.add("LEFTPADDING", (0, 0), (-1, -1), 0)
        ts.add("RIGHTPADDING", (0, 0), (2, -1), 0)
        ts.add("BOTTOMPADDING", (0, 0), (-1, -1), 0.75/2*cm)
        ts.add("TOPPADDING", (1, 0), (-1, -1), 0.25*cm) # .75/2*cm)
        ts.add('LINEABOVE', (0, 0), (-1, 0), 1, colors.black)
        ts.add('LINEBELOW', (0, len(data_ops)-1), (-1, len(data_ops)-1), 1, colors.black)

        t = platypus.Table(data_ops, repeatRows=0, colWidths=[1.5*cm,1.5*cm,0.5*cm,8.5*cm,6.5*cm,1*cm]) # Repeat the table header
        # t = platypus.Table(data_ops, repeatRows=1, colWidths=[3*cm,1*cm,0.5*cm,13*cm,1*cm,1*cm]) # Repeat the table header
        t.setStyle(ts)
Ejemplo n.º 15
0
def _make_supply_order(supply_order_id,filename):

    global header_text
    global sub_header_text

    s = ParagraphStyle(name = "regular", fontName = 'Helvetica', fontSize=12, spaceAfter=6)
    table_style = ParagraphStyle(name = "regular", fontName = 'Helvetica', fontSize=11, spaceAfter=6)
    signatures_style = ParagraphStyle(name = "signature", fontName = 'Helvetica', fontSize=12, alignment=TA_CENTER)
    warning_style = ParagraphStyle(name = "warning", fontName = 'Helvetica-Bold', fontSize=20, spaceAfter=6,alignment=TA_CENTER, borderWidth=2, borderColor=colors.black, leading=30)
    right_align = ParagraphStyle(name = "right_align", fontName = 'Helvetica', fontSize=12,alignment=TA_RIGHT)
    complete_document = []
    spacer = platypus.Spacer(1,1*cm)

    supply_order, parts = supply_order_service.find_by_id(supply_order_id)
    supplier = supplier_service.find_by_id(supply_order.supplier_id)

    p = Paragraph(escape_html(supplier.fullname),s)
    complete_document.append(p)
    p = Paragraph(escape_html(supplier.address1),s)
    complete_document.append(p)
    p = Paragraph(escape_html(supplier.address2),s)
    complete_document.append(p)

    complete_document.append(FrameBreak())


    append_header_block(complete_document,
                        _("Order number <b>{}</b>, your ref. : {}").format(supply_order.accounting_label,
                                                                        escape_html(supply_order.supplier_reference or '-')),
                        supply_order.creation_date)

    p = Paragraph(escape_html(_("Delivery date : {}").format(date_to_dmy(supply_order.expected_delivery_date))),s)
    complete_document.append(p)

    # Well, by combining a MIDDLE VALIGN and a leading=20, I can get the
    # paragraph to be right in the middle of the cell (vertically speaking)
    # It doesn't make sense to me, it's pure trial and error...

    subtitle = ParagraphStyle(name = "subtitle", fontName = 'Helvetica', fontSize=16, leading=20)

    p = Paragraph("",s)
    complete_document.append(p)
    complete_document.append(spacer)

    data_ops = [ [ _('Ref.'),'',_('Description'),'',_('Quantity'),'',_('Unit price') ] ]

    for part in parts:
        data_ops.append([Paragraph(escape_html(part.human_identifier),table_style),
                         None,
                         Paragraph(escape_html(part.description),table_style),
                         None,
                         Paragraph(u"{}".format(quantity_to_str(part.quantity)),table_style),
                         None,
                         Paragraph(u"{}".format(amount_to_s(part.unit_price,"-")),table_style)])


    t = platypus.Table(data_ops, repeatRows=1, colWidths=[1.25*cm,0.75*cm,10*cm,0.75*cm,2*cm,0.75*cm,2.5*cm]) # Repeat the table header

    ts = platypus.TableStyle([('FONT', (0, 0), (-1, -1), 'Helvetica-Bold', 12)])
    ts.add('ALIGN', (0, 0), (-1, -1), 'LEFT')
    ts.add('VALIGN', (0, 0), (-1, -1), 'TOP')

    ts.add("LEFTPADDING", (0, 0), (-1, -1), 0)
    ts.add("RIGHTPADDING", (0, 0), (-1, -1), 0)

    # This is the header row
    ts.add('LINEBELOW', (0, 0), (0, 0), 0.5, colors.black)
    ts.add('LINEBELOW', (2, 0), (2, 0), 0.5, colors.black)
    ts.add('LINEBELOW', (4, 0), (4, 0), 0.5, colors.black)
    ts.add('LINEBELOW', (6, 0), (6, 0), 0.5, colors.black)
    ts.add('VALIGN', (0, 0), (-1, 0), 'MIDDLE')

    # for row in titles_row:
    #     ts.add('FONT', (0, row), (-1, row), 'Helvetica', 10)

    t.setStyle(ts)
    complete_document.append(t)

    complete_document.append(spacer)
    data_ops = [ [ Paragraph(_("Daniel Dumont<br/>Administrateur delegue"),signatures_style),
                   Paragraph(_("Pierre Jodogne<br/>Superviseur de production"),signatures_style)] ]
    t = platypus.Table(data_ops, repeatRows=1, colWidths=[9*cm,9*cm]) # Repeat the table header
    ts = platypus.TableStyle([('FONT', (0, 0), (-1, -1), 'Helvetica-Bold', 12)])
    ts.add('ALIGN', (0, 0), (-1, -1), 'CENTER')
    t.setStyle(ts)
    complete_document.append(t)


    ladderDoc = customer_PDF(filename)
    ladderDoc.build(complete_document,canvasmaker=NumberedCanvas)