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-2.20.0 to master #2894

Merged
merged 7 commits into from
Sep 4, 2024
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
8 changes: 4 additions & 4 deletions .github/workflows/dev-release.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## For each release, the value of name, branches, RELEASE_NAME and PR_NUMBER need to be adjusted accordingly
## For each release, update lib/config.js: version and releaseBranch

name: TFRS Dev release-2.19.0
name: TFRS Dev release-2.20.0

on:
push:
branches: [ release-2.19.0 ]
branches: [ release-2.20.0 ]
paths:
- frontend/**
- backend/**
Expand All @@ -15,8 +15,8 @@ on:
env:
## The pull request number of the Tracking pull request to merge the release branch to main
## Also remember to update the version in .pipeline/lib/config.js
PR_NUMBER: 2885
RELEASE_NAME: release-2.19.0
PR_NUMBER: 2894
RELEASE_NAME: release-2.20.0

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
41 changes: 16 additions & 25 deletions .github/workflows/tfrs-release.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## For each release, the value of name, branches, RELEASE_NAME and PR_NUMBER need to be adjusted accordingly
## For each release, update lib/config.js: version and releaseBranch

name: TFRS release-2.19.0
name: TFRS release-2.20.0

on:
workflow_dispatch:
Expand All @@ -10,35 +10,32 @@ on:
env:
## The pull request number of the Tracking pull request to merge the release branch to main
## Also remember to update the version in .pipeline/lib/config.js
PR_NUMBER: 2885
RELEASE_NAME: release-2.19.0
PR_NUMBER: 2894
RELEASE_NAME: release-2.20.0

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

unit-test:

name: Run Backend Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 60

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run coverage report for django tests

- name: Run coverage report for django tests
uses: kuanfandevops/django-test-action@itvr-django-test
continue-on-error: true
with:
settings-dir-path: "backend/api"
requirements-file: "backend/requirements.txt"
managepy-dir: backend

lint:

lint:
name: Linting
runs-on: ubuntu-latest
timeout-minutes: 60
Expand All @@ -47,13 +44,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Frontend Linting
- name: Frontend Linting
continue-on-error: true
run: |
cd frontend
pwd
npm install
npm run lint
npm run lint

- name: Backend linting
uses: github/super-linter/slim@v4
Expand All @@ -66,20 +63,18 @@ jobs:
LOG_LEVEL: WARN

build:

name: Build TFRS on Openshift
runs-on: ubuntu-latest
timeout-minutes: 60

steps:

## it will checkout to /home/runner/work/itvr/itvr
- name: Check out repository
uses: actions/checkout@v3

## Log in to Openshift with a token of service account
- name: Log in to Openshift
##uses: redhat-actions/oc-login@v1
##uses: redhat-actions/oc-login@v1
uses: smlgbl/oc-login@main
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
Expand All @@ -92,17 +87,15 @@ jobs:
run: |
cd .pipeline
npm install
npm run build -- --pr=${{ env.PR_NUMBER }} --env=build
npm run build -- --pr=${{ env.PR_NUMBER }} --env=build

deploy-on-test:

name: Deploy TFRS on Test
runs-on: ubuntu-latest
timeout-minutes: 240
needs: build

steps:

## it will checkout to /home/runner/work/itvr/itvr
- name: Check out repository
uses: actions/checkout@v3
Expand All @@ -114,31 +107,29 @@ jobs:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools
namespace: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools

- name: Ask for approval for TFRS Test deployment
uses: trstringer/[email protected]
with:
secret: ${{ github.TOKEN }}
approvers: AlexZorkin,emi-hi,tim738745,kuanfandevops,jig-patel,prv-proton,JulianForeman
approvers: AlexZorkin,kuanfandevops,prv-proton,JulianForeman,kevin-hashimoto,dhaselhan
minimum-approvals: 1
issue-title: "TFRS ${{ env.RELEASE_NAME }} Test Deployment"

- name: Run deploy
run: |
cd .pipeline
npm install
npm run deploy -- --pr=${{ env.PR_NUMBER }} --env=test
npm run deploy -- --pr=${{ env.PR_NUMBER }} --env=test

deploy-on-prod:

name: Deploy TFRS on Prod
runs-on: ubuntu-latest
timeout-minutes: 2880
needs: deploy-on-test

steps:

## it will checkout to /home/runner/work/itvr/itvr
- name: Check out repository
uses: actions/checkout@v3
Expand All @@ -150,18 +141,18 @@ jobs:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools
namespace: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools

- name: Ask for approval for TFRS Prod deployment
uses: trstringer/[email protected]
with:
secret: ${{ github.TOKEN }}
approvers: AlexZorkin,kuanfandevops,tim738745,jig-patel,prv-proton,JulianForeman
approvers: AlexZorkin,kuanfandevops,prv-proton,JulianForeman,kevin-hashimoto,dhaselhan
minimum-approvals: 2
issue-title: "TFRS ${{ env.RELEASE_NAME }} Prod Deployment"

- name: Run deploy
run: |
cd .pipeline
npm install
npm run deploy -- --pr=${{ env.PR_NUMBER }} --env=prod
npm run deploy -- --pr=${{ env.PR_NUMBER }} --env=prod
4 changes: 2 additions & 2 deletions .pipeline/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const options= require('@bcgov/pipeline-cli').Util.parseArguments()
const changeId = options.pr //aka pull-request
const version = '2.19.0'
const version = '2.20.0'
const name = 'tfrs'
const ocpName = 'apps.silver.devops'

Expand All @@ -13,7 +13,7 @@ options.git.repository='tfrs'
const phases = {
build: { namespace:'0ab226-tools' , name: `${name}`, phase: 'build' , changeId:changeId, suffix: `-build-${changeId}` ,
instance: `${name}-build-${changeId}` , version:`${version}-${changeId}`, tag:`build-${version}-${changeId}`,
releaseBranch: 'release-2.19.0'
releaseBranch: 'release-2.20.0'
},
dev: {namespace:'0ab226-dev' , name: `${name}`, phase: 'dev' , changeId:changeId, suffix: `-dev` ,
instance: `${name}-dev` , version:`${version}`, tag:`dev-${version}`, dbServiceName: 'tfrs-spilo',
Expand Down
81 changes: 28 additions & 53 deletions backend/api/serializers/ComplianceReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,62 +89,21 @@ def get_previous_report_was_credit(self, obj):
def get_total_previous_credit_reductions(self, obj):
# Return the total number of credits for all previous reductions for
# supplemental reports
# previous_transactions = []
submitted_reports = []
previous_transactions = []
current = obj
submitted_reports_end = False
rejected_found = False

total_previous_reduction = Decimal(0.0)

# this is an attempt to simplify the process of calculation previous
# credit reductions
# If the last supplemental report was submitted we can just use the
# credit offset there as our previous reduction (which is credit offset A)
if current.supplements and current.supplements.status and \
current.supplements.status.fuel_supplier_status_id in [
"Submitted"
] and current.supplements.status.director_status_id in [
"Unreviewed"
]:
total_previous_reduction = current.supplements.summary.credits_offset
submitted_reports_end = True

while current.supplements is not None and not submitted_reports_end:
while current.supplements is not None:
current = current.supplements
if current.status.director_status_id in [
"Rejected"
]:
rejected_found = True
if current.credit_transaction is not None and \
current.status.director_status_id == "Accepted":
previous_transactions.append(current.credit_transaction)

if current.status.director_status_id in [
"Accepted"
]:
submitted_reports_end = True

# if current.credit_transaction is not None and \
# current.status.director_status_id not in ["Rejected"]:
# previous_transactions.append(current.credit_transaction)
if current.status.fuel_supplier_status_id == "Submitted" and \
not submitted_reports_end and \
not rejected_found:
submitted_reports.append(current)

if rejected_found and submitted_reports_end and current.summary:
# Clear the submitted reports and we only care about the
# last accepted one
total_previous_reduction = current.summary.credits_offset

# for transaction in previous_transactions:
# if transaction.type.the_type in ['Credit Reduction']:
# total_previous_reduction += transaction.number_of_credits
# elif transaction.type.the_type in ['Credit Validation']:
# total_previous_reduction -= transaction.number_of_credits

if not rejected_found:
for report in submitted_reports:
if report.summary and report.summary.credits_offset_b:
total_previous_reduction += report.summary.credits_offset_b
for transaction in previous_transactions:
if transaction.type.the_type == 'Credit Reduction':
total_previous_reduction += transaction.number_of_credits
elif transaction.type.the_type == 'Credit Validation':
total_previous_reduction -= transaction.number_of_credits

return total_previous_reduction

Expand Down Expand Up @@ -1123,8 +1082,24 @@ def create(self, validated_data):
original_summary.diesel_class_obligation

summary.credits_offset = original_summary.credits_offset
summary.credits_offset_a = original_summary.credits_offset or \
original_summary.credits_offset_a

# Calculate the total credits offset from all previous ACCEPTED reports
# This is necessary because credits_offset_a should represent the cumulative
# credit reductions from all accepted previous reports, not just the most recent one.
# We iterate through all previous reports (supplements) and sum up their credit offsets,
# but only if the report was accepted by the director.
total_accepted_reductions = 0
current = previous_report

while current is not None:
if current.status.director_status_id == 'Accepted' and current.summary:
if current.summary.credits_offset > 0:
total_accepted_reductions += current.summary.credits_offset
elif current.summary.credits_offset_b > 0:
total_accepted_reductions += current.summary.credits_offset_b
current = current.supplements

summary.credits_offset_a = total_accepted_reductions

credits_offset_c = original_summary.credits_offset_c
if credits_offset_c is not None and credits_offset_c > 0:
Expand Down
39 changes: 37 additions & 2 deletions backend/api/services/OrganizationService.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def get_pending_transfers_value(organization):
@staticmethod
def get_pending_deductions(
organization,
ignore_pending_supplemental=True
ignore_pending_supplemental=True,
compliance_period=None
):
deductions = 0
deductions += OrganizationService.get_pending_transfers_value(organization)
Expand Down Expand Up @@ -112,6 +113,36 @@ def get_pending_deductions(
# if report.summary.credits_offset:
# deductions -= report.summary.credits_offset


# Adjust deductions for reports in the current compliance period
# This addresses a specific scenario where credits from the most recent
# submitted but not accepted report in the current period should not be
# considered as unavailable
if compliance_period:
# Get all unique report chains for the current compliance period
report_chains = ComplianceReport.objects.filter(
organization_id=organization.id,
compliance_period__description=str(compliance_period)
).values('id').distinct()

for chain in report_chains:
# Get all reports in this chain, ordered from newest to oldest
reports_in_chain = ComplianceReport.objects.filter(
id=chain['id']
).order_by('-id')
# Traverse the chain backwards, looking for the first submitted
# but not accepted report
for report in reports_in_chain:
if report.status.fuel_supplier_status.status in ["Submitted"] and \
report.status.director_status.status not in ["Accepted", "Rejected"]:
# Subtract the credits_offset of this report from the total deductions
# This ensures that credits from the most recent relevant report
# are not incorrectly marked as unavailable
if report.summary and report.summary.credits_offset is not None:
deductions -= report.summary.credits_offset
# Break after processing the first relevant report in the chain
break

if deductions < 0:
deductions = 0

Expand Down Expand Up @@ -160,6 +191,8 @@ def get_max_credit_offset(organization, compliance_year, exclude_reserved=False)
Q(number_of_credits__gte=0) &
Q(trade_effective_date__lte=effective_date_deadline))
).aggregate(total=Sum('number_of_credits'))

# print("CREDITS -- ", credits_until_deadline)

# Query to sum up all approved, non-rescinded debits (outgoing credits) for the organization.
all_debits = CreditTrade.objects.filter(
Expand Down Expand Up @@ -192,6 +225,7 @@ def get_max_credit_offset(organization, compliance_year, exclude_reserved=False)
)
)
)
# print("DEBITS -- ", all_debits)

# Calculate the net available balance by subtracting debits from credits.
net_available_balance = 0
Expand All @@ -205,8 +239,9 @@ def get_max_credit_offset(organization, compliance_year, exclude_reserved=False)
if exclude_reserved:
pending_deductions = OrganizationService.get_pending_transfers_value(organization)
else:
pending_deductions = OrganizationService.get_pending_deductions(organization, ignore_pending_supplemental=False)
pending_deductions = OrganizationService.get_pending_deductions(organization, ignore_pending_supplemental=False, compliance_period=compliance_year)

# print("PENDING DEDUCTIONS -- ", pending_deductions)
# Deduct pending deductions from the available balance and ensure it does not drop below zero.
available_balance_now = net_available_balance - pending_deductions
if available_balance_now < 0:
Expand Down
Loading
Loading