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

Merge branch 'feature/cheque-cols-should-be-empty' into 'develop'

Feature/cheque cols should be empty

See merge request !5
parents 78dae063 408ab6df
No related branches found
No related tags found
1 merge request!5Feature/cheque cols should be empty
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# #
import os import os
import sys import sys
import django import django
sys.path.insert(0, os.path.abspath("../../")) sys.path.insert(0, os.path.abspath("../../"))
...@@ -20,12 +21,12 @@ django.setup() ...@@ -20,12 +21,12 @@ django.setup()
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
project = 'Sage Validation' project = "Sage Validation"
copyright = '2024, GÉANT' copyright = "2024, GÉANT"
author = 'GÉANT' author = "GÉANT"
# The full version, including alpha/beta/rc tags # The full version, including alpha/beta/rc tags
release = '0.1' release = "0.1"
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
...@@ -34,13 +35,13 @@ release = '0.1' ...@@ -34,13 +35,13 @@ release = '0.1'
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones. # ones.
extensions = [ extensions = [
'sphinx.ext.autodoc', "sphinx.ext.autodoc",
'sphinx.ext.napoleon', "sphinx.ext.napoleon",
'sphinx_autodoc_typehints', "sphinx_autodoc_typehints",
] ]
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ["_templates"]
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
...@@ -53,9 +54,9 @@ exclude_patterns = [] ...@@ -53,9 +54,9 @@ exclude_patterns = []
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
# #
html_theme = 'alabaster' html_theme = "alabaster"
# Add any paths that contain custom static files (such as style sheets) here, # Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files, # relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static'] html_static_path = ["_static"]
\ No newline at end of file
...@@ -60,4 +60,8 @@ The following table describes the validation rules applied when uploading a CSV ...@@ -60,4 +60,8 @@ The following table describes the validation rules applied when uploading a CSV
* - Checks * - Checks
- `...TaxRate` - `...TaxRate`
- Validate against `[Tax code]` in `dbo.meoValidVAT`. - Validate against `[Tax code]` in `dbo.meoValidVAT`.
- Ensure valid tax rates. - Ensure valid tax rates.
\ No newline at end of file
* - Checks
- `ChequeCurrencyName`, `ChequeToBankExchangeRate`, `ChequeValueInChequeCurrency`
- Cheque fields must be empty.
\ No newline at end of file
...@@ -45,6 +45,9 @@ class CSVUploadForm(forms.Form): ...@@ -45,6 +45,9 @@ class CSVUploadForm(forms.Form):
"TaxValue", "TaxValue",
"SYSTraderGenerationReasonType", "SYSTraderGenerationReasonType",
"GoodsValueInBaseCurrency", "GoodsValueInBaseCurrency",
"ChequeCurrencyName",
"ChequeToBankExchangeRate",
"ChequeValueInChequeCurrency",
] ]
repeating_columns: ClassVar[dict] = { repeating_columns: ClassVar[dict] = {
...@@ -83,6 +86,7 @@ class CSVUploadForm(forms.Form): ...@@ -83,6 +86,7 @@ class CSVUploadForm(forms.Form):
error_list.extend(self._validate_source_and_trader_type(data)) error_list.extend(self._validate_source_and_trader_type(data))
error_list.extend(self._validate_nominal_analysis_account(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._validate_nc_cc_dep_combination_against_meo_sage_account(data))
error_list.extend(self._cheque_fields_must_be_empty(data))
if error_list: if error_list:
raise forms.ValidationError(error_list) raise forms.ValidationError(error_list)
...@@ -251,3 +255,22 @@ class CSVUploadForm(forms.Form): ...@@ -251,3 +255,22 @@ class CSVUploadForm(forms.Form):
) )
return errors 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
...@@ -37,6 +37,9 @@ def sample_input_file() -> SimpleUploadedFile: ...@@ -37,6 +37,9 @@ def sample_input_file() -> SimpleUploadedFile:
"SYSTraderGenerationReasonType", "SYSTraderGenerationReasonType",
"GoodsValueInBaseCurrency", "GoodsValueInBaseCurrency",
"TransactionReference", "TransactionReference",
"ChequeCurrencyName",
"ChequeToBankExchangeRate",
"ChequeValueInChequeCurrency",
# NominalAnalysis repeating columns (Example: /1 for first occurrence) # NominalAnalysis repeating columns (Example: /1 for first occurrence)
"NominalAnalysisTransactionValue/1", "NominalAnalysisTransactionValue/1",
...@@ -79,6 +82,9 @@ def sample_input_file() -> SimpleUploadedFile: ...@@ -79,6 +82,9 @@ def sample_input_file() -> SimpleUploadedFile:
"1000", # SYSTraderGenerationReasonType "1000", # SYSTraderGenerationReasonType
"1200", # GoodsValueInBaseCurrency "1200", # GoodsValueInBaseCurrency
"BK123", # TransactionReference(Batch Number) "BK123", # TransactionReference(Batch Number)
"", # ChequeCurrencyName
"", # ChequeToBankExchangeRate
"", # ChequeValueInChequeCurrency
# NominalAnalysis repeating values (Example: /1) # NominalAnalysis repeating values (Example: /1)
"500.75", # NominalAnalysisTransactionValue/1 "500.75", # NominalAnalysisTransactionValue/1
......
...@@ -92,3 +92,11 @@ def test_validate_nc_cc_dep_combination_against_meo_sage_account( ...@@ -92,3 +92,11 @@ def test_validate_nc_cc_dep_combination_against_meo_sage_account(
assert ("Row 1: 'NominalAnalysisNominalCostCentre/1' (Invalid_CC) is not a valid cost centre." assert ("Row 1: 'NominalAnalysisNominalCostCentre/1' (Invalid_CC) is not a valid cost centre."
in str(form.errors["file"][0])) in str(form.errors["file"][0]))
def test_cheque_fields_must_be_empty(sample_input_file: SimpleUploadedFile, mock_meo_database: MagicMock) -> None:
"""Test that cheque fields must be empty."""
modified_file = create_modified_csv(sample_input_file,
{"ChequeCurrencyName": "USD", "ChequeToBankExchangeRate": "1"})
form = CSVUploadForm(files={"file": modified_file})
assert not form.is_valid()
assert "Row 1: Unexpected values in the Cheque columns. All cheque columns must be empty." in form.errors["file"][0]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment