Common Functions

จาก คูนิฟ็อกซ์ วิกิ

Main 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
  • bookcode (str): The database name (usually a three-lettered string).
  • sch_kw (str): The search keyword.
  • models (CuneiModel or [CuneiModel,]): The model(s) of the database entry. Developers may choose to feed all the relevant models or only the master model.
  • isgl (bool): Whether the database is considered an accounting journal database. (One can also feed the argument bookcode in the format GL_XXX and ignore this argument.)
  • datatype (str: 'table', 'data', or 'report'): The data type (location) of the database file.
  • month (str, date, or datetime): The data month (effective for datatype='data'). If the argument is a string, it must be formatted either as YYYYMM or YYYYMMDD.
  • sch_col (str): the name of the search column.
Returns
  • If a match is found: Returns the match's ID (int).
  • Otherwise: Returns None.
grab_whole_doc(bookcode, identifiers, master_model, detail_models, isgl=False,
               datatype="data", month=None)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
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.
  • dbtype (str): Pointer to let CuneiFox grab the correct database file. Options include 'data', 'table', 'report', and 'temp'.
  • tbname (str): The database file name (without file extension).
  • model (CuneiModel): The model to commit to.
  • form (FlaskForm-CuneiForm): The form to read the committing data from.
  • perm_bit (int): The integer permission bit. This form of permission control is quite rigid and works well with single-table databases.
  • allowed_action ({'add':<bool>, 'edit':<bool>, 'delete':<bool>}): A more complicated form of permission control. This allows for more precise control. However, it cannot be read directly from a permission database, but must be interpreted from the stored integer value upon use.
  • suppress_success_msg (bool): Whether to show a message on action success.
  • lock_on_add (bool): Lock the document upon successful add-type commit. (This works for multi-table databases by putting the current username in the editting column of the header table.)
  • head_id_col (str): The name of the field unique to each entry. (The field must be present both in the form and in the database table.)
  • get_dict (list): If provided, new_entry is returned as a dict instead of a CuneiModel instance. (Values from field names listed in this argument are returned as their integer references. This is useful for ForeignKeyFields.)
  • skip_validation (bool): Whether the form validation step is skipped. ONLY SET THIS IF THE FORM IS VALIDATED ELSEWHERE.
  • month (date or datetime): (Only applies for dbtype 'data') The month sub-directory of the database. If not given, the program infers the month from the session time.
Returns
  • db_mod_code (int or None): The returned value can be:
    • None: Indicate a permission error.
    • 2: For a successful/failed addition attempt.
    • 3: For a successful/failed edit attempt.
    • 4: For a successful/failed deletion attempt.
  • new_entry (CuneiModel instance or dict or None): CuneiModel instance or a dict representing the successfully added/edited entry. Returned None for a failed attempt.
  • resp_dict (dict or int):
    • For a successful/failed attempt: The data dict to be sent to the client-side. This function takes care of the 'data', 'flash_messages', and 'err' keys.
    • For a permission error: Integer 403.
prefetch_all_docs(bookcode, master_spec, detail_specs, isgl=False, datatype="data",
                  month=None, headid=None, id_col="id", return_instance=False, crossers=[])
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
prep_copy(cp_form, bookcode, head_model, detail_models=[], isgl=False)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
create_doc_copy(cp_form, copy_params, bookcode, orig_doc, head_model, detail_models={},
                isgl=False, omit_cols=[])
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
check_modact_stat(modid=None, modcode=None, mode="activate", response="return")
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
process_doc_file(dbtype, tbname, model, at_form, isgl=False, month=None)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
gen_random_token(length=10, lower=True, upper=True, number=True)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX

User Authentication Functions

process_beacon_args(internal_args, request)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
process_doclock(beacon_args, module_name, perm_name, headmodel=None, paired_gl=None)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
change_datetime(form, reset=False, date_obj=None, time_obj=None)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX

Thread Functions

init_task_db(job_token, overall_load, new_stat="", activity_str="",
             suppress_request=True, further_action="")
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
update_task_db(job_token, finished_load=0, overall_load=None,
               new_stat=None, activity_str=None, further_action=None)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
read_task_db(job_token)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
read_resus_import_file(job_token, will_abort=False)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX

Printing Functions

Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
gen_qr(num, qr_type="out", info=None)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX
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)
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX

Spreadsheet Export Functions

gen_spreadsheet(specs, round_all=None, col_desc=None, col_size={})
Description XXXXXX
Parameters
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
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
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
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
  • xxx (xxx):
  • xxx (xxx):
Returns
  • xxx (xxx):
  • xxx (xxx):
Notes XXXXXX