|
|
บรรทัดที่ 359: |
บรรทัดที่ 359: |
| * The final concatenated PDF is always named {{code|lang=python|'<username>_out.pdf'}} and located in the company's {{code|temp}} directory. | | * The final concatenated PDF is always named {{code|lang=python|'<username>_out.pdf'}} and located in the company's {{code|temp}} directory. |
| * The arguments '''doc_objs, modcode, pseudo_mapper, template_name, svg_name,''' and '''stat_cols''' can be layered one level deeper into lists, as demonstrated in Example #2. ''(Note that, in the example '''modcode''' is not layered; the function can assume that the same '''modcode''' should apply to all iterations.)'' | | * The arguments '''doc_objs, modcode, pseudo_mapper, template_name, svg_name,''' and '''stat_cols''' can be layered one level deeper into lists, as demonstrated in Example #2. ''(Note that, in the example '''modcode''' is not layered; the function can assume that the same '''modcode''' should apply to all iterations.)'' |
| |}
| |
|
| |
| '''<syntaxhighlight lang="python" id="gen_qr">
| |
| gen_qr(num, qr_type="out", info=None)
| |
| </syntaxhighlight>'''
| |
| {| style="margin-left:20px;"
| |
| |- style="vertical-align:top;"
| |
| | style="width:120px;" | '''Description''' || Generate QR code for making or receiving payment. The QR code expects '''Thailand's Tax ID Promptpay''' format.
| |
| |- style="vertical-align:top;"
| |
| | '''Parameters''' ||
| |
| * '''num''' ''(float)'': The numerical value to embed in the QR code (in THB).
| |
| * '''qr_type''' ''({{code|lang=python|'in'}} or {{code|lang=python|'out'}})'': Whether the QR code is for paying or receiving money.
| |
| * '''info''' ''([str:company_name, str:company_taxID] or {{code|lang=python|None}})'': If the argument is {{code|lang=python|None}}, the function assumes the company name and tax ID of the current company.
| |
| |- style="vertical-align:top;"
| |
| | '''Returns''' || The path to the output PNG file ''(str)'' or a 404-abortion the image cannot be created.
| |
| |}
| |
|
| |
| == Printing Functions ==
| |
| '''<syntaxhighlight lang="python" id="replace_printsvg">
| |
| replace_printsvg(tbfm_mapper, modcode, bookname=None, svg_name=None, suffix=None,
| |
| job_data=None, clear_printed=True, skip_company_template=False,
| |
| make_pdfa3=False)
| |
|
| |
| # Example adapted from accounting journal printing.
| |
| tbfm_dict = {"f1":thisdoc, "t1":thisdoc.detail, "t2":thisdoc.vat_detail, "t3":thisdoc.wht_detail}
| |
| pdf_path = replace_printsvg(tbfm_dict, "cunei_gl", bookname="GL_BOOK",
| |
| svg_name="GL_{}".format(thisdoc.docno[:3]))
| |
| </syntaxhighlight>'''
| |
| {| style="margin-left:20px;"
| |
| |- style="vertical-align:top;"
| |
| | style="width:120px;" | '''Description''' || The main function for printing. Replace [[CuneiTongue]] tags in SVG templates with appropriate values.
| |
| |- style="vertical-align:top;"
| |
| | '''Parameters''' ||
| |
| * '''tbfm_mapper''' ''(dict)'': The dict matching the form/table references (as used in SVG templates) to the objects holding the values.
| |
| ** A reference to a '''form''' take the format {{code|lang=python|'f1'}}, {{code|lang=python|'f2'}}, {{code|lang=python|'f3'}}, .... The corresponding value is an {{code|lang=python|Object}} (preferably a CuneiModel instance).
| |
| ** A reference to a '''table''' take the format {{code|lang=python|'t1'}}, {{code|lang=python|'t2'}}, {{code|lang=python|'t3'}}, .... The corresponding value is an iterable (e.g. a list) of {{code|lang=python|Object}}s (preferably a CuneiModel instances).
| |
| * '''modcode''' ''(str)'': ''(Obsolete)'' The code of the module from which the printing is invoked.
| |
| * '''bookname''' ''(str)'': The name of the fallback template to be used in case the template '''svg_name''' is not found. Usually this coincides with the database file name, hence the argument name.
| |
| * '''svg_name''' ''(str)'': The name of the print template.
| |
| * '''suffix''' ''(int)'': The suffix to append to the PDF file name. This argument is only used internally via {{code|print_in_thread}} where multiple documents are printed as separated PDF files to be concatenated together in the final step.
| |
| * '''job_data''' ''(list or {{code|lang=python|None}})'': The task information. This argument is only applicable when printing in a long-job (usually via {{code|print_in_thread}}).
| |
| * '''clear_printed''' ''(bool)'': Whether to clear other residual PDFs that might be left in the company's {{code|temp}} directory. This argument is exclusively set to {{code|lang=python|True}} via {{code|print_in_thread}} where multiple PDFs are to be concatenated. ''(Only affects temporary PDFs created by the same user.)''
| |
| * '''skip_company_template''' ''(bool)'': Whether to skip looking for print templates in the company-specific folder and only look for CuneiFox official templates.
| |
| * '''make_pdfa3''' ''(bool)'': Whether to convert the final PDF to PDF/A-3b.
| |
| |- style="vertical-align:top;"
| |
| | '''Returns''' || The path to the output PDF file ''(str)'' or {{code|lang=python|None}} if the templates cannot be found.
| |
| |- style="vertical-align:top;"
| |
| | '''Notes''' || The final PDF is always located in the company's {{code|temp}} directory and named either {{code|lang=python|'<username>_out.pdf'}} or {{code|lang=python|'<username>_out_<suffix>.pdf'}}.
| |
| |}
| |
|
| |
| '''<syntaxhighlight lang="python" id="print_in_thread">
| |
| print_in_thread(job_token, doc_objs, pseudo_mapper, modcode, template_name,
| |
| svg_name=None, stat_cols=[], skip_company_template=False,
| |
| make_pdfa3=False)
| |
|
| |
| # Example adapted from accounting journal mass-printing.
| |
| print_in_thread(job_token, doc_objs, modcode="cunei_gl",
| |
| pseudo_mapper={"f1":"self", "t1":"detail", "t2":"vat_detail", "t3":"wht_detail"},
| |
| template_name="GL_BOOK", svg_name=chosen_template,
| |
| stat_cols=["docno"], make_pdfa3=make_pdfa3)
| |
| </syntaxhighlight>'''
| |
| {| style="margin-left:20px;"
| |
| |- style="vertical-align:top;"
| |
| | style="width:120px;" | '''Description''' || The custom printing function that enables using custom templates, printing multiple documents at once, and the PDF/A-3b option. Because it allows multiple-document printing and the process can potentially take a long time, this means of printing is done in as a long-job in a Thread.
| |
| |- style="vertical-align:top;"
| |
| | '''Parameters''' ||
| |
| * '''job_token''' ''(str)'': Job token of the task (usually a randomly generated string).
| |
| * '''doc_objs''' ''([CuneiModels_instance,])'': The list (iterable) containing the prefetched Cuneifox instances for the documents to be printed.
| |
| * '''pseudo_mapper''' ''(dict)'': The dict matching the form/table references (as used in SVG templates) to the objects holding the values. However, this argument can be one-level more abstracted than '''tbfm_mapper''' of {{code|replace_printsvg}} to facilitate multiple-document printing.
| |
| ** A reference to a '''form''' take the format {{code|lang=python|'f1'}}, {{code|lang=python|'f2'}}, {{code|lang=python|'f3'}}, .... The corresponding value can be either:
| |
| *** An {{code|lang=python|Object}} (preferably a CuneiModel instance) '''OR'''
| |
| *** The string {{code|lang=python|'self'}} to indicate that the master entry itself is being referenced '''OR'''
| |
| *** A back-reference of the ForeignKeyField linking the entry of interest to the master entry ''(str)''.
| |
| ** A reference to a '''table''' take the format {{code|lang=python|'t1'}}, {{code|lang=python|'t2'}}, {{code|lang=python|'t3'}}, .... The corresponding value can be either:
| |
| *** An iterable (e.g. a list) of {{code|lang=python|Object}}s (preferably a CuneiModel instances) '''OR'''
| |
| *** A back-reference of the ForeignKeyField linking the sub-entries to the master entry ''(str)''.
| |
| * '''modcode''' ''(str)'': ''(Obsolete)'' The code of the module from which the printing is invoked.
| |
| * '''template_name''' ''(str)'': The name of the fallback template to be used in case the template '''svg_name''' is not found.
| |
| * '''svg_name''' ''(str)'': The name of the print template.
| |
| * '''stat_cols''' ''(str)'': The column of the master entries to use as the process indicator ''(e.g. 'Currently printing document <???>...')''.
| |
| * '''skip_company_template''' ''(bool)'': Whether to skip looking for print templates in the company-specific folder and only look for CuneiFox official templates.
| |
| * '''make_pdfa3''' ''(bool)'': Whether to convert the final PDF to PDF/A-3b.
| |
| |- style="vertical-align:top;"
| |
| | '''Returns''' || {{code|lang=python|None}}
| |
| |- style="vertical-align:top;"
| |
| | '''Notes''' || The final concatenated PDF is always named {{code|lang=python|'<username>_out.pdf'}} and located in the company's {{code|temp}} directory.
| |
| |} | | |} |
|
| |
|