Skip to content
Snippets Groups Projects
Commit fa982c79 authored by Neda Moeini's avatar Neda Moeini
Browse files

Add validation for Check columns must not be empty.

parent 78dae063
No related branches found
Tags 0.8
1 merge request!5Feature/cheque cols should be empty
......@@ -45,6 +45,9 @@ class CSVUploadForm(forms.Form):
"TaxValue",
"SYSTraderGenerationReasonType",
"GoodsValueInBaseCurrency",
"ChequeCurrencyName",
"ChequeToBankExchangeRate",
"ChequeValueInChequeCurrency",
]
repeating_columns: ClassVar[dict] = {
......@@ -83,6 +86,7 @@ class CSVUploadForm(forms.Form):
error_list.extend(self._validate_source_and_trader_type(data))
error_list.extend(self._validate_nominal_analysis_account(data))
error_list.extend(self._validate_nc_cc_dep_combination_against_meo_sage_account(data))
error_list.extend(self._cheque_fields_must_be_empty(data))
if error_list:
raise forms.ValidationError(error_list)
......@@ -251,3 +255,22 @@ class CSVUploadForm(forms.Form):
)
return errors
@staticmethod
def _cheque_fields_must_be_empty(data: list[dict]) -> list[str]:
"""Validate that cheque fields are empty.
The cheque fields are 'ChequeCurrencyName', 'ChequeToBankExchangeRate', and 'ChequeValueInChequeCurrency'.
"""
errors = []
for index, row in enumerate(data, start=1):
cheque_currency_name = row.get("ChequeCurrencyName")
cheque_to_bank_exchange_rate = row.get("ChequeToBankExchangeRate")
cheque_value_in_cheque_currency = row.get("ChequeValueInChequeCurrency")
if any([cheque_currency_name, cheque_to_bank_exchange_rate, cheque_value_in_cheque_currency]):
errors.append(
f"Row {index}: Unexpected values in the Cheque columns. All cheque columns must be empty."
)
return errors
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment