Skip to content

Commit

Permalink
Merge branch 'main' into issue-304
Browse files Browse the repository at this point in the history
  • Loading branch information
pvvramakrishnarao234 authored Sep 17, 2024
2 parents 79a19dc + 1086e05 commit e3063a4
Show file tree
Hide file tree
Showing 18 changed files with 441 additions and 136 deletions.
31 changes: 31 additions & 0 deletions assets/scripts/validate_payment_details.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
window.validate_sort_code = function validate_sort_code(value) {
// Remove any non-numeric characters
value = value.replace(/\D/g, '');

// Ensure the value is no longer than 9 characters (123-123-123)
if (value.length > 6) {
value = value.slice(0, 6);
}

// Format the value as "12-34-56"
if (value.length >= 2) {
value = value.slice(0, 2) + "-" + value.slice(2);
}
if (value.length >= 5) {
value = value.slice(0, 5) + "-" + value.slice(5);
}

return value;
}

window.validate_account_number = function validate_account_number(value) {
// Remove any non-numeric characters
value = value.replace(/\D/g, '');

// Ensure the value is no longer than 16 characters (1234-1234-1234-1234)
if (value.length > 8) {
value = value.slice(0, 8);
}

return value;
}
12 changes: 11 additions & 1 deletion backend/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,17 @@ class InvoiceURLAdmin(admin.ModelAdmin):
fields = list(UserAdmin.fieldsets) # type: ignore[arg-type]
fields[0] = (
None,
{"fields": ("username", "password", "logged_in_as_team", "awaiting_email_verification", "stripe_customer_id", "entitlements")},
{
"fields": (
"username",
"password",
"logged_in_as_team",
"awaiting_email_verification",
"stripe_customer_id",
"entitlements",
"require_change_password",
)
},
)
UserAdmin.fieldsets = tuple(fields)
admin.site.register(User, UserAdmin)
Expand Down
10 changes: 10 additions & 0 deletions backend/api/base/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from backend.types.htmx import HtmxHttpRequest
from backend.types.requests import WebRequest
from backend.utils.feature_flags import get_feature_status
from backend.service.defaults.get import get_account_defaults


# from backend.utils.quota_limit_ops import quota_usage_check_under
Expand Down Expand Up @@ -91,6 +92,15 @@ def open_modal(request: WebRequest, modal_name, context_type=None, context_value
context["from_city"] = invoice.self_city
context["from_county"] = invoice.self_county
context["from_country"] = invoice.self_country
elif context_type == "create_invoice_from":
defaults = get_account_defaults(request.actor)

context["from_name"] = getattr(defaults, f"invoice_from_name")
context["from_company"] = getattr(defaults, f"invoice_from_company")
context["from_address"] = getattr(defaults, f"invoice_from_address")
context["from_city"] = getattr(defaults, f"invoice_from_city")
context["from_county"] = getattr(defaults, f"invoice_from_county")
context["from_country"] = getattr(defaults, f"invoice_from_country")
elif context_type == "invoice":
try:
invoice = Invoice.objects.get(id=context_value)
Expand Down
4 changes: 2 additions & 2 deletions backend/api/invoices/create/set_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def set_destination_to(request: HtmxHttpRequest):
context: dict = {"swapping": True}

context.update({key: request.POST.get(key, "") for key in to_get})
context.update({f"to_{key}": request.POST.get(key, "") for key in to_get})

use_existing = True if request.POST.get("use_existing") == "true" else False
selected_client = request.POST.get("selected_client") if use_existing else None
Expand All @@ -31,6 +31,6 @@ def set_destination_to(request: HtmxHttpRequest):
def set_destination_from(request: HtmxHttpRequest):
context: dict = {"swapping": True}

context.update({key: request.POST.get(key, "") for key in to_get})
context.update({f"from_{key}": request.POST.get(key, "") for key in to_get})

return render(request, "pages/invoices/create/destinations/_from_destination.html", context)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 5.1 on 2024-09-16 19:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("backend", "0060_user_require_change_password"),
]

