Beispiel #1
0
def make_operation_boxes(operation_ndx, op, opNumberStyle):
    s = ParagraphStyle(name = "zou", fontName = 'Helvetica', fontSize=12) #, borderWidth=1, borderColor=colors.black)
    centered = ParagraphStyle(name = "zou", fontName = 'Helvetica-bold', fontSize=14) #, borderWidth=1, borderColor=colors.black) alignment=TA_CENTER,

    operation_number = Paragraph("{}".format(operation_ndx), opNumberStyle)

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

    if op.operation_model and op.operation_model.imputable:
        code = BarCodeIdentifier.code_for(op)
        # humanReadable : remove the numbers under the barcode
        barcode = createBarcodeDrawing('EAN13',value=str(code),width=4*cm,barHeight=1*cm,humanReadable=False)
        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(crlf_to_br(op.description))
        assignee = ''
        if op.assignee:
            assignee = op.assignee.fullname
        full_desc = u"<b>{}</b><br/>{}".format(escape_html(op.description), escape_html(assignee))
    else:
        full_desc = "---"

    data_ops = [[operation_number,
                 barcode,
                 model,
                 Paragraph(full_desc,s)]]
    t = platypus.Table(data_ops, repeatRows=0, colWidths=compute_strut( [1.5*cm, 4.5*cm, 1.5*cm, None], 19.5*cm) )
    ts = platypus.TableStyle()

    # ts.add('LINEABOVE', (0, len(data_ops)-1), (-1, len(data_ops)-1), 0.5, colors.black)
    ts.add('GRID',(0,0),(-1,-1),0.5,colors.black)
    ts.add('LINEBEFORE', (0, 0), (0, -1), 1, colors.black)
    ts.add('LINEAFTER', (-1, 0), (-1, -1), 1, colors.black)
    ts.add('LINEABOVE', (0, 0), (-1, 0), 1, colors.black)
    ts.add('LINEBELOW', (0, 0), (-1, 0), 0, colors.white)
    ts.add('VALIGN', (2, 0), (-1, -1), 'TOP')
    t.setStyle(ts)

    return t
