ผลต่างระหว่างรุ่นของ "Common Functions"
บรรทัดที่ 280: | บรรทัดที่ 280: | ||
job_data=None, clear_printed=True, skip_company_template=False, | job_data=None, clear_printed=True, skip_company_template=False, | ||
make_pdfa3=False) | make_pdfa3=False) | ||
# Example adapted from accounting journal mass-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>''' | </syntaxhighlight>''' | ||
{| style="margin-left:20px;" | {| style="margin-left:20px;" | ||
บรรทัดที่ 286: | บรรทัดที่ 291: | ||
|- style="vertical-align:top;" | |- style="vertical-align:top;" | ||
| '''Parameters''' || | | '''Parameters''' || | ||
* '''tbfm_mapper''' ''(dict)'': | * '''tbfm_mapper''' ''(dict)'': The dict matching the form/table references (as used in SVG templates) to the objects holding the values. | ||
* '''modcode''' ''(str)'': ''(Obsolete)'' | ** 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). | ||
* '''bookname''' ''(str)'': | ** 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). | ||
* '''svg_name''' ''(str)'': | * '''modcode''' ''(str)'': ''(Obsolete)'' The code of the module from which the printing is invoked. | ||
* '''suffix''' ''(int)'': | * '''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. | ||
* '''job_data''' ''(list)'': | * '''svg_name''' ''(str)'': The name of the print template. | ||
* '''clear_printed''' ''(bool)'': | * '''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. | ||
* '''skip_company_template''' ''(bool)'': | * '''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}}). | ||
* '''make_pdfa3''' ''(bool)'': | * '''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;" | |- style="vertical-align:top;" | ||
| '''Returns''' || The path to the output PDF file ''(str)''. | | '''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 concatenated 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'}}. | |||
|} | |} | ||
บรรทัดที่ 303: | บรรทัดที่ 312: | ||
svg_name=None, stat_cols=[], skip_company_template=False, | svg_name=None, stat_cols=[], skip_company_template=False, | ||
make_pdfa3=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>''' | </syntaxhighlight>''' | ||
{| style="margin-left:20px;" | {| style="margin-left:20px;" | ||
|- style="vertical-align:top;" | |- style="vertical-align:top;" | ||
| style="width:120px;" | '''Description''' || | | 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;" | |- style="vertical-align:top;" | ||
| '''Parameters''' || | | '''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;" | |- style="vertical-align:top;" | ||
| '''Returns''' || | | '''Returns''' || {{code|lang=python|None}} | ||
|- style="vertical-align:top;" | |- style="vertical-align:top;" | ||
| '''Notes''' || | | '''Notes''' || The final concatenated PDF is always named {{code|lang=python|'<username>_out.pdf'}} and located in the company's {{code|temp}} directory. | ||
|} | |} | ||
รุ่นแก้ไขเมื่อ 12:15, 26 กรกฎาคม 2567
Database Read Functions
grab_id(bookcode, sch_kw, models, isgl=False, datatype="data", month=None, sch_col="docno")
Description | Fetch the ID of the looked-up entry. Because this function is usually utilized in the page-level search function, it is designed to target string-based column by looking for values that starts-with the search keyword. In case of multiple matches, the ID of the first match (ordered by the search column). |
Parameters |
|
Returns |
|
grab_whole_doc(bookcode, identifiers, master_model, detail_models, isgl=False,
datatype="data", month=None)
Description | Retrieve a single document (along with all its sub-entries) to display on the client-side. This function is tailored to the client-side mass-populate routine, so its algorithm leans heavily in that direction. For a more server-friendly retrieval, use prefetch_all_docs instead. |
Parameters | DO NOT rely on argument order beyond detail_models.
|
Returns | 3 objects:
|
prefetch_all_docs(bookcode, master_spec, detail_specs, isgl=False, datatype="data",
month=None, headid=None, id_col="id", return_instance=False, crossers=[])
Description | Retrieve one or any number of database entries. Since this function allows retrieval from a master table with sub-tables, it is mostly used with (and thus named) documents, however using it with complex code tables is also valid. |
Parameters |
|
Returns | 2 objects:
|
Database Write Functions
gen_dbcommit_resp(dbtype, tbname, model, form, perm_bit=None, allowed_action=None,
suppress_success_msg=False, lock_on_add=True, head_id_col="id",
get_dict=None, skip_validation=False, month=None)
Description | Conduct form validation and, if passed, commit the form data to database. |
Parameters | DO NOT rely on argument order beyond perm_bit.
|
Returns |
|
Copy-based Functions
prep_copy(cp_form, bookcode, head_model, detail_models=[], isgl=False)
Description | Interpret and validate the Copy Form. If the validation is successful, retrieve the original document as well. |
Parameters |
|
Returns | 3 objects:
|
create_doc_copy(cp_form, copy_params, bookcode, orig_doc, head_model, detail_models={},
isgl=False, omit_cols=[])
Description | Commit the document copying to the proper database. |
Parameters |
|
Returns | The newly copied document (if successfully copied) or None (if copying failed).
|
Notes | A notable kink in this function is that the cp_form and copy_params arguments are quite redundant. In the algorithm, cp_form is only used for its automatic document number attribute. If the function assign_autorun is well modified, the need for cp_form might cease to exist.
|
Session-based Functions
check_modact_stat(modid=None, modcode=None, mode="activate", response="return")
Description | Check whether certain module is activated. (See more on Activation Level.) |
Parameters |
|
Returns |
|
change_datetime(form, reset=False, date_obj=None, time_obj=None)
Description | Change the session date-time as dictated by the DateTimeForm or as explicitly specified. And store the change in the session token database. |
Parameters |
|
Returns | 3 Objects:
|
Thread Functions
init_task_db(job_token, overall_load, new_stat="", activity_str="",
suppress_request=True, further_action="")
Description | Initialize a long-task in the task database. If there are more parallel tasks running than the maximum number allowed, put the new task in the queue. |
Parameters |
|
Returns | A Task (CuneiModel) instance corresponding to the newly initiated task.
|
update_task_db(job_token, finished_load=0, overall_load=None,
new_stat=None, activity_str=None, further_action=None)
Description | Update the status of a task in the task database. |
Parameters |
|
Returns | None
|
Notes |
|
read_task_db(job_token)
Description | Retrieve the Task instance with the token matching the given value.
|
Parameters | job_token (str): Job token of the task to be retrieved. |
Returns | A Task (CuneiModel) instance corresponding to the newly initiated task or None if not found.
|
read_resus_import_file(job_token, will_abort=False)
Description | A shortcut to extract the path to the file assciated with the task. This function expects the path to be stored as a string under the 'file_path' key in the Task's further_action attribute (json.loads(current_task.further_action)['file_path'] ).
|
Parameters |
|
Returns |
|
Notes | One can also choose to use the function read_task_db and work their way from there without ever using this function. |
Printing Functions
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 mass-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]))
Description | The main function for printing. Replace CuneiTongue tags in SVG templates with appropriate values. |
Parameters |
|
Returns | The path to the output PDF file (str) or None if the templates cannot be found.
|
Notes | The final concatenated PDF is always located in the company's temp directory and named either '<username>_out.pdf' or '<username>_out_<suffix>.pdf' .
|
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)
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. |
Parameters |
|
Returns | None
|
Notes | The final concatenated PDF is always named '<username>_out.pdf' and located in the company's temp directory.
|
gen_qr(num, qr_type="out", info=None)
Description | XXXXXX |
Parameters |
|
Returns |
|
Notes | XXXXXX |
Spreadsheet Export Functions
gen_spreadsheet(specs, round_all=None, col_desc=None, col_size={})
Description | XXXXXX |
Parameters |
|
Returns |
|
Notes | XXXXXX |
Import & Mass Delete Functions
docimport_to_db(file_path, dbtype, dbname, models, specs, month=None,
verify_cmd=None, post_cmd=None, addi_args=[], autorun_specs=None,
job_token=None, custom_datasets=None)
Description | XXXXXX |
Parameters |
|
Returns |
|
Notes | XXXXXX |
doc_mass_delete(dbtype, dbname, models, doc_objs=[], month=None, post_cmd=None,
job_token=None, addi_args=[], docno_to_skip=[])
Description | XXXXXX |
Parameters |
|
Returns |
|
Notes | XXXXXX |
Miscellaneous
process_doc_file(dbtype, tbname, model, at_form, isgl=False, month=None)
Description | XXXXXX |
Parameters |
|
Returns |
|
Notes | XXXXXX |
gen_random_token(length=10, lower=True, upper=True, number=True)
Description | XXXXXX |
Parameters |
|
Returns |
|
Notes | XXXXXX |