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

Tracking pull request to merge release-1.49.0 to master #1916

Merged
merged 12 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 18 additions & 7 deletions .github/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,27 @@ Notes: the change may take about 20 minutes to be promoted to Zeva development e

The "Build PR on Dev" pipeline will be triggered when it identified pull request's title ends with "build-on-dev"

# Post production release
# Production release

## Merge the tracking pull request and create the new release branch
## Pre-production release

* Update the description of the tracking pull request
* Verify the changes made during the previous post production release

## Production release

* Manually trigger the pipeline release-build.yaml (Release Build 1.49.0)

## Post production release

### Merge the tracking pull request and create the new release branch

* Squash merge the tracking pull request to master
* Create the release on GitHub from master branch
* Create the new release branch from master branch (this is done automatically by pipeline create-release.yaml)
* Change the new release branch as the default branch in the repo and update the branch protection rules https://github.com/bcgov/zeva/settings/branches

## Updates for the new release branch
### Updates for the new release branch

* dev-build.yaml
* on -> push -> branches
Expand All @@ -43,9 +54,9 @@ The "Build PR on Dev" pipeline will be triggered when it identified pull request
## Primary Pipelines

* build-on-dev.yaml (Build PR on Dev): Build pull request if the string build-on-dev is appended at the end of pull request title
* dev-build.yaml (Dev Build 1.48.0): Every commit on the current release branch is automatically released to Dev.
* release-build.yaml (Release Build 1.48.0): This is a manually managed pipeline. It needs to be triggered manually to build the current release branch and deploy on Test and further on Prod.
* create-release.yaml (Create Release after merging to master): Tag and create the release after merging release branch to master. The description of the tracking pull request becomes release notes.
* dev-build.yaml (Dev Build 1.49.0): Every commit on the current release branch is automatically released to Dev.
* release-build.yaml (Release Build 1.49.0): This is a manually managed pipeline. It needs to be triggered manually to build the current release branch and deploy on Test and further on Prod.
* create-release.yaml (Create Release after merging to master): Automatically tag and create the release after merging release branch to master. The description of the tracking pull request becomes release notes.

## Other Pipelines

Expand All @@ -55,5 +66,5 @@ The "Build PR on Dev" pipeline will be triggered when it identified pull request
* pr-build-template.yaml (PR Build Template): a pipeline template for pull request build
* pr-lable.yaml (Label PR): ignore this one for now, it is automatically triggered after the pull request is merged or closed
* pr-teardown.yaml (Teardown PR on Dev): remove the deployed pull request on Dev
* release-build.yaml (Release Build 1.48.0): a pipeline to build release branch
* release-build.yaml (Release Build 1.49.0): a pipeline to build release branch
* unit-test-template.yaml (Unit Test Template): a pipeline template for unit test
10 changes: 5 additions & 5 deletions .github/workflows/dev-build.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## For each release, please update the value of workflow name, branches and PR_NUMBER
## Also update frontend/package.json version

name: Dev Build 1.48.0
name: Dev Build 1.49.0

