Pārlūkot izejas kodu

updated Rechnungstool

Nico Ruhnke 1 gadu atpakaļ
vecāks
revīzija
ab320f6f2f

+ 20 - 0
fast_excel_to_bill/bill_doc/docx_builder.py

@@ -156,6 +156,26 @@ class DOCFileBuilder:
                 except AttributeError:
                     pass
 
+    def replace_Rechnungsnummer(self, month, year):
+        for p in self.paragraphs_in_table():
+            inline = p.runs
+            for i in range(len(inline)):
+                try:
+                    re.search(r'Rechnung Nr', inline[i].text).group()
+                    lines = inline[i].text.split('\n')
+                    updated_lines = []
+                    for line in lines:
+                        if r'Rechnung Nr' in line:
+                            updated_lines.append('Rechnung Nr.: {}-{}'.format(year, month))
+                        else:
+                            updated_lines.append(line)
+
+                    text = '\n'.join(updated_lines)
+
+                    inline[i].text = text
+                except AttributeError:
+                    pass
+
     # High Tier functions
     def replace_all_dates_custom_wise(self, start_date, end_date):
         self.replace_dates_string_in_standard_text(end_date)

+ 42 - 12
fast_excel_to_bill/main.py

@@ -9,7 +9,6 @@ from fast_excel_to_bill.transform_excel_data_to_bill_data.time_recorder_format_m
 PAYMENT_REQUEST_RANGE = config_for_custom_bills.payment_request_range
 CURRENT_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 / 'bill_{}.docx'.format(CURRENT_MONTH_YEAR)
 
 
 def get_excel_data():
@@ -32,25 +31,50 @@ def set_current_dates(builder_obj):
 
 
 def set_Leistungszeitraum(builder_obj, month: int, year: int):
-    if not 0 < month <= 12:
-        last_month = datetime_functions.get_current_month_number() - 1
-    else:
-        last_month = month
-
     if year < 0:
         year = CURRENT_YEAR
 
-    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)
+    month_range = datetime_functions.get_count_of_days_for_specific_month(year=year, month_number=month)
+    if month > 9:
+        start_date = '01.' + str(month) + '.' + str(year)
     else:
-        start_date = '01.' + '0' + str(last_month) + '.' + str(year)
+        start_date = '01.' + '0' + str(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)
     return builder_obj
 
 
+def set_Rechnungsnummer(builder_obj, month, year):
+    month_str = str(month)
+    if month <= 9:
+        month_str = '0' + month_str
+
+    builder_obj.replace_Rechnungsnummer(month_str, str(year))
+    return builder_obj
+
+
+def get_selected_month():
+    if not 0 < OUTPUT_MONTH <= 12:
+        return datetime_functions.get_current_month_number() - 1
+    else:
+        return OUTPUT_MONTH
+
+
+def get_selected_year():
+    if 0 > OUTPUT_YEAR:
+        return CURRENT_YEAR
+    else:
+        return OUTPUT_YEAR
+
+
+def month_to_string(month: int):
+    if month <= 9:
+        return '0' + str(month)
+    else:
+        return str(month)
+
+
 def set_rechnungsnummer():
     pass
 
@@ -67,14 +91,20 @@ def main():
 
     bill_data_dict = get_excel_data()
 
+    docx_output_path = config_for_custom_bills.docx_output_dir_path / 'bill_{}.docx'.format(
+        month_to_string(get_selected_month()) + '_' + str(get_selected_year()))
+
     # Create a doc file which is based on a docx template
-    builder_obj = DOCFileBuilder(config_for_custom_bills.DOCX_INPUT_PATH, DOCX_OUTPUT_PATH)
+    builder_obj = DOCFileBuilder(config_for_custom_bills.DOCX_INPUT_PATH, docx_output_path)
 
     # Set Date of Template
     builder_obj = set_current_dates(builder_obj)
 
     # Set Leistungszeitraum
-    builder_obj = set_Leistungszeitraum(builder_obj, OUTPUT_MONTH, OUTPUT_YEAR)
+    builder_obj = set_Leistungszeitraum(builder_obj, get_selected_month(), get_selected_year())
+
+    # Set Rechnungsnummer
+    builder_obj = set_Rechnungsnummer(builder_obj, get_selected_month(), get_selected_year())
 
     # Table KW/Time/ sum
     data_list = []

+ 4 - 0
fast_excel_to_bill/transform_excel_data_to_bill_data/time_recorder_format_main.py

@@ -92,6 +92,8 @@ def compress_data_by_key_list(*compressable_lists, key_list):
                 pos_bias += 1
             else:
                 past_values += [value]
+                if isinstance(compressable_lists[pos - pos_bias], str):
+                    compressable_lists[pos-pos_bias] = [compressable_lists[pos-pos_bias]]
     return compressable_lists
 
 
@@ -120,6 +122,8 @@ def main_data_collection(pathes, list_of_keys=['Arbeitszeit', 'Task']):
                     date_filter_value_indices.append(date_value_idx)
             customer_and_date_filtered_indices = list(set(customer_filter_value_indices) & set(date_filter_value_indices))
 
+            customer_and_date_filtered_indices.sort()
+
             for key in table_object:
                 table_object[key] = [table_object[key][idx] for idx in customer_and_date_filtered_indices]