from fast_excel_to_bill.bill_doc.docx_builder import DOCFileBuilder from fast_excel_to_bill import config_for_custom_bills from tool_lib import datetime_functions from datetime import datetime payment_request_range = config_for_custom_bills.payment_request_range year = int(datetime_functions.datetime_to_str(datetime_functions.get_current_date(), '%Y')) current_month_year= datetime_functions.datetime_to_str('current', '%m_%Y') docx_output_path = config_for_custom_bills.docx_output_dir_path+ r'\bill_{}.docx'.format(current_month_year) def main(): # Get Data which is necessary for the docx # data_from_excel = ... payment_request_date = datetime_functions.add_days_to_date(datetime_functions.get_current_date(),payment_request_range) payment_request_date = datetime_functions.datetime_to_str(payment_request_date, '%d.%m.%Y') # data_from_excel.append(payment_request_date) # Create a doc file which is based on a docx template builder_obj = DOCFileBuilder(config_for_custom_bills.docx_input_path, docx_output_path) # Set Date of Template current_date = datetime_functions.datetime_to_str(datetime_functions.get_current_date(), '%d.%m.%Y') builder_obj.replace_dates_string_in_standard_text(current_date) builder_obj.replace_dates_string_in_all_tables(current_date) # Set Leistungszeitraum last_month = datetime_functions.get_current_month_number()-1 month_range = datetime_functions.get_count_of_days_for_specific_month(year=year, month_number=last_month) if last_month>9: start_date = '01.'+ str(last_month) +'.'+ str(year) else: start_date = '01.' + '0' + str(last_month) + '.' + str(year) end_date = datetime_functions.add_days_to_date(datetime.strptime(start_date,'%d.%m.%Y'), month_range-1) end_date = datetime_functions.datetime_to_str(end_date, '%d.%m.%Y') builder_obj.replace_Leistungszeitraum(start_date, end_date) builder_obj.save_docx() # Replace Placeholders # place_holders = config_for_custom_bills.list_of_place_holders # for place_holder in place_holders: # builder_obj.replace_custom_placeholder_in_doc(place_holder, data_from_excel) # keys = ['KW', 'Leistung', 'Zeit in Stunden', 'Betrag in Euro'] # example_tuple = [(123123, 213123, 12312312, 445235)] # key_table = builder_obj.search_table_with_key_columns(keys) # builder_obj.replace_rows(key_table, example_tuple) # builder_obj.delete_empty_rows_in_table(key_table, 4) # builder_obj.document.add_page_break() # key_table = builder_obj.search_table_with_key_columns(['KW', 'Leistungsübersicht']) # builder_obj.delete_empty_rows_in_table(key_table, 2) data_to_bill_doc = ... # Transform the doc file to a pdf file doc_to_pdf = ... if __name__ == '__main__': main()