Skip to content

Commit

Permalink
added invoice reference, fixed tests
Browse files Browse the repository at this point in the history
Signed-off-by: Trey <[email protected]>
  • Loading branch information
TreyWW committed Nov 17, 2024
1 parent 849ed79 commit 278770e
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 38 deletions.
1 change: 0 additions & 1 deletion backend/core/api/public/endpoints/Invoices/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def edit_invoice_endpoint(request: APIRequest):
"self_county": request.POST.get("from_county"),
"self_country": request.POST.get("from_country"),
"notes": request.POST.get("notes"),
"invoice_number": request.POST.get("invoice_number"),
"vat_number": request.POST.get("vat_number"),
"reference": request.POST.get("reference"),
"sort_code": request.POST.get("sort_code"),
Expand Down
3 changes: 0 additions & 3 deletions backend/core/service/invoices/common/create/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def create_invoice_items(request: WebRequest):


def save_invoice_common(request: WebRequest, invoice_items, invoice: Invoice | InvoiceRecurringProfile):

if request.user.logged_in_as_team:
invoice.organization = request.user.logged_in_as_team
else:
Expand Down Expand Up @@ -49,7 +48,6 @@ def save_invoice_common(request: WebRequest, invoice_items, invoice: Invoice | I
invoice.self_county = request.POST.get("from_county")
invoice.self_country = request.POST.get("from_country")
invoice.notes = request.POST.get("notes")
invoice.invoice_number = request.POST.get("invoice_number")
invoice.vat_number = request.POST.get("vat_number")
if request.FILES.get("logo") is not None:
invoice.logo = request.FILES.get("logo")
Expand All @@ -60,7 +58,6 @@ def save_invoice_common(request: WebRequest, invoice_items, invoice: Invoice | I
defaults: DefaultValues = get_account_defaults(request.actor)
if defaults:
invoice.logo = defaults.default_invoice_logo
invoice.reference = request.POST.get("reference")
invoice.sort_code = request.POST.get("sort_code")
invoice.account_number = request.POST.get("account_number")
invoice.account_holder_name = request.POST.get("account_holder_name")
Expand Down
2 changes: 1 addition & 1 deletion backend/core/service/invoices/common/emails/on_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def on_create_invoice_email_service(users_email: str, invoice: Invoice) -> OnCre
user_data = {
"first_name": invoice.client_to.name.split(" ")[0] if invoice.client_to else invoice.client_name,
"invoice_id": invoice.id,
"invoice_ref": invoice.reference or invoice.invoice_number or invoice.id,
"invoice_ref": invoice.reference or invoice.id,
"due_date": invoice.date_due.strftime("%A, %B %d, %Y"),
"amount_due": invoice.get_total_price(),
"currency": invoice.currency,
Expand Down
1 change: 1 addition & 0 deletions backend/core/service/invoices/single/create/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def save_invoice(request: WebRequest, invoice_items):
date_due=datetime.strptime(date_due, "%Y-%m-%d").date(),
date_issued=request.POST.get("date_issued"),
currency=currency,
reference=request.POST.get("reference"),
)

save_invoice_common(request, invoice_items, invoice)
Expand Down
2 changes: 1 addition & 1 deletion backend/core/service/reports/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def generate_report(
for invoice in all_invoices:
row = MonthlyReportRow(
date=invoice.date_issued or invoice.date_created,
reference_number=invoice.invoice_number or invoice.id,
reference_number=invoice.reference or invoice.id,
item_type="invoice",
paid_in=invoice.get_total_price(),
)
Expand Down
1 change: 0 additions & 1 deletion backend/finance/api/invoices/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def edit_invoice(request: HtmxHttpRequest):
"self_county": request.POST.get("from_county"),
"self_country": request.POST.get("from_country"),
"notes": request.POST.get("notes"),
"invoice_number": request.POST.get("invoice_number"),
"vat_number": request.POST.get("vat_number"),
"reference": request.POST.get("reference"),
"sort_code": request.POST.get("sort_code"),
Expand Down
1 change: 0 additions & 1 deletion backend/finance/api/invoices/recurring/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def edit_invoice_recurring_profile_endpoint(request: WebRequest, invoice_profile
"self_county": request.POST.get("from_county"),
"self_country": request.POST.get("from_country"),
"notes": request.POST.get("notes"),
"invoice_number": request.POST.get("invoice_number"),
"vat_number": request.POST.get("vat_number"),
"reference": request.POST.get("reference"),
"sort_code": request.POST.get("sort_code"),
Expand Down
7 changes: 2 additions & 5 deletions backend/finance/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ class InvoiceBase(OwnerBase):
sort_code = models.CharField(max_length=8, blank=True, null=True) # 12-34-56
account_holder_name = models.CharField(max_length=100, blank=True, null=True)
account_number = models.CharField(max_length=100, blank=True, null=True)
reference = models.CharField(max_length=100, blank=True, null=True)
invoice_number = models.CharField(max_length=100, blank=True, null=True)
vat_number = models.CharField(max_length=100, blank=True, null=True)
logo = models.ImageField(
upload_to="invoice_logos",
Expand Down Expand Up @@ -150,7 +148,7 @@ class Invoice(InvoiceBase):
("paid", "Paid"),
)

invoice_id = models.IntegerField(unique=True, blank=True, null=True) # todo: add
reference = models.CharField(max_length=16, blank=True, null=True)
date_due = models.DateField()
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default="draft")
status_updated_at = models.DateTimeField(auto_now_add=True)
Expand All @@ -159,15 +157,14 @@ class Invoice(InvoiceBase):
)

def __str__(self):
invoice_id = self.invoice_id or self.id
if self.client_name:
client = self.client_name
elif self.client_to:
client = self.client_to.name
else:
client = "Unknown Client"

return f"Invoice #{invoice_id} for {client}"
return f"Invoice #{self.id} for {client}"

def set_status(self, status: str, save=True):
if status not in ["draft", "pending", "paid"]:
Expand Down
2 changes: 1 addition & 1 deletion backend/finance/views/invoices/single/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def invoice_get_existing_data(invoice_obj):
"account_holder_name": invoice_obj.account_holder_name,
"sort_code": invoice_obj.sort_code,
"account_number": invoice_obj.account_number,
"reference": invoice_obj.reference,
"logo": invoice_obj.logo,
}
if invoice_obj.client_to:
Expand Down Expand Up @@ -101,7 +102,6 @@ def edit_invoice(request: WebRequest, invoice_id):
"self_county": request.POST.get("from_county"),
"self_country": request.POST.get("from_country"),
"notes": request.POST.get("notes"),
"invoice_number": request.POST.get("invoice_number"),
"vat_number": request.POST.get("vat_number"),
"reference": request.POST.get("reference"),
"sort_code": request.POST.get("sort_code"),
Expand Down
34 changes: 34 additions & 0 deletions backend/migrations/0070_remove_invoice_invoice_id_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 5.1.1 on 2024-11-17 15:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("backend", "0069_alter_auditlog_action"),
]

