diff --git a/cleanup_script.py b/cleanup_script.py index aa2b338..57cc7f2 100755 --- a/cleanup_script.py +++ b/cleanup_script.py @@ -56,15 +56,23 @@ class Company: def clean_complex(self, year: int, state: str) -> None: """Clean the complex data. This means earnings before/after tax.""" try: - if f"Gewinn/(Verlust) {state} Steuern EUR {year}" in self.data.keys() and self.data[f"Gewinn/(Verlust) {state} Steuern EUR {year}"] != '' and not self.cleaned_data.get(f"gn{year}"): + if f"Gewinn/(Verlust) {state} Steuern EUR {year}" in self.data.keys() and self.data[f"Gewinn/(Verlust) {state} Steuern EUR {year}"] != '' and not self.cleaned_data.get(f"gn{year}") and self.cut_negative(state, int(self.data[f"Gewinn/(Verlust) {state} Steuern EUR {year}"])): self.cleaned_data[f"g{self.get_suffix(state)}{year}"] = int(self.data[f"Gewinn/(Verlust) {state} Steuern EUR {year}"]) - elif f"Gewinn/Verlust {state} Steuern EUR {year}" in self.data.keys() and self.data[f"Gewinn/Verlust {state} Steuern EUR {year}"] != '' and not self.cleaned_data.get(f"gn{year}"): + elif f"Gewinn/Verlust {state} Steuern EUR {year}" in self.data.keys() and self.data[f"Gewinn/Verlust {state} Steuern EUR {year}"] != '' and not self.cleaned_data.get(f"gn{year}") and self.cut_negative(state, int(self.data[f"Gewinn/(Verlust) {state} Steuern EUR {year}"])): self.cleaned_data[f"g{self.get_suffix(state)}{year}"] = int(self.data[f"Gewinn/Verlust {state} Steuern EUR {year}"]) else: self.report.log.debug(f"{self.cleaned_data['name']}:g{self.get_suffix(state)}{year} empty value") except ValueError: self.report.log.debug(f"{self.cleaned_data['name']}: g{self.get_suffix(state)}{year} ValueError") + def cut_negative(self, state: str, gv: int) -> bool: + if state == "vor": + return False if gv < 0 else True + elif state == "nach": + return True + else: + raise Exception("IMPOSSIBLE STATE CN") + def get_suffix(self, state: str) -> str: """Get suffix for the complex cleaning process.""" return "n" if state == "nach" else "v"