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

Cleanup #479

Merged
merged 10 commits into from
Oct 30, 2024
5 changes: 0 additions & 5 deletions mooringlicensing/components/approvals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def update_approval_doc_filename(instance, filename):
def update_approval_comms_log_filename(instance, filename):
return '{}/proposals/{}/approvals/communications/{}'.format(settings.MEDIA_APP_DIR, instance.log_entry.approval.current_proposal.id,filename)

#TODO this is not used or accessed anywhere except when a mooring is offered (upload) - consider removing or using
class WaitingListOfferDocument(Document):
@staticmethod
def relative_path_to_file(approval_id, filename):
Expand Down Expand Up @@ -319,10 +318,6 @@ class Approval(RevisionedMixin):
renewal_count = models.PositiveSmallIntegerField('Number of times an Approval has been renewed', default=0)
migrated = models.BooleanField(default=False)

#TODO review this - look in to how exports are supposed to work, remove if not required
# for cron job
exported = models.BooleanField(default=False) # must be False after every add/edit

moorings = models.ManyToManyField(Mooring, through=MooringOnApproval)
vessel_ownerships = models.ManyToManyField(VesselOwnership, through=VesselOwnershipOnApproval)
wla_order = models.PositiveIntegerField(help_text='wla order per mooring bay', null=True)
Expand Down
7 changes: 1 addition & 6 deletions mooringlicensing/components/main/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib import admin

from mooringlicensing.components.main.models import VesselSizeCategory, VesselSizeCategoryGroup, ApplicationType, \
NumberOfDaysSetting, NumberOfDaysType, TemporaryDocument
NumberOfDaysSetting, NumberOfDaysType
from mooringlicensing.components.payments_ml.models import OracleCodeItem
from django.utils.html import mark_safe

Expand Down Expand Up @@ -111,11 +111,6 @@ def get_vessel_size_categories(self, obj):
get_vessel_size_categories.short_description = 'vessel size category'


@admin.register(TemporaryDocument)
class TemporaryDocumentAdmin(admin.ModelAdmin):
pass


class OracleCodeItemInline(admin.TabularInline):
model = OracleCodeItem
extra = 0
Expand Down
20 changes: 0 additions & 20 deletions mooringlicensing/components/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,6 @@ class Meta:
def __str__(self):
return 'System Maintenance: {} ({}) - starting {}, ending {}'.format(self.name, self.description, self.start_date, self.end_date)

#TODO appears to be unused - check if needed
class TemporaryDocumentCollection(models.Model):

class Meta:
app_label = 'mooringlicensing'

#TODO appears to be unused - check if needed
class TemporaryDocument(Document):
temp_document_collection = models.ForeignKey(
TemporaryDocumentCollection,
related_name='documents',
on_delete=models.CASCADE,
)
_file = models.FileField(storage=private_storage,max_length=255)

class Meta:
app_label = 'mooringlicensing'


