Exemplo n.º 1
0
def gen_declaration(invoice, target_folder, copyt, serialno):
    """
    Generates a copy of the Customs Declaration for Imports.

    :param invoice: The invoice object with customs information
    :type invoice: :class:`tendril.sourcing.customs.CustomsInvoice`
    :param target_folder: The folder in which the generated files
                          should be written to
    :param copyt: A string specifying which copy it is ("ORIGINAL",
                  "DUPLICATE", so on)
    :type copyt: str
    :param serialno: The serial number of the Customs documentation set
    :type serialno: str
    :return: The output file path

    .. rubric:: Template Used

    ``tendril/dox/templates/customs/decl.tex``
    (:download:`Included version
    <../../tendril/dox/templates/customs/decl.tex>`)

    .. rubric:: Stage Keys Provided
    .. list-table::

        * - ``date``
          - The date the documents were generated at, from
            :func:`datetime.date.today`.
        * - ``signatory``
          - The name of the person who 'signs' the document, from
            :data:`tendril.utils.config.COMPANY_GOVT_POINT`.
        * - ``inv_no``
          - The vendor's invoice number.
        * - ``inv_date``
          - The date of the vendor's invoice.
        * - ``given_data``
          - A dict containing various facts about the invoice. See
            :attr:`tendril.sourcing.customs.CustomsInvoice.given_data`
        * - ``currency``
          - The symbol of the currency of the invoice.
        * - ``inv_total``
          - The total value of the invoice, in vendor currency.
        * - ``exchrate``
          - The applicable exchange rate.
        * - ``exchnotif``
          - The government notification number specifying the exchange rate.
        * - ``exchnotifdt``
          - The date of the exchange rate notification.
        * - ``extended_total_sc``
          - The extended total invoice value, in the vendor's currency.
        * - ``assessable_total_sc``
          - The assessable total invoice value, in the vendor's currency.
        * - ``assessable_total_nc``
          - The assessable total invoice value, in the vendor's currency.
        * - ``copyt``
          - The string specifying which copy it is.
        * - ``sno``
          - The serial number of the document.

    """
    outpath = os.path.join(
        target_folder,
        "customs-declaration-" + copyt + '-' + str(invoice.inv_no) + ".pdf"
    )

    given_data = copy.deepcopy(invoice.given_data)

    for k, v in given_data['costs_not_included'].iteritems():
        given_data['costs_not_included'][k] = render.escape_latex(v)

    stage = {'date': datetime.date.today().isoformat(),
             'signatory': COMPANY_GOVT_POINT,
             'inv_no': invoice.inv_no,
             'inv_date': invoice.inv_date,
             'given_data': given_data,
             'currency': render.escape_latex(invoice.currency.symbol),
             'inv_total':
             render.escape_latex(invoice.extendedtotal.source_string),
             'exchrate': invoice.given_data['exchrate'],
             'exchnotif': invoice.given_data['exchnotif'],
             'exchnotifdt': invoice.given_data['exchnotif_date'],
             'extended_total_sc':
             render.escape_latex(invoice.extendedtotal.source_string),
             'assessable_total_sc':
             render.escape_latex(invoice.assessabletotal.source_string),
             'assessable_total_nc':
             render.escape_latex(invoice.assessabletotal.native_string),
             'copyt': copyt,
             'sno': serialno + '.5'
             }

    return render.render_pdf(stage, 'customs/decl.tex', outpath)
