Common Functions
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 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 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)
# Example adapted from VAT report printing.
print_in_thread(job_token, doc_objs, modcode=gl_moddata["code"],
pseudo_mapper=[{"f1":"self", "t1":"b_detail"},
{"f1":"self", "t1":"s_detail"},
{"f1":"self", "t1":"detail"},
{"f1":"self", "t1":"subst_detail"},
{"f1":"self", "t1":"subst_detail"}],
template_name=["VT_RPRT_B_REPORT", "VT_RPRT_S_REPORT",
"VT_RPRT_SUM_REPORT", "VT_RPRT_SUBST_REPORT",
"VT36_RPRT_SUM_REPORT"],
stat_cols=[["section_code", "section_name"], ["section_code", "section_name"],
["section_code", "section_name"], ["section_code", "section_name"],
["section_code", "section_name"]])
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 |
|
gen_qr(num, qr_type="out", info=None)
Description | Generate QR code for making or receiving payment. The QR code expects Thailand's Tax ID Promptpay format. |
Parameters |
|
Returns | The path to the output PNG file (str) or a 404-abortion the image cannot be created. |
Spreadsheet Export Functions
gen_spreadsheet(specs, round_all=None, col_desc=None, col_size={})
Description | XXXXXX |
Parameters |
|
Returns | The path to the exported spreadsheet (XLSX) file. |
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 |