def update_electoral_roll_doc_filename(instance, filename):
return '{}/emailusers/{}/documents/{}'.format(settings.MEDIA_APP_DIR, instance.emailuser.id,filename)
Expand Down Expand Up @@ -435,8 +417,6 @@ def get_setting_by_date(number_of_days_type, target_date=datetime.now(pytz.timez
reversion.register(ApplicationType, follow=['proposalstandardrequirement_set', 'feeseason_set', 'feeconstructor_set', 'oracle_code_items'])
reversion.register(GlobalSettings, follow=[])
reversion.register(SystemMaintenance, follow=[])
reversion.register(TemporaryDocumentCollection, follow=['documents'])
reversion.register(TemporaryDocument, follow=[])
reversion.register(VesselSizeCategoryGroup, follow=['vessel_size_categories', 'fee_constructors'])
reversion.register(VesselSizeCategory, follow=['feeitem_set'])
reversion.register(NumberOfDaysType, follow=['settings'])
Expand Down
5 changes: 1 addition & 4 deletions mooringlicensing/components/main/serializers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from rest_framework import serializers
from mooringlicensing import settings
from mooringlicensing.components.main.models import (
CommunicationsLogEntry,
TemporaryDocumentCollection,
)
from mooringlicensing.components.main.models import CommunicationsLogEntry
from ledger_api_client.ledger_models import EmailUserRO, Invoice
from mooringlicensing.ledger_api_utils import get_invoice_payment_status

Expand Down
158 changes: 2 additions & 156 deletions mooringlicensing/components/payments_ml/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
import pytz
from django.http import HttpResponse
from django.urls import reverse
from ledger_api_client.utils import create_basket_session, create_checkout_session, calculate_excl_gst, use_existing_basket_from_invoice
from ledger_api_client.utils import create_basket_session, create_checkout_session, calculate_excl_gst
from ledger_api_client.settings_base import *
from mooringlicensing import settings
from mooringlicensing.components.payments_ml.models import (
ApplicationFee, DcvPermitFee,
DcvAdmissionFee, StickerActionFee
)

logger = logging.getLogger(__name__)


def checkout(request, email_user, lines, return_url, return_preload_url, booking_reference, invoice_text=None, vouchers=[], proxy=False,):
basket_params = {
'products': make_serializable(lines),
Expand Down Expand Up @@ -106,159 +101,10 @@ def generate_line_item(application_type, fee_amount_adjusted, fee_constructor, i
}


NAME_SESSION_APPLICATION_INVOICE = 'mooringlicensing_app_invoice'
NAME_SESSION_DCV_PERMIT_INVOICE = 'mooringlicensing_dcv_permit_invoice'
NAME_SESSION_DCV_ADMISSION_INVOICE = 'mooringlicensing_dcv_admission_invoice'
NAME_SESSION_STICKER_ACTION_INVOICE = 'mooringlicensing_sticker_action_invoice'

#TODO review - does not appear to be required
def set_session_sticker_action_invoice(session, application_fee):
""" Application Fee session ID """
session[NAME_SESSION_STICKER_ACTION_INVOICE] = application_fee.id
session.modified = True

#TODO review - does not appear to be required
def get_session_sticker_action_invoice(session):
""" Application Fee session ID """
if NAME_SESSION_STICKER_ACTION_INVOICE in session:
application_fee_id = session[NAME_SESSION_STICKER_ACTION_INVOICE]
else:
raise Exception('Application not in Session')

try:
return StickerActionFee.objects.get(id=application_fee_id)
except StickerActionFee.DoesNotExist:
raise Exception('StickerActionFee not found for id: {}'.format(application_fee_id))

#TODO review - does not appear to be required
def delete_session_sticker_action_invoice(session):
""" Application Fee session ID """
if NAME_SESSION_STICKER_ACTION_INVOICE in session:
del session[NAME_SESSION_STICKER_ACTION_INVOICE]
session.modified = True


def set_session_application_invoice(session, application_fee):
print('in set_session_application_invoice')

""" Application Fee session ID """
session[NAME_SESSION_APPLICATION_INVOICE] = application_fee.id
session.modified = True

#TODO review - does not appear to be required
def get_session_application_invoice(session):
print('in get_session_application_invoice')

""" Application Fee session ID """
if NAME_SESSION_APPLICATION_INVOICE in session:
application_fee_id = session[NAME_SESSION_APPLICATION_INVOICE]
else:
# Reach here when the ApplicationFeeSuccessView is accessed 2nd time. Which is correct.
raise Exception('Application not in Session')

try:
return ApplicationFee.objects.get(id=application_fee_id)
except ApplicationFee.DoesNotExist:
raise


#TODO review - does not appear to be required
def delete_session_application_invoice(session):
print('in delete_session_application_invoice')

""" Application Fee session ID """
if NAME_SESSION_APPLICATION_INVOICE in session:
del session[NAME_SESSION_APPLICATION_INVOICE]
session.modified = True

#TODO review - does not appear to be required
def set_session_dcv_permit_invoice(session, dcv_permit_fee):
session[NAME_SESSION_DCV_PERMIT_INVOICE] = dcv_permit_fee.id
session.modified = True

#TODO review - does not appear to be required
def get_session_dcv_permit_invoice(session):
if NAME_SESSION_DCV_PERMIT_INVOICE in session:
dcv_permit_fee_id = session[NAME_SESSION_DCV_PERMIT_INVOICE]
else:
raise Exception('DcvPermit not in Session')

try:
return DcvPermitFee.objects.get(id=dcv_permit_fee_id)
except DcvPermitFee.DoesNotExist:
raise Exception('DcvPermit not found for application {}'.format(dcv_permit_fee_id))

#TODO review - does not appear to be required
def delete_session_dcv_permit_invoice(session):
if NAME_SESSION_DCV_PERMIT_INVOICE in session:
del session[NAME_SESSION_DCV_PERMIT_INVOICE]
session.modified = True


def set_session_dcv_admission_invoice(session, dcv_admission_fee):
session[NAME_SESSION_DCV_ADMISSION_INVOICE] = dcv_admission_fee.id
session.modified = True

#TODO review - does not appear to be required
def get_session_dcv_admission_invoice(session):
if NAME_SESSION_DCV_ADMISSION_INVOICE in session:
dcv_admission_fee_id = session[NAME_SESSION_DCV_ADMISSION_INVOICE]
else:
raise Exception('DcvAdmission not in Session')

try:
return DcvAdmissionFee.objects.get(id=dcv_admission_fee_id)
except DcvAdmissionFee.DoesNotExist:
raise Exception('DcvAdmission not found for application {}'.format(dcv_admission_fee_id))

#TODO review - does not appear to be required
def delete_session_dcv_admission_invoice(session):
if NAME_SESSION_DCV_ADMISSION_INVOICE in session:
del session[NAME_SESSION_DCV_ADMISSION_INVOICE]
session.modified = True


def make_serializable(line_items):
for line in line_items:
for key in line:
if isinstance(line[key], decimal.Decimal):
# Convert Decimal to str
line[key] = float(line[key])
return line_items

#TODO review - does not appear to be required
def checkout_existing_invoice(request, invoice, return_url_ns='public_booking_success'):

basket, basket_hash = use_existing_basket_from_invoice(invoice.reference)
return_preload_url = settings.MOORING_LICENSING_EXTERNAL_URL + reverse(return_url_ns)
checkout_params = {
'system': settings.PAYMENT_SYSTEM_ID,
'fallback_url': request.build_absolute_uri('/'),
'return_url': request.build_absolute_uri(reverse(return_url_ns)),
'return_preload_url': return_preload_url,
'force_redirect': True,
'invoice_text': invoice.text,
}

if request.user.is_anonymous():
# We need to determine the basket owner and set it to the checkout_params to proceed the payment
application_fee = ApplicationFee.objects.filter(invoice_reference=invoice.reference)
if application_fee:
application_fee = application_fee[0]
checkout_params['basket_owner'] = application_fee.proposal.applicant_id

create_checkout_session(request, checkout_params)

# use HttpResponse instead of HttpResponseRedirect - HttpResonseRedirect does not pass cookies which is important for ledger to get the correct basket
response = HttpResponse(
"<script> window.location='" + reverse('checkout:index') + "';</script> <a href='" + reverse(
'checkout:index') + "'> Redirecting please wait: " + reverse('checkout:index') + "</a>")

# inject the current basket into the redirect response cookies
# or else, anonymous users will be directionless
response.set_cookie(
settings.OSCAR_BASKET_COOKIE_OPEN, basket_hash,
max_age=settings.OSCAR_BASKET_COOKIE_LIFETIME,
secure=settings.OSCAR_BASKET_COOKIE_SECURE, httponly=True
)
return response
return line_items
7 changes: 1 addition & 6 deletions mooringlicensing/components/payments_ml/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
FeeItemStickerReplacement, FeeItemApplicationFee, FeeCalculation
)
from mooringlicensing.components.payments_ml.utils import (
checkout, set_session_application_invoice, set_session_dcv_admission_invoice,
checkout
)
from mooringlicensing.components.proposals.models import (
Proposal, ProposalUserAction,
Expand Down Expand Up @@ -68,8 +68,6 @@ def post(self, request, *args, **kwargs):

try:
with transaction.atomic():
#TODO what does this do?
set_session_dcv_admission_invoice(request.session, dcv_admission_fee)

lines, db_processes = dcv_admission.create_fee_lines()

Expand Down Expand Up @@ -393,9 +391,6 @@ def post(self, request, *args, **kwargs):

try:
with transaction.atomic():
#TODO what does this do?
set_session_application_invoice(request.session, application_fee)

try:
lines, db_processes_after_success = proposal.child_obj.create_fee_lines() # Accessed by WL and AA
except Exception as e:
Expand Down
47 changes: 0 additions & 47 deletions mooringlicensing/components/proposals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,13 @@ class Proposal(DirtyFieldsMixin, RevisionedMixin):
processing_status = models.CharField('Processing Status',
max_length=40, choices=PROCESSING_STATUS_CHOICES,
default=PROCESSING_STATUS_CHOICES[0][0])

#TODO used by on_hold - which is not implemented (remove if on_hold removed)
prev_processing_status = models.CharField(max_length=40, blank=True, null=True)

approval = models.ForeignKey('mooringlicensing.Approval',null=True,blank=True, on_delete=models.SET_NULL)
previous_application = models.ForeignKey('self', on_delete=models.SET_NULL, blank=True, null=True, related_name="succeeding_proposals")

proposed_decline_status = models.BooleanField(default=False)
title = models.CharField(max_length=255,null=True,blank=True)

#TODO currently not in use, but may be required (remove if not)
approval_comment = models.TextField(blank=True)

#If the proposal is created as part of migration of approvals
migrated = models.BooleanField(default=False)

Expand Down Expand Up @@ -1386,39 +1380,6 @@ def final_decline(self, request, details):
except:
raise

#TODO not in use and has outdated code - remove or check if required
def on_hold(self,request):
with transaction.atomic():
try:
if not self.can_assess(request.user):
raise exceptions.ProposalNotAuthorized()
if not (self.processing_status == 'with_assessor' or self.processing_status == 'with_referral'):
raise ValidationError('You cannot put on hold if it is not with assessor or with referral')

self.prev_processing_status = self.processing_status
self.processing_status = self.PROCESSING_STATUS_ONHOLD
self.save()
# Log proposal action
self.log_user_action(ProposalUserAction.ACTION_PUT_ONHOLD.format(self.id),request)
except:
raise

#TODO not in use and has outdated code - remove or check if required
def on_hold_remove(self,request):
with transaction.atomic():
try:
if not self.can_assess(request.user):
raise exceptions.ProposalNotAuthorized()
if self.processing_status != 'on_hold':
raise ValidationError('You cannot remove on hold if it is not currently on hold')

self.processing_status = self.prev_processing_status
self.prev_processing_status = self.PROCESSING_STATUS_ONHOLD
self.save()
# Log proposal action
self.log_user_action(ProposalUserAction.ACTION_REMOVE_ONHOLD.format(self.id),request)
except:
raise

def proposed_approval(self, request, details):
from mooringlicensing.components.approvals.models import MooringOnApproval
Expand Down Expand Up @@ -4458,10 +4419,6 @@ class VesselDetails(RevisionedMixin): # ManyToManyField link in Proposal
created = models.DateTimeField(default=timezone.now)
updated = models.DateTimeField(auto_now=True)

# TODO review how this works and determine if needed
# for cron job
exported = models.BooleanField(default=False) # must be False after every add/edit

objects = models.Manager()
filtered_objects = VesselDetailsManager()

Expand Down Expand Up @@ -4551,10 +4508,6 @@ class VesselOwnership(RevisionedMixin):
created = models.DateTimeField(default=timezone.now)
updated = models.DateTimeField(auto_now=True)

# TODO review how this works and determine if needed
# for cron job
exported = models.BooleanField(default=False) # must be False after every add/edit

objects = models.Manager()
filtered_objects = VesselOwnershipManager()
## Name as shown on DoT registration papers
Expand Down
1 change: 0 additions & 1 deletion mooringlicensing/components/proposals/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,6 @@ class Meta:
'berth_mooring',
'created',
'updated',
'exported',
'read_only',
'vessel_type_display',
)
Expand Down
Loading
Loading