Exemplo n.º 2
0
def gen_tech_writeup(invoice, target_folder, serialno):
    """
    Generates the Customs Technical Writeup.

    :param invoice: The invoice object with customs information
    :type invoice: :class:`tendril.sourcing.customs.CustomsInvoice`
    :param target_folder: The folder in which the generated files
                          should be written to
    :param serialno: The serial number of the Customs documentation set
    :type serialno: str
    :return: The output file path

    .. rubric:: Template Used

    Template Filename :
    ``tendril/dox/templates/customs/technical-writeup.tex``
    (:download:`Included version
    <../../tendril/dox/templates/customs/technical-writeup.tex>`)

    .. rubric:: Stage Keys Provided
    .. list-table::

        * - ``date``
          - The date the documents were generated at,
            from :func:`datetime.date.today`.
        * - ``signatory``
          - The name of the person who 'signs' the document, from
            :data:`tendril.utils.config.COMPANY_GOVT_POINT`.
        * - ``inv_no``
          - The vendor's invoice number.
        * - ``inv_date``
          - The date of the vendor's invoice.
        * - ``given_data``
          - A dict containing various facts about the invoice. See
            :attr:`tendril.sourcing.customs.CustomsInvoice.given_data`
        * - ``sno``
          - The serial number of the document.
        * - ``linecount``
          - The number of lines in the invoice.
        * - ``tqty``
          - The total quantity.
        * - ``tvalue``
          - The total value.
        * - ``unclassified``
          - Lines in the invoice which could not be classified
        * - ``sectable``
          - The secion table, containing a list of ``section lines``,
            described below. The 'sections' here are Customs HS Codes.

    .. list-table:: Section line keys

        * - ``code``
          - The HS section code.
        * - ``name``
          - The HS section name.
        * - ``idxs``
          - Line numbers classified into this line.
        * - ``qty``
          - Total quantity of all lines classified into this line.
        * - ``value``
          - Total value of all lines classified into this line.

    """
    outpath = os.path.join(
        target_folder,
        "customs-tech-writeup-" + str(invoice.inv_no) + ".pdf"
    )
    sectable = []
    tqty = 0
    tvalue = 0
    for section in invoice.hssections:
        lval = invoice.getsection_assessabletotal(section).source_string
        secline = {'code': section.code,
                   'name': section.name,
                   'idxs': invoice.getsection_idxs(section),
                   'qty': invoice.getsection_qty(section),
                   'value': render.escape_latex(lval)
                   }
        sectable.append(secline)
        tqty += invoice.getsection_qty(section)
        tvalue += invoice.getsection_assessabletotal(section)

    unclassified = {'idxs': [x.idx for x in invoice.unclassified],
                    'qty': sum([x.qty for x in invoice.unclassified]),
                    }
    if unclassified['qty'] > 0:
        unclassified['value'] = \
            render.escape_latex(
                sum([x.assessableprice
                     for x in invoice.unclassified]).source_string)
        tvalue += sum([x.assessableprice for x in invoice.unclassified])
        tqty += unclassified['qty']
    else:
        unclassified['value'] = None

    stage = {'date': datetime.date.today().isoformat(),
             'signatory': COMPANY_GOVT_POINT,
             'inv_no': invoice.inv_no,
             'inv_date': invoice.inv_date,
             'given_data': invoice.given_data,
             'linecount': invoice.linecount,
             'sectable': sectable,
             'tqty': tqty,
             'tvalue': render.escape_latex(tvalue.source_string),
             'unclassified': unclassified,
             'sno': serialno + '.4'
             }
    return render.render_pdf(stage, 'customs/technical-writeup.tex', outpath)
