当前位置: 首页>>代码示例>>Python>>正文


Python BaseDocTemplate.fatture方法代码示例

本文整理汇总了Python中reportlab.platypus.doctemplate.BaseDocTemplate.fatture方法的典型用法代码示例。如果您正苦于以下问题:Python BaseDocTemplate.fatture方法的具体用法?Python BaseDocTemplate.fatture怎么用?Python BaseDocTemplate.fatture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reportlab.platypus.doctemplate.BaseDocTemplate的用法示例。


在下文中一共展示了BaseDocTemplate.fatture方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_to_reportlab

# 需要导入模块: from reportlab.platypus.doctemplate import BaseDocTemplate [as 别名]
# 或者: from reportlab.platypus.doctemplate.BaseDocTemplate import fatture [as 别名]
def render_to_reportlab(context):
    """
        In context dictionary we could have a 'fattura'
        or a list of fatture in 'fatture'.

        Everything will be appended to a pdf returned as Django response.

        To reset page counter between different invoices, we'll use
        2 "Normale" templates, one for even and one for odds, so every times
        the template changes we'll reset the NumberedCanvas
    """
    if "fattura" in context and "fatture" in context:
        raise Exception("Please create PDF choosing between a fattura or multiple fatture")
    if "fattura" in context:
        fatture = [context.get('fattura')]
    else:
        fatture = context.get('fatture')

    response = http.HttpResponse(content_type='application/pdf')
    NormalTemplates = ['Normale0', 'Normale1']

    fatture_rimanenti = len(fatture)
    story = []

    pageTemplates = [
        PageTemplate(id='Normale0', onPage=onPageNormal),
        PageTemplate(id='Normale1', onPage=onPageNormal),
        PageTemplate(id='ConducenteConsorzio', onPage=onPageConducenteConsorzio),
        PageTemplate(id='ConsorzioConducente', onPage=onPageConsorzioConducente),
    ]
    # scelgo il template della prima pagina come primo della lista
    if fatture[0].is_ricevuta_sdoppiata():
        lastTemplateID = 'ConducenteConsorzio'
        pageTemplates = pageTemplates[2:] + pageTemplates[:2]
    else:
        lastTemplateID = 'Normale0'

    width, height = portrait(A4)
    doc = BaseDocTemplate(
        response,
        pagesize=(width, height),
        leftMargin=1 * cm,
        rightMargin=1 * cm,
        bottomMargin=1.5 * cm,
        topMargin=1 * cm,
        showBoundary=test,
        pageTemplates=pageTemplates,
    )
    doc.fatture = fatture
    doc.lastTemplateID = lastTemplateID
    doc.fattura_corrente = 0

    for fattura in fatture:
        ricevutaMultipla = fattura.is_ricevuta_sdoppiata()
        story_fattura = []
        fatturazione = FATTURE_PER_TIPO[fattura.tipo]

        righeFattura = [
            ('Descrizione', 'Q.tà',) +
            (('Prezzo', 'IVA %') if FATTURE_SHOW_VAT_COLUMN else tuple()) +
            ('Importo',),
        ]

        righe = fattura.righe.all()

        raggruppa_barbatrucco = False
        if fatturazione.codice == "5":
            totale = sum([r.val_totale() for r in righe])
            conducente = righe[0].conducente if righe else None
            if "Imposta di bollo" not in [r.descrizione for r in righe]:
                if not (totale < settings.MIN_PRICE_FOR_TAXSTAMP
                        and (conducente is None or conducente.emette_ricevute)
                ):
                    raggruppa_barbatrucco = True

        if raggruppa_barbatrucco:
            # print "5 esente iva con barbatrucco"

            netto = totale / Decimal(1.1)

            class RigaTotaleIvata(object):  # una riga che fa corrispondere il totale
                descrizione = "Servizi per consorzio."
                note = None
                qta = 1
                prezzo = netto
                iva = 10

                def val_imponibile(self):
                    return self.prezzo

                def val_iva(self):
                    return totale - netto

                def val_totale(self):
                    return totale

            riga = RigaTotaleIvata()
            # la fattura ha totale pari al totale di tutte le righe
            # l'iva è fissa al 10% e il netto è calcolato di conseguenza
            imponibile = netto
#.........这里部分代码省略.........
开发者ID:dariosky,项目名称:tam,代码行数:103,代码来源:pdf.py


注:本文中的reportlab.platypus.doctemplate.BaseDocTemplate.fatture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。