operations = [
migrations.RemoveField(
model_name="invoice",
name="invoice_id",
),
migrations.RemoveField(
model_name="invoice",
name="invoice_number",
),
migrations.RemoveField(
model_name="invoicerecurringprofile",
name="invoice_number",
),
migrations.RemoveField(
model_name="invoicerecurringprofile",
name="reference",
),
migrations.AlterField(
model_name="invoice",
name="reference",
field=models.CharField(blank=True, max_length=16, null=True),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h3 class="text-sm text-natural font-semibold hidden lg:block text-end me-6">To<
STEP 5 - CUSTOM DESIGNS
<i class="text-neutral-content">[OPTIONAL]</i>
</div>
{% include "pages/invoices/create/custom_designs/logo.html" %}
<div class="my-4 flex w-full flex-row">{% include "pages/invoices/create/custom_designs/logo.html" %}</div>
{# <div class="divider my-4">STEP 5 - NOTES [OPTIONAL]</div>#}
{# {% include "pages/invoices/create/notes/notes.html" %}#}
<div class="group-invalid:tooltip"
Expand Down
5 changes: 4 additions & 1 deletion frontend/templates/pages/invoices/create/create_single.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ <h3 class="text-sm text-natural font-semibold hidden lg:block text-end me-6">To<
STEP 5 - CUSTOM DESIGNS
<i class="text-neutral-content">[OPTIONAL]</i>
</div>
{% include "pages/invoices/create/custom_designs/logo.html" %}
<div class="my-4 flex w-full flex-row">
{% include "pages/invoices/create/custom_designs/logo.html" %}
{% include "pages/invoices/create/custom_designs/reference.html" %}
</div>
{# <div class="divider my-4">STEP 5 - NOTES [OPTIONAL]</div>#}
{# {% include "pages/invoices/create/notes/notes.html" %}#}
<div class="group-invalid:tooltip"
Expand Down
22 changes: 9 additions & 13 deletions frontend/templates/pages/invoices/create/custom_designs/logo.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
{# TODO: show the logo preview on the left #}
<div class="my-4 flex w-full flex-col">
<div class="w-full gap-4 grid grid-cols-1 lg:grid-cols-2">
<div class="input_card">
<div class="card-body">
<div class="form-control w-full">
<label class="label justify-start">Use custom logo</label>
<input type="file"
name="logo"
value="{% if logo %}{{ logo.url }}{% endif %}" {# doesn't auto-fill #}
class="file-input file-input-bordered max-w-full"
accept="image/jpeg,image/png,image/jpg">
</div>
</div>
<div class="input_card">
<div class="card-body">
<div class="form-control w-full">
<label class="label justify-start">Use custom logo</label>
<input type="file"
name="logo"
value="{% if logo %}{{ logo.url }}{% endif %}" {# doesn't auto-fill #}
class="file-input file-input-bordered max-w-full"
accept="image/jpeg,image/png,image/jpg">
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="input_card">
<div class="card-body">
<div class="form-control w-full">
<label class="label justify-start">
Invoice Reference
<span class="tooltip tooltip-secondary"
data-tip="This is a custom reference to use instead of our auto-generated invoice ID. This will be shown on the invoice too.">
<i class="fa fa-info-circle ms-2"></i>
</span>
</label>
<input type="text"
name="reference"
value="{{ reference }}"
placeholder="INV0012"
class="input input-bordered max-w-full">
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ <h3 class="text-sm text-natural font-semibold block lg:hidden ms-3">To</h3>
<input type="hidden" name="selected_client" value="{{ existing_client.id }}">
<input type="hidden"
name="is_representative"
value="{{ is_representative | default:to_is_representative }}">
value="{% if to_is_representative %}{{ is_representative | default:to_is_representative }}{% else %}{{ is_representative }}{% endif %}">
{% if not swapping %}</button>{% endif %}
11 changes: 10 additions & 1 deletion frontend/templates/pages/invoices/dashboard/_fetch_body.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@
hx-push-url="{% url "finance:invoices:single:overview" invoice_id=invoice.id %}"
hx-get="{% url "finance:invoices:single:overview" invoice_id=invoice.id %}">
<td class="link link-primary no-underline" td-value="{{ invoice.id }}">
<a href="{% url "finance:invoices:single:overview" invoice_id=invoice.id %}">{{ invoice.id }}</a>
<a href="{% url "finance:invoices:single:overview" invoice_id=invoice.id %}">
{% if invoice.reference %}
{{ invoice.reference }}
<span class="tooltip text-neutral-content"
data-tip="This is the actual invoice ID">({{ invoice.id }})</span>
{% else %}
{{ invoice.id }}
{% endif %}
</a>
</td>
<td></td>
<td>{{ invoice.date_due | date:"d/m/Y" }}</td>
{% with cli_name=invoice.client_to.name|default:invoice.client_name %}
<td td-value="{{ cli_name|default_if_none:"No Client" }}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h3 class="text-sm text-natural font-semibold hidden lg:block text-end me-6">To<
STEP 5 - CUSTOM DESIGNS
<i class="text-neutral-content">[OPTIONAL]</i>
</div>
{% include "pages/invoices/create/custom_designs/logo.html" %}
<div class="my-4 flex w-full flex-row">{% include "pages/invoices/create/custom_designs/logo.html" %}</div>
{# <div class="divider my-4">STEP 5 - NOTES [OPTIONAL]</div>#}
{# {% include "pages/invoices/create/notes/notes.html" %}#}
<div class="group-invalid:tooltip"
Expand Down
5 changes: 4 additions & 1 deletion frontend/templates/pages/invoices/single/edit/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ <h3 class="text-sm text-natural font-semibold hidden lg:block text-end me-6">To<
STEP 5 - CUSTOM DESIGNS
<i class="text-neutral-content">[OPTIONAL]</i>
</div>
{% include "pages/invoices/create/custom_designs/logo.html" %}
<div class="my-4 flex w-full flex-row">
{% include "pages/invoices/create/custom_designs/logo.html" %}
{% include "pages/invoices/create/custom_designs/reference.html" %}
</div>
<div class="group-invalid:tooltip mt-4"
data-tip="Fill out all required details to save the invoice.">
<button class="btn btn-primary group-invalid:btn-disabled btn-block">Save Invoice</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h1 class="text-2xl font-semibold">{{ invoice.self_company|default_if_none:invoi
<section class="text-right space-y-4 invoice-details">
<div>
<p class="text-sm text-gray-500 uppercase tracking-wide">Invoice Ref</p>
<p>{{ invoice.invoice_id|default:invoice.id }}</p>
<p>{{ invoice.reference|default:invoice.id }}</p>
</div>
<div>
<p class="text-sm text-gray-500 uppercase tracking-wide">Date Sent</p>
Expand Down
6 changes: 2 additions & 4 deletions tests/views/test_invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def setUp(self):
"from_county": "Self County",
"from_country": "Self Country",
"notes": "Invoice Notes",
"invoice_number": "INV-001",
"vat_number": "VAT-001",
"reference": "Reference",
"reference": "INV-001",
"sort_code": "123456",
"account_number": "12345678",
"account_holder_name": "Account Holder Name",
Expand Down Expand Up @@ -117,9 +116,8 @@ def test_invoices_create_invoice_from_post_data(self):
self.assertEqual(invoice.self_county, "Self County")
self.assertEqual(invoice.self_country, "Self Country")
self.assertEqual(invoice.notes, "Invoice Notes")
self.assertEqual(invoice.invoice_number, "INV-001")
self.assertEqual(invoice.vat_number, "VAT-001")
self.assertEqual(invoice.reference, "Reference")
self.assertEqual(invoice.reference, "INV-001")
self.assertEqual(invoice.sort_code, "123456")
self.assertEqual(invoice.account_number, "12345678")
self.assertEqual(invoice.account_holder_name, "Account Holder Name")
Expand Down

0 comments on commit 278770e

Please sign in to comment.