Exemplo n.º 3
0
def gen_valuation(invoice, target_folder, serialno):
    """
    Generates the Customs Valuation Note.

    :param invoice: The invoice object with customs information
    :type invoice: :class:`tendril.sourcing.customs.CustomsInvoice`
    :param target_folder: The folder in which the generated files
                          should be written to
    :param serialno: The serial number of the Customs documentation set
    :type serialno: str
    :return: The output file path

    .. rubric:: Template Used

    ``tendril/dox/templates/customs/valuation.tex``
    (:download:`Included version
    <../../tendril/dox/templates/customs/valuation.tex>`)

    .. rubric:: Stage Keys Provided
    .. list-table::

        * - ``date``
          - The date the documents were generated at, from
            :func:`datetime.date.today`.
        * - ``signatory``
          - The name of the person who 'signs' the document, from
            :data:`tendril.utils.config.COMPANY_GOVT_POINT`.
        * - ``inv_no``
          - The vendor's invoice number.
        * - ``inv_date``
          - The date of the vendor's invoice.
        * - ``given_data``
          - A dict containing various facts about the invoice. See
            :attr:`tendril.sourcing.customs.CustomsInvoice.given_data`
        * - ``currency``
          - The symbol of the currency of the invoice.
        * - ``inv_total``
          - The total value of the invoice, in vendor currency.
        * - ``exchrate``
          - The applicable exchange rate.
        * - ``exchnotif``
          - The government notification number specifying the exchange rate.
        * - ``exchnotifdt``
          - The date of the exchange rate notification.
        * - ``note1``
          - A note mentioning the inclusion of freight.
        * - ``note2``
          - A list of strings mentioning other additions to the valuation.
        * - ``include_note2``
          - Boolean, whether or not to include note2.
        * - ``extended_total_sc``
          - The extended total invoice value, in the vendor's currency.
        * - ``assessable_total_sc``
          - The assessable total invoice value, in the vendor's currency.
        * - ``assessable_total_nc``
          - The assessable total invoice value, in the vendor's currency.
        * - ``copyt``
          - The string specifying which copy it is.
        * - ``sno``
          - The serial number of the document.
        * - ``is_wire``
          - Bool, whether the payment was made by a wire transfer.

    """
    outpath = os.path.join(
        target_folder,
        "customs-valuation-" + str(invoice.inv_no) + ".pdf"
    )

    note1 = ''
    if invoice.includes_freight is True:
        note1 += "As listed in the invoice, {0} towards freight " \
                 "is also added. ".format(invoice.freight.source_string)
    note1 = render.escape_latex(note1)

    note2 = []

    if invoice.added_insurance is True:
        note2.append(
            "An additional {0}% of FOB is added to the assessable value "
            "as per Rule 10(2)(c)(iii) of Customs Valuation "
            "(Determination of Value of Imported Goods) Rules, 2007. "
            "No specific insurance charges were paid as part of the"
            " transaction.".format(invoice.insurance_pc)
        )
    if invoice.added_handling is True:
        note2.append(
            "An additional {0}% of CIF is added to the assessable value "
            "as per Rule 10(2)(b)(ii) of Customs Valuation "
            "(Determination of Value of Imported Goods) Rules, 2007. "
            "No specific handling charges were paid as part of the"
            " transaction.".format(invoice.handling_pc)
        )

    include_note2 = False
    if len(note2) > 0:
        include_note2 = True
    if invoice.given_data['bank_ref'] is None:
        is_wire = False
    else:
        is_wire = True

    stage = {'date': datetime.date.today().isoformat(),
             'signatory': COMPANY_GOVT_POINT,
             'inv_no': invoice.inv_no,
             'inv_date': invoice.inv_date,
             'given_data': invoice.given_data,
             'currency': render.escape_latex(invoice.currency.symbol),
             'inv_total':
             render.escape_latex(invoice.extendedtotal.source_string),
             'exchrate': invoice.given_data['exchrate'],
             'exchnotif': invoice.given_data['exchnotif'],
             'exchnotifdt': invoice.given_data['exchnotif_date'],
             'note1': note1,
             'note2': note2,
             'include_note2': include_note2,
             'extended_total_sc':
             render.escape_latex(invoice.extendedtotal.source_string),
             'assessable_total_sc':
             render.escape_latex(invoice.assessabletotal.source_string),
             'assessable_total_nc':
             render.escape_latex(invoice.assessabletotal.native_string),
             'sno': serialno + '.3',
             'is_wire': is_wire
             }

    return render.render_pdf(stage, 'customs/valuation.tex', outpath)