Beispiel #2
0
def _make_delivery_slip(dao, slip_id, filename):

    global header_text
    global sub_header_text

    s = ParagraphStyle(name="regular",
                       fontName='Helvetica',
                       fontSize=12,
                       spaceAfter=6)
    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)

    slip = dao.delivery_slip_part_dao.find_by_id(slip_id)
    order = slip.delivery_slip_parts[0].order_part.order
    c = order.customer

    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)

    complete_document.append(FrameBreak())

    append_header_block(
        complete_document,
        _("Delivery slip <b>{}</b>").format(slip.delivery_slip_id),
        slip.creation)

    # 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)

    if not slip.active:
        p = Paragraph(_("!!! This delivery slip has been DEACTIVATED !!!"),
                      warning_style)
        complete_document.append(p)
        complete_document.append(spacer)

    p = Paragraph(
        _("Order number <b>{}</b>").format(order.customer_order_name), s)
    complete_document.append(p)
    complete_document.append(spacer)

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

    for part in sorted(slip.delivery_slip_parts,
                       key=lambda p: p.order_part.position):
        data_ops.append([
            Paragraph("<b>{}</b>".format(part.order_part.human_identifier), s),
            None,
            Paragraph(u"{}".format(escape_html(part.order_part.description)),
                      s), None,
            Paragraph(u"{}".format(int(part.quantity_out)), s)
        ])

    session().close()
    t = platypus.Table(data_ops,
                       repeatRows=1,
                       colWidths=[2 * cm, 1 * cm, 10 * cm, 1 * cm,
                                  3 * 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('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)
    p = Paragraph(
        _(u"Sauf avis contraire stipule ci-dessus, les marchandises circulent aux<br/> frais du delivery_slips et a ses risques et perils."
          ), s)
    complete_document.append(p)
    p = Paragraph(_(u"Les frais de port seront portes en facture."), s)
    complete_document.append(p)

    complete_document.append(spacer)

    data_ops = [[
        Paragraph(_("Signature :"), s),
        Paragraph(_("Reception date :"), s)
    ]]
    t = platypus.Table(data_ops,
                       repeatRows=1,
                       colWidths=[(A4[0] - 3 * cm) / 2, (A4[0] - 3 * cm) / 2
                                  ])  # Repeat the table header
    complete_document.append(t)

    # append_general_conditions(complete_document)

    ladderDoc = customer_PDF(filename)
    ladderDoc.build(complete_document, canvasmaker=NumberedCanvas)
Beispiel #3
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)
Beispiel #4
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
Beispiel #5
0
 def add_paragraph(self, txt, style):
     p = Paragraph(escape_html(txt), style)
     self.complete_document.append(p)
Beispiel #6
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)
Beispiel #7
0
 def format(self, s):
     return Paragraph(escape_html(str(s)), self.column_style)
Beispiel #8
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)
Beispiel #9
0
def make_boxes(operation_ndx, op, test_mode=False):
    s = ParagraphStyle(name = "Regular", fontName = 'Helvetica', fontSize=12) #, borderWidth=1, borderColor=colors.black)
    c = ParagraphStyle(name = "Centered", fontName = 'Helvetica', alignment=TA_CENTER, fontSize=12) #, borderWidth=1, borderColor=colors.black)

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

    barcode_width = 3*cm
    if op.operation_model and op.operation_model.imputable:
        code = BarCodeIdentifier.code_for(op)
        # humanReadable : remove the numbers under the barcode
        barcode = createBarcodeDrawing('EAN13',value=str(code),width=barcode_width,barHeight=1*cm,humanReadable=False)
        mainlog.debug("Barcode for {} is {}".format(op, code))
    else:
        barcode = None


    full_desc = ""
    if op.description:
        # full_desc = u"<b>{}</b>".format(crlf_to_br(op.description))
        assignee = ''
        if op.assignee:
            assignee = op.assignee.fullname
        full_desc = escape_html(op.description)

        if test_mode and operation_ndx % 2 == 1:
            full_desc = LOREM_IPSUM[0:len(op.description)]

    else:
        full_desc = "---"

    op_ndx = "{:02}".format(operation_ndx)

    data_ops = [[ Paragraph(op_ndx,c),    model,                   barcode,            None,   Paragraph("Stop",c), Paragraph("Val1",c), Paragraph("Descriptif / remarque",c), None,   Paragraph("Acc",c), Paragraph("Ref",c), Paragraph("Val2",c), Paragraph("Mac",c)],
                [ "",                     "",                      "",                 None,   "",                  "",                  "",                                   None,   "",                 "",                 "",                  ""],
                [ Paragraph(full_desc,s), "",                      "",                 None,   "",                  "",                  "",                                   None,   "",                 "",                 "",                  ""]]

    # 1.16 = EAN13 quiet zone proportion
    col_widths= [ 0.8*cm,                 0.8*cm,                  barcode_width*1.16, 0.1*cm, 1.5*cm,              1.5*cm,              None,                                 0.1*cm, 1.1*cm,             1.1*cm,             1.5*cm,              1.1*cm]

    t = platypus.Table(data_ops, repeatRows=0, colWidths=compute_strut( col_widths, 19.5*cm) )

    ts = platypus.TableStyle()

    # Tuples are (x,y)
    ts.add('BOX',(0,0),(-1,-1),1,colors.black)
    ts.add('LINEBELOW', (4, 0), (-1, 0), 0.5, colors.black)
    # Two inner grids not to overwrite the fine linebelow
    ts.add('INNERGRID',(0,0),(-1,0),1,colors.black)
    ts.add('INNERGRID',(0,1),(-1,1),1,colors.black)
    ts.add('BOX',(0,2),(-1,2),1,colors.black)

    ts.add('ALIGN',(0,0),(-1,0),"CENTER")
    ts.add('VALIGN',(0,0),(2,0),"MIDDLE")

    # First row vertical spans
    ts.add('SPAN',(0,0),(0,1))
    ts.add('LEFTPADDING',(0,0),(-1,0),0)
    ts.add('RIGHTPADDING',(0,0),(-1,0),0)

    ts.add('SPAN',(1,0),(1,1))
    ts.add('SPAN',(2,0),(2,1))

    # Separators
    ts.add('SPAN',(3,0),(3,1))
    ts.add('SPAN',(7,0),(7,1))

    ts.add('LEADING', (0, 1), (-1, 1), 1.4*cm) # Sets the row height

    # ts.add('LINEBEFORE', (3, 0), (3, 1), 1, colors.black)
    # ts.add('LINEBEFORE', (7, 0), (7, 1), 1, colors.black)

    ts.add('TOPPADDING',(4,0),(-1,0),0)
    ts.add('BOTTOMPADDING',(4,0),(-1,0),3)

    # Last row horizontal span
    ts.add('SPAN',(0,2),(-1,2))
    ts.add('TOPPADDING',(0,2),(-1,2),6)
    ts.add('BOTTOMPADDING',(0,2),(-1,2),12)

    t.setStyle(ts)

    return t
Beispiel #10
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)
Beispiel #11
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)