operations = [
migrations.AddField(
model_name="defaultvalues",
name="invoice_from_address",
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name="defaultvalues",
name="invoice_from_city",
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name="defaultvalues",
name="invoice_from_company",
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name="defaultvalues",
name="invoice_from_country",
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name="defaultvalues",
name="invoice_from_county",
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name="defaultvalues",
name="invoice_from_name",
field=models.CharField(blank=True, max_length=100, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.1 on 2024-09-16 20:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("backend", "0061_defaultvalues_invoice_from_address_and_more"),
]

operations = [
migrations.AddField(
model_name="defaultvalues",
name="invoice_account_holder_name",
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name="defaultvalues",
name="invoice_account_number",
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name="defaultvalues",
name="invoice_sort_code",
field=models.CharField(blank=True, max_length=100, null=True),
),
]
11 changes: 11 additions & 0 deletions backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,17 @@ class InvoiceDateType(models.TextChoices):
invoice_date_value = models.PositiveSmallIntegerField(default=15, null=False, blank=False)
invoice_date_type = models.CharField(max_length=20, choices=InvoiceDateType.choices, default=InvoiceDateType.day_of_month)

invoice_from_name = models.CharField(max_length=100, null=True, blank=True)
invoice_from_company = models.CharField(max_length=100, null=True, blank=True)
invoice_from_address = models.CharField(max_length=100, null=True, blank=True)
invoice_from_city = models.CharField(max_length=100, null=True, blank=True)
invoice_from_county = models.CharField(max_length=100, null=True, blank=True)
invoice_from_country = models.CharField(max_length=100, null=True, blank=True)

invoice_account_number = models.CharField(max_length=100, null=True, blank=True)
invoice_sort_code = models.CharField(max_length=100, null=True, blank=True)
invoice_account_holder_name = models.CharField(max_length=100, null=True, blank=True)

def get_issue_and_due_dates(self, issue_date: date | str | None = None) -> tuple[str, str]:
due: date
issue: date
Expand Down
6 changes: 5 additions & 1 deletion backend/service/boto3/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ def _initiate_session(self):
boto3.set_stream_logger("", level=logging.INFO)

def _initiate_clients(self):
if get_var("AWS_DISABLED"):
if get_var("AWS_DISABLED", "").lower() == "true":
logger.info("The variable AWS_DISABLED is present, not initiating boto3")
return

if not get_var("AWS_ENABLED"):
logger.error("The variable AWS_ENABLED is not present, not initiating boto3")
return

self._initiate_session()

try:
Expand Down
33 changes: 33 additions & 0 deletions backend/service/defaults/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,39 @@ def change_client_defaults(request: WebRequest, defaults: DefaultValues) -> Clie
else:
return ClientDefaultsServiceResponse(error_message=logo_ok)

DETAIL_INPUTS = {
"name": {"max_len": 100},
"company": {"max_len": 100},
"address": {"max_len": 100},
"city": {"max_len": 100},
"county": {"max_len": 100},
"country": {"max_len": 100},
}

for detail, value_dict in DETAIL_INPUTS.items():
input_post = request.POST.get(f"invoice_from_{detail}", "")

if len(input_post) > value_dict["max_len"]:
return ClientDefaultsServiceResponse(
error_message=f"Details - From {detail} is too long, max length is {value_dict['max_len']}"
)

setattr(defaults, f"invoice_from_{detail}", input_post)

PAYMENT_INPUTS = {
"account_number": {"max_len": 100},
"sort_code": {"max_len": 100},
"account_holder_name": {"max_len": 100},
}

for detail, value_dict in PAYMENT_INPUTS.items():
input_post = request.POST.get(f"invoice_{detail}", "")

if len(input_post) > value_dict["max_len"]:
return ClientDefaultsServiceResponse(error_message=f"Payment - {detail} is too long, max length is {value_dict['max_len']}")

setattr(defaults, f"invoice_{detail}", input_post)

defaults.save()
return ClientDefaultsServiceResponse(True)

Expand Down
22 changes: 21 additions & 1 deletion backend/service/invoices/common/create/get_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def global_get_invoice_context(request: WebRequest) -> CreateInvoiceContextServi
defaults = get_account_defaults(request.actor, client=None)

for item in ["name", "company", "address", "city", "county", "country"]:
context[f"{item}"] = request.GET.get(f"from_{item}", "")
context[f"from_{item}"] = request.GET.get(f"from_{item}", "")

if issue_date := request.GET.get("issue_date"):
try:
Expand Down Expand Up @@ -72,4 +72,24 @@ def global_get_invoice_context(request: WebRequest) -> CreateInvoiceContextServi
if account_number := request.GET.get("account_number"):
context["account_number"] = account_number

details_from = ["name", "company", "address", "city", "county", "country"]

for detail in details_from:
detail_value = request.GET.get(f"from_{detail}", "")

if not detail_value:
detail_value = getattr(defaults, f"invoice_from_{detail}")

context[f"from_{detail}"] = detail_value

payment_details = ["sort_code", "account_holder_name", "account_number"]

for detail in payment_details:
detail_value = request.GET.get(detail, "")

if not detail_value:
detail_value = getattr(defaults, f"invoice_{detail}")

context[detail] = detail_value

return CreateInvoiceContextServiceResponse(True, CreateInvoiceContextTuple(defaults, context))
Loading

0 comments on commit e3063a4

Please sign in to comment.