Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tp2000 1129 reference documents megabranch #1100

Open
wants to merge 143 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
d5d6424
Add reference_documents app
LaurenMullally Nov 22, 2023
3de7ad2
WIP - Templates >:(
LaurenMullally Nov 22, 2023
60a332b
Get a template of some sort working
LaurenMullally Nov 22, 2023
6e60fba
Add reference document detail path and templates
LaurenMullally Dec 1, 2023
6bcfc51
add date filters to the get_context_data function
LaurenMullally Dec 5, 2023
512ff93
WiP
LaurenMullally Dec 8, 2023
e668d14
Rough commit - working tabs - need cleaning up
LaurenMullally Dec 13, 2023
b8b73db
Add button to home form
LaurenMullally Dec 13, 2023
93adf29
Add comm code links to table
LaurenMullally Dec 18, 2023
aa67405
Merge branch 'master' into TP2000-1129-reference-documents-megabranch
a-gleeson Jan 16, 2024
71da90c
initial commit - ref doc data model
dougmills-DIT Feb 6, 2024
eb2cd34
initial commit - ref doc data model
dougmills-DIT Feb 6, 2024
1246355
wip commit
dougmills-DIT Feb 8, 2024
2cb2cf2
Merge remote-tracking branch 'origin/TP2000-1186_ref_doc_data_model' …
dougmills-DIT Feb 8, 2024
22f444f
initial commit - ref doc data model
dougmills-DIT Feb 6, 2024
d1d49cf
wip commit
dougmills-DIT Feb 8, 2024
627ae6e
initial commit - ref doc data model
dougmills-DIT Feb 6, 2024
24ede2f
wip commit
dougmills-DIT Feb 13, 2024
b547381
wip commit
dougmills-DIT Feb 14, 2024
864fc89
wip commit
dougmills-DIT Feb 14, 2024
a622c35
wip commit
dougmills-DIT Feb 14, 2024
9418199
added alignment report, reference document and reference document ver…
dougmills-DIT Feb 20, 2024
c34ef76
TP2000-1168 Add sub-quota, blocking period & suspension period nested…
dalecannon Jan 17, 2024
b34a5cd
Feat: expand expiring quotas report to include tabs (#1131)
nboyse Jan 17, 2024
38e4f01
feat: invoke UI changes to reports and create new URL path to handle …
nboyse Jan 18, 2024
c861f24
feat: Add both CSV and excel types for charts exporting (#1136)
nboyse Jan 19, 2024
062c52b
TP2000-1185 Add maintenance mode (#1137)
mattjamc Jan 22, 2024
ee7da3c
Increment message id & record sequence number correctly (#1083)
a-gleeson Jan 22, 2024
d7f9611
feat: implement URLs for quota reports to ease navigation (#1135)
nboyse Jan 23, 2024
bafbc72
Update readme with maintenance mode instructions. (#1140)
paulpepper-trade Jan 26, 2024
8ecd002
TP2000-1130 Move current workbasket from Session to custom User model…
mattjamc Jan 29, 2024
0dae8b5
Bump aiohttp from 3.9.1 to 3.9.2 (#1142)
dependabot[bot] Jan 30, 2024
9fe334d
update importer model matching to account for end dated objects. (#1146)
dougmills-DIT Feb 6, 2024
53cb3ac
Tp2000 1211 (#1148)
dougmills-DIT Feb 7, 2024
641a434
Bump django from 3.2.23 to 3.2.24 (#1150)
dependabot[bot] Feb 8, 2024
4db2ff3
Tp2000 652 force rule check after real edit (#1130)
a-gleeson Feb 8, 2024
86da168
TP2000-1219 Prevent maintenance mode errors (#1152)
dalecannon Feb 14, 2024
a372cbc
Formatting updates and adding end date field to footnote create (#1154)
mattjamc Feb 14, 2024
bd2020f
TP2000-1114: React enhanced forms proof of concept (#1091)
eadpearce Feb 14, 2024
d4e274e
Move babel packages out of dev deps (#1155)
eadpearce Feb 14, 2024
0b23dec
initial commit - ref doc data model
dougmills-DIT Feb 6, 2024
2e5e86e
wip commit
dougmills-DIT Feb 8, 2024
353ffcb
initial commit - ref doc data model
dougmills-DIT Feb 6, 2024
ed19ef1
wip commit
dougmills-DIT Feb 13, 2024
34d3f5e
wip commit
dougmills-DIT Feb 14, 2024
edb1804
initial commit - ref doc data model
dougmills-DIT Feb 6, 2024
25f803d
wip commit
dougmills-DIT Feb 8, 2024
641cfe3
initial commit - ref doc data model
dougmills-DIT Feb 6, 2024
af15b0d
wip commit
dougmills-DIT Feb 14, 2024
d1d4412
added alignment report, reference document and reference document ver…
dougmills-DIT Feb 20, 2024
8fe80b8
added alignment report, reference document and reference document ver…
dougmills-DIT Feb 20, 2024
5e95288
merge from megabranch
dougmills-DIT Feb 20, 2024
fef34d9
prep for merge to mega branch
dougmills-DIT Feb 21, 2024
c430ba1
prep for merge to mega branch
dougmills-DIT Feb 21, 2024
b9b54e7
prep for merge to mega branch
dougmills-DIT Feb 23, 2024
e10118a
Tp2000 1186 ref doc data model (#1164)
dougmills-DIT Feb 23, 2024
ef0c125
prep for merge to mega branch
dougmills-DIT Feb 23, 2024
2f61117
Merge remote-tracking branch 'origin/TP2000-1129-reference-documents-…
dougmills-DIT Feb 23, 2024
5a72f9b
Add command to import duties and quotas
dougmills-DIT Feb 23, 2024
d547f84
Add command to import duties and quotas
dougmills-DIT Feb 23, 2024
6167197
Functionality to edit reference documents
mattjamc Feb 26, 2024
c432681
CRUD templates
mattjamc Feb 26, 2024
7af88a7
Reference Doc CRUD
mattjamc Feb 27, 2024
35655e9
Add factories, add editing for rates - still WIP but working
dougmills-DIT Feb 28, 2024
c198cc0
Add factories, add editing for rates - still WIP but working
dougmills-DIT Feb 28, 2024
66c38f7
Added test on success banner following business rule checks passing o…
mattjamc Feb 28, 2024
442f0bb
Add factories, add editing for rates - still WIP but working
dougmills-DIT Feb 28, 2024
56e1e3f
TP2000-1232 Reference doc UI management (#1165)
mattjamc Feb 28, 2024
28fc44b
Merge branch 'TP2000-1129-reference-documents-megabranch' of github.c…
mattjamc Feb 28, 2024
fde420f
fixed time zone issue with factories.py
dougmills-DIT Feb 28, 2024
455cc73
Create update form tests
mattjamc Feb 28, 2024
6cf338e
Merge branch 'TP2000-1129-reference-documents-megabranch' of github.c…
mattjamc Feb 28, 2024
3fbf34f
fixed time zone issue with factories.py
dougmills-DIT Feb 28, 2024
8545e49
add basic tests for models
dougmills-DIT Feb 29, 2024
b5599e9
add basic tests for models
dougmills-DIT Feb 29, 2024
3bd7472
Add test init files
mattjamc Feb 29, 2024
22b47f3
View and form tests for ref doc crud
mattjamc Feb 29, 2024
f37c7ce
Merge branch 'TP2000-1129-reference-documents-megabranch' of github.c…
mattjamc Feb 29, 2024
fc1d3f0
Remove init files
mattjamc Feb 29, 2024
a4b461b
Add reference doc form and view tests
mattjamc Feb 29, 2024
290a3da
Move get_area_name_by_id to model
mattjamc Mar 1, 2024
5cb642f
add basic tests for models
dougmills-DIT Mar 1, 2024
b10aad9
add basic tests for models
dougmills-DIT Mar 1, 2024
d33d92a
add basic tests for models
dougmills-DIT Mar 4, 2024
197fbce
update edit quota view
dougmills-DIT Mar 4, 2024
fd32c27
fix views
dougmills-DIT Mar 4, 2024
205c0f6
Ref doc versions create and edit urls/templates
mattjamc Mar 4, 2024
7629f43
Ref doc formatting tidy up
mattjamc Mar 4, 2024
5aac540
Ref doc versions create and edit views/form
mattjamc Mar 4, 2024
ca751d2
Merge branch 'TP2000-1129-reference-documents-megabranch' of github.c…
mattjamc Mar 4, 2024
b0f2c55
fix views
dougmills-DIT Mar 5, 2024
6f08bcb
Merge remote-tracking branch 'origin/TP2000-1129-reference-documents-…
dougmills-DIT Mar 5, 2024
14e732d
fix views
dougmills-DIT Mar 5, 2024
8950683
Update ref doc create breadcrumbs
mattjamc Mar 5, 2024
85cedb1
Ref doc version delete
mattjamc Mar 5, 2024
86a3e52
Merge branch 'TP2000-1129-reference-documents-megabranch' of github.c…
mattjamc Mar 5, 2024
6f9cb69
Delete ref doc version and confirmation pages
mattjamc Mar 6, 2024
12d9533
Area ID and version form validation
mattjamc Mar 6, 2024
cd8b173
update data
dougmills-DIT Mar 6, 2024
b27283c
Merge remote-tracking branch 'origin/TP2000-1129-reference-documents-…
dougmills-DIT Mar 6, 2024
f0a2fd7
Ref doc versions form and view tests
mattjamc Mar 6, 2024
c0b133b
Add model test for get_area_name_by_id
mattjamc Mar 7, 2024
406a516
Merge branch 'TP2000-1129-reference-documents-megabranch' of github.c…
mattjamc Mar 7, 2024
0efc1f1
Update data model
dougmills-DIT Mar 7, 2024
b9dcdda
Merge remote-tracking branch 'origin/TP2000-1129-reference-documents-…
dougmills-DIT Mar 7, 2024
22268d4
Preferential rate style and consistency tidy
mattjamc Mar 7, 2024
343e363
separate out the context from reference document version details
dougmills-DIT Mar 8, 2024
7161b01
separate out the context from reference document version details
dougmills-DIT Mar 8, 2024
32df83d
separate out the context from reference document version details
dougmills-DIT Mar 8, 2024
c8b5294
separate out the context from reference document version details
dougmills-DIT Mar 8, 2024
30770c1
separate out the context from reference document version details
dougmills-DIT Mar 8, 2024
c264d0c
Pref quota bulk create base
mattjamc Mar 8, 2024
3d0b9b0
Merge branch 'TP2000-1129-reference-documents-megabranch' of github.c…
mattjamc Mar 8, 2024
e6007c7
add / edit order number
dougmills-DIT Mar 11, 2024
860ab4b
Merge remote-tracking branch 'origin/TP2000-1129-reference-documents-…
dougmills-DIT Mar 11, 2024
2113323
Bulk add preferential quotas for a commodity code list
mattjamc Mar 11, 2024
0fbeeb4
add / edit order number
dougmills-DIT Mar 12, 2024
8b39d1a
Bulk create quotas for multiple validity period volume combos
mattjamc Mar 12, 2024
4c05783
Merge branch 'TP2000-1129-reference-documents-megabranch' of github.c…
mattjamc Mar 13, 2024
44aaf01
WIP commit - quota and order number updates
dougmills-DIT Mar 15, 2024
26685e2
WIP commit - quota and order number updates
dougmills-DIT Mar 18, 2024
5235106
quota and order number views + test fixes
dougmills-DIT Mar 18, 2024
531695c
quota and order number views + test fixes
dougmills-DIT Mar 18, 2024
4c27d3a
Bulk create quotas redo without validityperiodform
mattjamc Mar 18, 2024
adfd87e
Merge branch 'TP2000-1129-reference-documents-megabranch' of github.c…
mattjamc Mar 18, 2024
d135a45
test fixes
dougmills-DIT Mar 19, 2024
51f8dc0
Merge remote-tracking branch 'origin/TP2000-1129-reference-documents-…
dougmills-DIT Mar 19, 2024
cbe694f
Add js remove button to additional quota definition forms
mattjamc Mar 19, 2024
88f9ca8
Merge branch 'TP2000-1129-reference-documents-megabranch' of github.c…
mattjamc Mar 19, 2024
2193470
tested quota order number and quota forms
dougmills-DIT Mar 20, 2024
e8a078d
Merge remote-tracking branch 'origin/TP2000-1129-reference-documents-…
dougmills-DIT Mar 20, 2024
f7b702b
Preferential quota bulk create tests
mattjamc Mar 20, 2024
dd1f7b4
Merge branch 'TP2000-1129-reference-documents-megabranch' of github.c…
mattjamc Mar 20, 2024
accb894
Content standardisations
mattjamc Mar 21, 2024
cf9d80c
Add preferential quota bulk create for specific order numbers
mattjamc Mar 21, 2024
416f7b1
models 100% tested, forms 100% tested
dougmills-DIT Mar 25, 2024
e12618c
models 100% tested, forms 100% tested
dougmills-DIT Mar 27, 2024
7b4833e
models 100% tested, forms 100% tested
dougmills-DIT Mar 27, 2024
9a7373d
Ref doc and versions view tests
mattjamc Mar 28, 2024
83b046a
added more tests
dougmills-DIT Mar 28, 2024
a87ac50
Merge remote-tracking branch 'origin/TP2000-1129-reference-documents-…
dougmills-DIT Mar 28, 2024
4e714ad
added more tests
dougmills-DIT Apr 2, 2024
6a246f0
Quota order number check
mattjamc Apr 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,4 @@ _dumped_cache.pkl

# Database dumps
*.sql
/.vscode/settings.json
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,21 @@ This tool is available as an importer alternative found within the web front end

This tool addresses several short falls that the current importer has.

Reference document data import
------------------------------

WARNING: this feature is in alpha : do not use in production until this feature has been
fully tested.

In order to populate the reference document data from extracted data from an external tool
you can use the management command ref_doc_csv_importer

Example:

.. code:: sh

$ python manage.py ref_doc_csv_importer "/absolute/path/to/duties.csv" "/absolute/path/to/quotas.csv"

Using the exporter
------------------

Expand Down
26 changes: 26 additions & 0 deletions common/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,32 @@ def compress(self, data_list):
return None


class DateInputFieldTakesParameters(DateInputField):
def __init__(self, day, month, year, **kwargs):
error_messages = {
"required": "Enter the day, month and year",
"incomplete": "Enter the day, month and year",
}
fields = (day, month, year)

forms.MultiValueField.__init__(
self,
error_messages=error_messages,
fields=fields,
**kwargs,
)

def compress(self, data_list):
day, month, year = data_list or [None, None, None]
if day and month and year:
try:
return date(day=int(day), month=int(month), year=int(year))
except ValueError as e:
raise ValidationError(str(e).capitalize()) from e
else:
return None


class GovukDateRangeField(DateRangeField):
base_field = DateInputFieldFixed

Expand Down
2 changes: 1 addition & 1 deletion common/jinja2/common/edit.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% endblock %}

{% block form %}
{% call django_form(action=object.get_url("edit")) %}
{% call django_form() %}
{{ crispy(form) }}
{% endcall %}
{% endblock %}
55 changes: 55 additions & 0 deletions common/static/common/js/addNewQuotaDefinitionForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { removeQuotaDefinitionForm } from "./removeQuotaDefinitionForm.js"

let formCounter = 1

const addNewForm = (event) => {
event.preventDefault();

let fieldset = document.querySelector(".quota-definition-row");
let formset = fieldset.parentNode;
let newForm = fieldset.cloneNode(true);

let new_class = "quota-definition-row-" + formCounter
newForm.classList.add(new_class)

newForm.innerHTML = newForm.innerHTML.replaceAll('name="volume_0"', 'name="volume_' + formCounter + '"');
newForm.innerHTML = newForm.innerHTML.replaceAll('name="start_date_0_0"', 'name="start_date_' + formCounter + '_0"');
newForm.innerHTML = newForm.innerHTML.replaceAll('name="start_date_0_1"', 'name="start_date_' + formCounter + '_1"');
newForm.innerHTML = newForm.innerHTML.replaceAll('name="start_date_0_2"', 'name="start_date_' + formCounter + '_2"');
newForm.innerHTML = newForm.innerHTML.replaceAll('name="end_date_0_0"', 'name="end_date_' + formCounter + '_0"');
newForm.innerHTML = newForm.innerHTML.replaceAll('name="end_date_0_1"', 'name="end_date_' + formCounter + '_1"');
newForm.innerHTML = newForm.innerHTML.replaceAll('name="end_date_0_2"', 'name="end_date_' + formCounter + '_2"');

let removeFormID = "form-remove_" + formCounter;
newForm.insertAdjacentHTML("beforeend", `<div><a id="${removeFormID}" class="govuk-link govuk-form-group remove-quota-definition" href="#" style="font-size:19px" >Remove</a><br></div>`);
let remove_button = newForm.lastChild
remove_button.addEventListener("click", removeQuotaDefinitionForm);

let formFields = newForm.querySelectorAll("input");
for (let field of formFields.values()) {
field.value = "";
}

let buttonGroup = document.querySelector('.govuk-button-group');
formset.insertBefore(newForm, buttonGroup);

let numForms = document.querySelectorAll(".quota-definition-row").length;

let addNewButton = document.querySelector("#add-new-definition");
addNewButton.scrollIntoView(false);
formCounter += 1;
if (numForms >= 10) {
addNewButton.style.display = "none";
}

}

const initAddNewDefinition = () => {
const btn = document.querySelector("#add-new-definition");

if (btn) {
btn.addEventListener("click", addNewForm);
}
}

export { initAddNewDefinition }
2 changes: 2 additions & 0 deletions common/static/common/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require.context('govuk-frontend/govuk/assets');
import showHideCheckboxes from './showHideCheckboxes';
import { initAutocomplete } from './autocomplete';
import { initAutocompleteProgressiveEnhancement } from './autocompleteProgressiveEnhancement';
import { initAddNewDefinition } from './addNewQuotaDefinitionForm';
import { initAddNewEnhancement } from './addNewForm';
import { initCopyToNextDuties } from './copyDuties';
import { initAll } from 'govuk-frontend';
Expand All @@ -21,6 +22,7 @@ showHideCheckboxes();
// Initialise accessible-autocomplete components without a `name` attr in order
// to avoid the "dummy" autocomplete field being submitted as part of the form
// to the server.
initAddNewDefinition();
initAddNewEnhancement();
initAutocomplete(false);
initCopyToNextDuties();
Expand Down
19 changes: 19 additions & 0 deletions common/static/common/js/removeQuotaDefinitionForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const removeQuotaDefinitionForm = (event) => {
event.preventDefault();
let remove_id = event.target.id;
let remove_number = remove_id.split('_').at(-1)

let fieldset_id = 'quota-definition-row-' + remove_number

let fieldset_to_remove = document.querySelector(".quota-definition-row-" + remove_number)
fieldset_to_remove.remove()

let addNewButton = document.querySelector("#add-new-definition");
let numForms = document.querySelectorAll(".quota-definition-row").length;
if (numForms < 10) {
addNewButton.style.display = "inline"
}

}

export { removeQuotaDefinitionForm }
1 change: 1 addition & 0 deletions common/static/common/scss/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ $govuk-image-url-function: frontend-image-url;
@import "publishing";
@import "regulations";
@import "workbaskets";
@import "reference_documents";
@import "versions";
@import "fake-link";
@import "violations";
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ norecursedirs = [
"venv",
]
markers = [
"importer_v2"
"importer_v2",
"reference_documents"
]
Empty file.
1 change: 1 addition & 0 deletions reference_documents/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Register your models here.
102 changes: 102 additions & 0 deletions reference_documents/alignment_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from commodities.models import GoodsNomenclature
from geo_areas.models import GeographicalArea
from datetime import date

from commodities.models import GoodsNomenclature
from geo_areas.models import GeographicalArea
from geo_areas.models import GeographicalAreaDescription
from reference_documents.models import PreferentialRate


class BaseCheck:
def run_check(self):
raise NotImplemented("Please implement on child classes")


class BasePreferentialRateCheck(BaseCheck):
def __init__(self, preferential_rate: PreferentialRate):
self.preferential_rate = preferential_rate

def comm_code(self):
goods = GoodsNomenclature.objects.latest_approved().filter(
item_id=self.preferential_rate.commodity_code,
valid_between__contains=self.ref_doc_version_eif_date(),
suffix=80,
)

if len(goods) == 0:
return None

return goods.first()

def geo_area(self):
return (
GeographicalArea.objects.latest_approved()
.filter(
area_id=self.preferential_rate.reference_document_version.reference_document.area_id,
)
.first()
)

def geo_area_description(self):
geo_area_desc = (
GeographicalAreaDescription.objects.latest_approved()
.filter(described_geographicalarea=self.geo_area())
.last()
)
return geo_area_desc.description

def ref_doc_version_eif_date(self):
eif_date = (
self.preferential_rate.reference_document_version.entry_into_force_date
)

# todo : make sure EIf dates are all populated correctly - and remove this
if eif_date is None:
eif_date = date.today()

return eif_date

def related_measures(self):
return (
self.comm_code()
.measures.latest_approved()
.filter(
geographical_area=self.geo_area(),
valid_between__contains=self.ref_doc_version_eif_date(),
)
)

def run_check(self):
raise NotImplementedError("Please implement on child classes")


class CheckPreferentialRateCommCode(BasePreferentialRateCheck):
def run_check(self):
# comm code live on EIF date
if not self.comm_code():
print(
"FAIL",
self.preferential_rate.commodity_code,
self.geo_area_description(),
"comm code not live",
)
return False

measures = self.related_measures()

if len(measures) == 1:
print("PASS", self.comm_code(), self.geo_area_description())
return True

if len(measures) == 0:
print("FAIL", self.comm_code(), self.geo_area_description())
return False

if len(measures) > 1:
print(
"WARNING - multiple measures",
self.comm_code(),
self.geo_area_description(),
)
return True
5 changes: 5 additions & 0 deletions reference_documents/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from common.app_config import CommonConfig


class ReferenceDocumentsConfig(CommonConfig):
name = "reference_documents"
Loading
Loading