Exemplo n.º 4
0
def gen_declaration(invoice, target_folder, copyt, serialno):
    """
    Generates a copy of the Customs Declaration for Imports.

    :param invoice: The invoice object with customs information
    :type invoice: :class:`tendril.sourcing.customs.CustomsInvoice`
    :param target_folder: The folder in which the generated files
                          should be written to
    :param copyt: A string specifying which copy it is ("ORIGINAL",
                  "DUPLICATE", so on)
    :type copyt: str
    :param serialno: The serial number of the Customs documentation set
    :type serialno: str
    :return: The output file path

    .. rubric:: Template Used

    ``tendril/dox/templates/customs/decl.tex``
    (:download:`Included version
    <../../tendril/dox/templates/customs/decl.tex>`)

    .. rubric:: Stage Keys Provided
    .. list-table::

        * - ``date``
          - The date the documents were generated at, from
            :func:`datetime.date.today`.
        * - ``signatory``
          - The name of the person who 'signs' the document, from
            :data:`tendril.utils.config.COMPANY_GOVT_POINT`.
        * - ``inv_no``
          - The vendor's invoice number.
        * - ``inv_date``
          - The date of the vendor's invoice.
        * - ``given_data``
          - A dict containing various facts about the invoice. See
            :attr:`tendril.sourcing.customs.CustomsInvoice.given_data`
        * - ``currency``
          - The symbol of the currency of the invoice.
        * - ``inv_total``
          - The total value of the invoice, in vendor currency.
        * - ``exchrate``
          - The applicable exchange rate.
        * - ``exchnotif``
          - The government notification number specifying the exchange rate.
        * - ``exchnotifdt``
          - The date of the exchange rate notification.
        * - ``extended_total_sc``
          - The extended total invoice value, in the vendor's currency.
        * - ``assessable_total_sc``
          - The assessable total invoice value, in the vendor's currency.
        * - ``assessable_total_nc``
          - The assessable total invoice value, in the vendor's currency.
        * - ``copyt``
          - The string specifying which copy it is.
        * - ``sno``
          - The serial number of the document.

    """
    outpath = os.path.join(
        target_folder,
        "customs-declaration-" + copyt + '-' + str(invoice.inv_no) + ".pdf"
    )

    given_data = copy.deepcopy(invoice.given_data)

    for k, v in given_data['costs_not_included'].iteritems():
        given_data['costs_not_included'][k] = render.escape_latex(v)

    stage = {'date': datetime.date.today().isoformat(),
             'signatory': COMPANY_GOVT_POINT,
             'inv_no': invoice.inv_no,
             'inv_date': invoice.inv_date,
             'given_data': given_data,
             'currency': render.escape_latex(invoice.currency.symbol),
             'inv_total':
             render.escape_latex(invoice.extendedtotal.source_string),
             'exchrate': invoice.given_data['exchrate'],
             'exchnotif': invoice.given_data['exchnotif'],
             'exchnotifdt': invoice.given_data['exchnotif_date'],
             'extended_total_sc':
             render.escape_latex(invoice.extendedtotal.source_string),
             'assessable_total_sc':
             render.escape_latex(invoice.assessabletotal.source_string),
             'assessable_total_nc':
             render.escape_latex(invoice.assessabletotal.native_string),
             'copyt': copyt,
             'sno': serialno + '.5'
             }

    return render.render_pdf(stage, 'customs/decl.tex', outpath)
Exemplo n.º 5
0
def gen_tech_writeup(invoice, target_folder, serialno):
    """
    Generates the Customs Technical Writeup.

    :param invoice: The invoice object with customs information
    :type invoice: :class:`tendril.sourcing.customs.CustomsInvoice`
    :param target_folder: The folder in which the generated files
                          should be written to
    :param serialno: The serial number of the Customs documentation set
    :type serialno: str
    :return: The output file path

    .. rubric:: Template Used

    Template Filename :
    ``tendril/dox/templates/customs/technical-writeup.tex``
    (:download:`Included version
    <../../tendril/dox/templates/customs/technical-writeup.tex>`)

    .. rubric:: Stage Keys Provided
    .. list-table::

        * - ``date``
          - The date the documents were generated at,
            from :func:`datetime.date.today`.
        * - ``signatory``
          - The name of the person who 'signs' the document, from
            :data:`tendril.utils.config.COMPANY_GOVT_POINT`.
        * - ``inv_no``
          - The vendor's invoice number.
        * - ``inv_date``
          - The date of the vendor's invoice.
        * - ``given_data``
          - A dict containing various facts about the invoice. See
            :attr:`tendril.sourcing.customs.CustomsInvoice.given_data`
        * - ``sno``
          - The serial number of the document.
        * - ``linecount``
          - The number of lines in the invoice.
        * - ``tqty``
          - The total quantity.
        * - ``tvalue``
          - The total value.
        * - ``unclassified``
          - Lines in the invoice which could not be classified
        * - ``sectable``
          - The secion table, containing a list of ``section lines``,
            described below. The 'sections' here are Customs HS Codes.

    .. list-table:: Section line keys

        * - ``code``
          - The HS section code.
        * - ``name``
          - The HS section name.
        * - ``idxs``
          - Line numbers classified into this line.
        * - ``qty``
          - Total quantity of all lines classified into this line.
        * - ``value``
          - Total value of all lines classified into this line.

    """
    outpath = os.path.join(
        target_folder,
        "customs-tech-writeup-" + str(invoice.inv_no) + ".pdf"
    )
    sectable = []
    tqty = 0
    tvalue = 0
    for section in invoice.hssections:
        lval = invoice.getsection_assessabletotal(section).source_string
        secline = {'code': section.code,
                   'name': section.name,
                   'idxs': invoice.getsection_idxs(section),
                   'qty': invoice.getsection_qty(section),
                   'value': render.escape_latex(lval)
                   }
        sectable.append(secline)
        tqty += invoice.getsection_qty(section)
        tvalue += invoice.getsection_assessabletotal(section)

    unclassified = {'idxs': [x.idx for x in invoice.unclassified],
                    'qty': sum([x.qty for x in invoice.unclassified]),
                    }
    if unclassified['qty'] > 0:
        unclassified['value'] = \
            render.escape_latex(
                sum([x.assessableprice
                     for x in invoice.unclassified]).source_string)
        tvalue += sum([x.assessableprice for x in invoice.unclassified])
        tqty += unclassified['qty']
    else:
        unclassified['value'] = None

    stage = {'date': datetime.date.today().isoformat(),
             'signatory': COMPANY_GOVT_POINT,
             'inv_no': invoice.inv_no,
             'inv_date': invoice.inv_date,
             'given_data': invoice.given_data,
             'linecount': invoice.linecount,
             'sectable': sectable,
             'tqty': tqty,
             'tvalue': render.escape_latex(tvalue.source_string),
             'unclassified': unclassified,
             'sno': serialno + '.4'
             }
    return render.render_pdf(stage, 'customs/technical-writeup.tex', outpath)