on:
push:
branches: [ release-1.48.0 ]
branches: [ release-1.49.0 ]
paths:
- frontend/**
- backend/**
Expand All @@ -14,8 +14,8 @@ on:

env:
## The pull request number of the Tracking pull request to merge the release branch to main
PR_NUMBER: 1818
VERSION: 1.48.0
PR_NUMBER: 1916
VERSION: 1.49.0
GIT_URL: https://github.com/bcgov/zeva.git
TOOLS_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools
DEV_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-dev
Expand All @@ -32,7 +32,7 @@ jobs:
call-unit-test:
uses: ./.github/workflows/unit-test-template.yaml
with:
pr-number: 1818
pr-number: 1916

build:

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release-build.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
## For each release, please update the value of workflow name, branches and PR_NUMBER
## Also update frontend/package.json version

name: Release Build 1.48.0
name: Release Build 1.49.0

on:
workflow_dispatch:
workflow_call:

env:
## The pull request number of the Tracking pull request to merge the release branch to main
PR_NUMBER: 1818
VERSION: 1.48.0
PR_NUMBER: 1916
VERSION: 1.49.0
GIT_URL: https://github.com/bcgov/zeva.git
TOOLS_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools
DEV_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-dev
Expand All @@ -27,7 +27,7 @@ jobs:
call-unit-test:
uses: ./.github/workflows/unit-test-template.yaml
with:
pr-number: 1818
pr-number: 1916

build:

Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
with:
secret: ${{ github.TOKEN }}
approvers: AlexZorkin,kuanfandevops,tim738745,emi-hi,jig-patel,prv-proton,JulianForeman
minimum-approvals: 1
minimum-approvals: 2
issue-title: "ZEVA ${{ env.VERSION }} Prod Deployment"

- name: Tag Frontend Image from tools to Prod
Expand Down
17 changes: 9 additions & 8 deletions backend/api/serializers/credit_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,26 +157,27 @@ def get_sufficient_credits(self, _obj):
request = self.context.get('request')
if request.user.is_government:
supplier_balance = calculate_insufficient_credits(
self.instance.debit_from)
self.instance.debit_from, self.instance)
content = CreditTransferContent.objects.filter(
credit_transfer_id=self.instance.id
)
content_count = 0
for each in content:
content_count += 1
request_year = each.model_year.id
request_credit_class = each.credit_class.id
request_weight = each.weight_class.id
request_credit_value = each.credit_value

request_weight = 1
for record in supplier_balance:
if request_weight == record['weight_class_id']:
if request_year == record['model_year_id']:
if request_credit_class == record['credit_class_id']:
content_count -= 1
if record['total_value'] < 0:
has_credits = False
if content_count > 0:
record['total_value'] = Decimal(record['total_value']) - request_credit_value

for record in supplier_balance:
if record['total_value'] < 0:
has_credits = False
break

return has_credits

def get_status(self, obj):
Expand Down
9 changes: 6 additions & 3 deletions backend/api/services/credit_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,19 @@ def aggregate_transactions_by_submission(organization):
return transactions


def calculate_insufficient_credits(org_id):
def calculate_insufficient_credits(org_id, credit_transfer_to_exclude=None):
issued_balances = aggregate_credit_balance_details(org_id)
issued_balances_list = list(issued_balances)
pending_balance = aggregate_credit_transfer_details(org_id)
for index, balance in enumerate(issued_balances_list):
pending = pending_balance.filter(
pending_qs = pending_balance.filter(
model_year_id=balance['model_year_id'],
credit_class_id=balance['credit_class_id'],
weight_class_id=balance['weight_class_id']
).first()
)
if credit_transfer_to_exclude is not None:
pending_qs = pending_qs.exclude(credit_transfer=credit_transfer_to_exclude)
pending = pending_qs.first()
if pending:
total_balance = balance['total_value'] + pending['credit_value']
update_list = {
Expand Down
15 changes: 15 additions & 0 deletions backend/api/services/model_year_report_ldv_sales.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from api.models.model_year_report_ldv_sales import ModelYearReportLDVSales


def get_most_recent_ldv_sales(model_year_report):
ldv_sales_obj = (
ModelYearReportLDVSales.objects.filter(
model_year=model_year_report.model_year, model_year_report=model_year_report
)
.order_by("-create_timestamp")
.only("ldv_sales")
.first()
)
if ldv_sales_obj:
return ldv_sales_obj.ldv_sales
return None
1 change: 1 addition & 0 deletions backend/api/services/supplemental_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def get_map_of_model_year_report_ids_to_latest_supplemental_ids(
def get_ordered_list_of_supplemental_reports(model_year_report, *fields):
reports = list(
SupplementalReport.objects.filter(model_year_report=model_year_report)
.exclude(status=ModelYearReportStatuses.DELETED)
.only("id", "supplemental_id", *fields)
.order_by("create_timestamp")
)
Expand Down
34 changes: 19 additions & 15 deletions backend/api/viewsets/model_year_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
SupplementalModelYearReportSerializer,
)
from api.models.organization import Organization
from api.services.supplemental_report import get_ordered_list_of_supplemental_reports


class ModelYearReportViewset(
Expand Down Expand Up @@ -339,27 +340,21 @@ def supplemental_history(self, request, pk=None):
exclude_supplemental_reports = []
for report in supplemental_reports:
if report.status.value in ["DRAFT", "RETURNED"] and (
request.user.is_government and not report.is_reassessment
):
exclude_supplemental_reports.append(report.id)
request.user.is_government and not report.is_reassessment
):
exclude_supplemental_reports.append(report.id)

if report.is_reassessment:
if (
report.status.value not in ["ASSESSED", "REASSESSED"]
and not request.user.is_government
):
exclude_supplemental_reports.append(report.id)

# If it's a reassessment report from a supplementary
# we don't need it as we've already added an entry to the
# history for the actual supplementary report created by
# the bceid user
supplemental_report = SupplementalReport.objects.filter(
supplemental_id=report.supplemental_id
).first()

if supplemental_report and supplemental_report.from_supplemental:
exclude_supplemental_reports.append(report.id)
exclude_supplemental_reports.append(report.id)
else:
if request.user.is_government and report.status.value == 'SUBMITTED':
next_report = SupplementalReport.objects.filter(supplemental_id=report.id).exclude(status=ModelYearReportStatuses.DELETED).first()
if next_report and next_report.is_reassessment:
exclude_supplemental_reports.append(report.id)

supplemental_reports = supplemental_reports.exclude(
id__in=exclude_supplemental_reports
Expand Down Expand Up @@ -1176,3 +1171,12 @@ def assessed_supplementals(self, request, pk):
data, context={"request": request}, many=True
)
return Response(serializer.data)

@action(detail=True, methods=["get"])
def latest_supplemental_status(self, request, pk):
result = None
supplementals = get_ordered_list_of_supplemental_reports(pk, "status")
if supplementals:
result = supplementals[-1].status.value
return Response(result)

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
get_current_year_balance
from api.models.organization_deficits import OrganizationDeficits
from api.services.supplemental_report import get_latest_assessed_supplemental
from api.services.model_year_report_ldv_sales import get_most_recent_ldv_sales


class ModelYearReportComplianceObligationViewset(
Expand Down Expand Up @@ -163,6 +164,9 @@ def details(self, request, *args, **kwargs):
summary_param = request.GET.get('summary', None)
summary = True if summary_param == "true" else None

most_recent_ldv_sales_param = request.GET.get("most_recent_ldv_sales", None)
most_recent_ldv_sales = True if most_recent_ldv_sales_param == "true" else False

organization = request.user.organization
id = kwargs.get('id')
report = get_object_or_404(ModelYearReport, pk=id)
Expand Down Expand Up @@ -526,7 +530,7 @@ def details(self, request, *args, **kwargs):
return Response({
'compliance_obligation': content + serializer.data,
'compliance_offset': compliance_offset,
'ldv_sales': report.ldv_sales
'ldv_sales': get_most_recent_ldv_sales(report) if most_recent_ldv_sales else report.ldv_sales
})
else:
serializer = ModelYearReportComplianceObligationSnapshotSerializer(
Expand All @@ -535,5 +539,5 @@ def details(self, request, *args, **kwargs):
return Response({
'compliance_obligation': serializer.data,
'compliance_offset': compliance_offset,
'ldv_sales': report.ldv_sales
'ldv_sales': get_most_recent_ldv_sales(report) if most_recent_ldv_sales else report.ldv_sales
})
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zeva-frontend",
"version": "1.48.0",
"version": "1.49.0",
"private": true,
"dependencies": {
"@babel/eslint-parser": "^7.19.1",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/routes/Compliance.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const COMPLIANCE = {
MAKES: `${API_BASE_PATH}/reports/:id/makes`,
SUPPLEMENTAL_CREATE: `${API_BASE_PATH}/reports/:id/supplemental_save`,
NOA_HISTORY: `${API_BASE_PATH}/reports/:id/noa_history`,
SUPPLEMENTAL_HISTORY: `${API_BASE_PATH}/reports/:id/supplemental_history`
SUPPLEMENTAL_HISTORY: `${API_BASE_PATH}/reports/:id/supplemental_history`,
LATEST_SUPPLEMENTAL_STATUS: `${API_BASE_PATH}/reports/:id/latest_supplemental_status`
}

export default COMPLIANCE
58 changes: 0 additions & 58 deletions frontend/src/compliance/components/AssessmentDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,56 +322,6 @@ const AssessmentDetailsPage = (props) => {
<div className="col-12">
<div id="compliance-obligation-page">
<span className="float-right d-print-none">
{CONFIG.FEATURES.SUPPLEMENTAL_REPORT.ENABLED &&
!user.isGovernment &&
statuses.assessment.status === 'ASSESSED' &&
((!supplementaryId && supplementaryStatus === 'DRAFT') ||
(supplementaryStatus === 'DRAFT' && createdByGov) ||
supplementaryStatus === 'DELETED' ||
supplementaryStatus === 'ASSESSED') && (
<Button
buttonTooltip={reassessmentTooltip}
buttonType="submit"
optionalClassname="btn button primary"
optionalText="Create Supplementary Report"
disabled={reassessmentExists}
action={() => {
history.push(
`${ROUTES_SUPPLEMENTARY.CREATE.replace(
/:id/g,
id
)}`
)
}}
/>
)}

{CONFIG.FEATURES.SUPPLEMENTAL_REPORT.ENABLED &&
user.isGovernment &&
user.hasPermission('RECOMMEND_COMPLIANCE_REPORT') &&
statuses.assessment.status === 'ASSESSED' &&
((!supplementaryId && supplementaryStatus === 'DRAFT') ||
(supplementaryStatus === 'DRAFT' && !createdByGov) ||
supplementaryStatus === 'DELETED' ||
supplementaryStatus === 'ASSESSED') && (
<>
<button
className="btn button primary"
onClick={() => {
history.push(
`${ROUTES_SUPPLEMENTARY.REASSESSMENT.replace(
/:id/g,
id
)}`
)
}}
type="button"
>
Create Reassessment Report
</button>
</>
)}

{analystAction &&
['RETURNED', 'SUBMITTED', 'UNSAVED'].indexOf(
statuses.assessment.status
Expand All @@ -388,14 +338,6 @@ const AssessmentDetailsPage = (props) => {
Edit
</button>
)}
<Button
buttonType="button"
optionalClassname="ml-2 mr-2 button btn"
optionalText="Print Page"
action={() => {
window.print()
}}
/>
</span>

<NoticeOfAssessmentSection
Expand Down
Loading