Exemplo n.º 6
0
def gen_valuation(invoice, target_folder, serialno):
    """
    Generates the Customs Valuation Note.

    :param invoice: The invoice object with customs information
    :type invoice: :class:`tendril.sourcing.customs.CustomsInvoice`
    :param target_folder: The folder in which the generated files
                          should be written to
    :param serialno: The serial number of the Customs documentation set
    :type serialno: str
    :return: The output file path

    .. rubric:: Template Used

    ``tendril/dox/templates/customs/valuation.tex``
    (:download:`Included version
    <../../tendril/dox/templates/customs/valuation.tex>`)

    .. rubric:: Stage Keys Provided
    .. list-table::

        * - ``date``
          - The date the documents were generated at, from
            :func:`datetime.date.today`.
        * - ``signatory``
          - The name of the person who 'signs' the document, from
            :data:`tendril.utils.config.COMPANY_GOVT_POINT`.
        * - ``inv_no``
          - The vendor's invoice number.
        * - ``inv_date``
          - The date of the vendor's invoice.
        * - ``given_data``
          - A dict containing various facts about the invoice. See
            :attr:`tendril.sourcing.customs.CustomsInvoice.given_data`
        * - ``currency``
          - The symbol of the currency of the invoice.
        * - ``inv_total``
          - The total value of the invoice, in vendor currency.
        * - ``exchrate``
          - The applicable exchange rate.
        * - ``exchnotif``
          - The government notification number specifying the exchange rate.
        * - ``exchnotifdt``
          - The date of the exchange rate notification.
        * - ``note1``
          - A note mentioning the inclusion of freight.
        * - ``note2``
          - A list of strings mentioning other additions to the valuation.
        * - ``include_note2``
          - Boolean, whether or not to include note2.
        * - ``extended_total_sc``
          - The extended total invoice value, in the vendor's currency.
        * - ``assessable_total_sc``
          - The assessable total invoice value, in the vendor's currency.
        * - ``assessable_total_nc``
          - The assessable total invoice value, in the vendor's currency.
        * - ``copyt``
          - The string specifying which copy it is.
        * - ``sno``
          - The serial number of the document.
        * - ``is_wire``
          - Bool, whether the payment was made by a wire transfer.

    """
    outpath = os.path.join(
        target_folder,
        "customs-valuation-" + str(invoice.inv_no) + ".pdf"
    )

    note1 = ''
    if invoice.includes_freight is True:
        note1 += "As listed in the invoice, {0} towards freight " \
                 "is also added. ".format(invoice.freight.source_string)
    note1 = render.escape_latex(note1)

    note2 = []

    if invoice.added_insurance is True:
        note2.append(
            "An additional {0}% of FOB is added to the assessable value "
            "as per Rule 10(2)(c)(iii) of Customs Valuation "
            "(Determination of Value of Imported Goods) Rules, 2007. "
            "No specific insurance charges were paid as part of the"
            " transaction.".format(invoice.insurance_pc)
        )
    if invoice.added_handling is True:
        note2.append(
            "An additional {0}% of CIF is added to the assessable value "
            "as per Rule 10(2)(b)(ii) of Customs Valuation "
            "(Determination of Value of Imported Goods) Rules, 2007. "
            "No specific handling charges were paid as part of the"
            " transaction.".format(invoice.handling_pc)
        )

    include_note2 = False
    if len(note2) > 0:
        include_note2 = True
    if invoice.given_data['bank_ref'] is None:
        is_wire = False
    else:
        is_wire = True

    stage = {'date': datetime.date.today().isoformat(),
             'signatory': COMPANY_GOVT_POINT,
             'inv_no': invoice.inv_no,
             'inv_date': invoice.inv_date,
             'given_data': invoice.given_data,
             'currency': render.escape_latex(invoice.currency.symbol),
             'inv_total':
             render.escape_latex(invoice.extendedtotal.source_string),
             'exchrate': invoice.given_data['exchrate'],
             'exchnotif': invoice.given_data['exchnotif'],
             'exchnotifdt': invoice.given_data['exchnotif_date'],
             'note1': note1,
             'note2': note2,
             'include_note2': include_note2,
             'extended_total_sc':
             render.escape_latex(invoice.extendedtotal.source_string),
             'assessable_total_sc':
             render.escape_latex(invoice.assessabletotal.source_string),
             'assessable_total_nc':
             render.escape_latex(invoice.assessabletotal.native_string),
             'sno': serialno + '.3',
             'is_wire': is_wire
             }

    return render.render_pdf(stage, 'customs/valuation.tex', outpath)