Skip to content

Commit 2dbf20b

Browse files
committed
Implement invoice name override and invoice due date
1 parent c6b7fbb commit 2dbf20b

11 files changed

+163
-29
lines changed

ledger/checkout/serializers.py

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class CheckoutSerializer(serializers.Serializer):
7575
icrn_format = serializers.ChoiceField(choices=['ICRNAMT', 'ICRNDATE', 'ICRNAMTDATE'], default='ICRNAMT')
7676
icrn_date = serializers.DateField(required=False, default=None)
7777
invoice_text = serializers.CharField(required=False, default=None)
78+
invoice_name = serializers.CharField(required=False, default=None)
7879
check_url = serializers.URLField(required=False, default=None)
7980
amount_override=serializers.FloatField(required=False, default=None)
8081
session_type = serializers.ChoiceField(choices=['standard', 'ledger_api'], default='standard')

ledger/checkout/utils.py

+10
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def create_checkout_session(request, parameters):
216216
session_data.icrn_using(serializer.validated_data['icrn_format'])
217217
session_data.bpay_by(serializer.validated_data['icrn_date'])
218218
session_data.set_invoice_text(serializer.validated_data['invoice_text'])
219+
session_data.set_invoice_name(serializer.validated_data['invoice_name'])
219220

220221
session_data.set_last_check(serializer.validated_data['check_url'])
221222
session_data.set_amount_override(serializer.validated_data['amount_override'])
@@ -376,6 +377,15 @@ def set_invoice_text(self,text):
376377
def get_invoice_text(self):
377378
return self._get('ledger','invoice_text')
378379

380+
381+
# Invoice Name Override Account Name
382+
# ==========================
383+
def set_invoice_name(self,text):
384+
self._set('ledger','invoice_name',text)
385+
386+
def get_invoice_name(self):
387+
return self._get('ledger','invoice_name')
388+
379389
# Last check url per system
380390
# ==========================
381391
def set_last_check(self,text):

ledger/checkout/views.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ def doInvoice(self,order_number,total,**kwargs):
362362
crn_string,
363363
system,
364364
self.checkout_session.get_invoice_text() if self.checkout_session.get_invoice_text() else '',
365-
self.checkout_session.payment_method() if self.checkout_session.payment_method() else None
365+
self.checkout_session.payment_method() if self.checkout_session.payment_method() else None,
366+
self.checkout_session.get_invoice_name() if self.checkout_session.get_invoice_name() else ''
366367
)
367368
self.createInvoiceLinks(invoice)
368369
return invoice
@@ -375,7 +376,8 @@ def doInvoice(self,order_number,total,**kwargs):
375376
icrn_format,
376377
system,
377378
self.checkout_session.get_invoice_text() if self.checkout_session.get_invoice_text() else '',
378-
self.checkout_session.payment_method() if self.checkout_session.payment_method() else None
379+
self.checkout_session.payment_method() if self.checkout_session.payment_method() else None,
380+
self.checkout_session.get_invoice_name() if self.checkout_session.get_invoice_name() else ''
379381
)
380382
self.createInvoiceLinks(invoice)
381383
return invoice

ledger/payments/admin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CashAdmin(admin.ModelAdmin):
2626

2727
@admin.register(models.Invoice)
2828
class InvoiceAdmin(admin.ModelAdmin):
29-
list_display = ('reference','oracle_invoice_number','order','payment_status','settlement_date','amount', 'system','created' )
29+
list_display = ('reference','oracle_invoice_number','order','payment_status','invoice_name','settlement_date','due_date','amount', 'system','created' )
3030
search_fields = ('reference',)
3131
list_filter = ('system'),
3232
raw_id_fields = ('previous_invoice','oracle_invoice_file')

ledger/payments/invoice/facade.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ def _get_payment_choice(payment_method):
1313
return Invoice.PAYMENT_METHOD_OTHER
1414
return None
1515

16-
def create_invoice_crn(order_number, amount, crn_string, system, text, payment_method=None):
16+
def create_invoice_crn(order_number, amount, crn_string, system, text, payment_method=None, invoice_name='', due_date=None):
1717
'''Make a new Invoice object using crn
1818
'''
1919
inv,created = Invoice.objects.get_or_create(
2020
order_number=order_number,
2121
amount=amount,
22-
reference = getCRN(crn_string)
22+
reference = getCRN(crn_string),
23+
invoice_name=invoice_name,
24+
due_date=due_date
2325
)
2426

2527
print ("create_invoice_crn!!! <<- JASON")
@@ -38,7 +40,7 @@ def create_invoice_crn(order_number, amount, crn_string, system, text, payment_m
3840
inv.save()
3941
return inv
4042

41-
def create_invoice_icrn(order_number, amount, crn_string, _format, system, text, payment_method=None):
43+
def create_invoice_icrn(order_number, amount, crn_string, _format, system, text, payment_method=None, invoice_name='', due_date=None):
4244
'''Make a new Invoice object using icrn
4345
'''
4446
if _format in ['ICRNDATE','ICRNAMTDATE']:
@@ -48,7 +50,9 @@ def create_invoice_icrn(order_number, amount, crn_string, _format, system, text,
4850
inv, created = Invoice.objects.get_or_create(
4951
order_number=order_number,
5052
amount=amount,
51-
reference = icrn
53+
reference = icrn,
54+
invoice_name=invoice_name,
55+
due_date=due_date
5256
)
5357
if created:
5458
if payment_method:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.29 on 2024-11-07 06:51
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('invoice', '0011_auto_20240111_1612'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='invoice',
17+
name='due_date',
18+
field=models.DateField(blank=True, null=True),
19+
),
20+
migrations.AddField(
21+
model_name='invoice',
22+
name='invoice_name',
23+
field=models.CharField(default='', max_length=255),
24+
),
25+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.29 on 2024-11-07 06:51
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('invoice', '0012_auto_20241107_1451'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='invoice',
17+
name='invoice_name',
18+
field=models.CharField(blank=True, default='', max_length=255, null=True),
19+
),
20+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.29 on 2024-11-07 06:56
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('invoice', '0013_auto_20241107_1451'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='invoice',
17+
name='invoice_name',
18+
field=models.CharField(blank=True, default='', help_text='Is used to override the customer account name.', max_length=255, null=True),
19+
),
20+
]

ledger/payments/invoice/models.py

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Invoice(models.Model):
5656
(PAYMENT_METHOD_OTHER, 'Other'),
5757
)
5858

59+
invoice_name = models.CharField(max_length=255, blank=True,null=True, default='', help_text="Is used to override the customer account name.")
5960
created = models.DateTimeField(auto_now_add=True)
6061
text = models.TextField(null=True,blank=True)
6162
amount = models.DecimalField(decimal_places=2,max_digits=12)
@@ -66,6 +67,7 @@ class Invoice(models.Model):
6667
voided = models.BooleanField(default=False)
6768
previous_invoice = models.ForeignKey('self',null=True,blank=True)
6869
settlement_date = models.DateField(blank=True, null=True)
70+
due_date = models.DateField(blank=True, null=True)
6971
payment_method = models.SmallIntegerField(choices=PAYMENT_METHOD_CHOICES, default=0)
7072
oracle_invoice_number = models.CharField(max_length=255, default='', null=True, blank=True)
7173
oracle_invoice_file = models.ForeignKey(OracleInvoiceDocument, null=True, blank=True, on_delete=models.SET_NULL, related_name='oracle_invoice_file')

ledger/payments/pdf.py

+56-20
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,43 @@ def __payment_line(self):
162162
self.current_y = current_y
163163

164164
def __footer_line(self):
165+
total_cols = 4
166+
try:
167+
print (self.invoice.due_date.strftime(DATE_FORMAT))
168+
total_cols = 5
169+
170+
except Exception as e:
171+
# if not valid date we keep totals cols at 4
172+
pass
173+
165174
canvas = self.canv
166175
current_y, current_x = self.current_y, self.current_x
167176
current_y -= 2 * inch
168177
total_gst_tax = self.invoice.order.total_incl_tax - self.invoice.order.total_excl_tax
169178
canvas.setFont(DEFAULT_FONTNAME, LARGE_FONTSIZE)
170179
canvas.setFillColor(colors.black)
171180
canvas.drawString(current_x, current_y, 'Invoice Number')
172-
canvas.drawString(PAGE_WIDTH/4, current_y, 'Invoice Date')
173-
canvas.drawString((PAGE_WIDTH/4) * 2, current_y, 'GST included')
174-
canvas.drawString((PAGE_WIDTH/4) * 3, current_y, 'Invoice Total')
181+
canvas.drawString(PAGE_WIDTH/total_cols, current_y, 'Invoice Date')
182+
nextrow = 2
183+
if self.invoice.due_date:
184+
canvas.drawString((PAGE_WIDTH/total_cols) * nextrow, current_y, 'Due Date')
185+
nextrow = nextrow + 1
186+
canvas.drawString((PAGE_WIDTH/total_cols) * nextrow, current_y, 'GST included')
187+
nextrow = nextrow + 1
188+
canvas.drawString((PAGE_WIDTH/total_cols) * nextrow, current_y, 'Invoice Total')
175189
current_y -= 20
176190
canvas.setFont(DEFAULT_FONTNAME, MEDIUM_FONTSIZE)
177191
canvas.drawString(current_x, current_y, self.invoice.reference)
178-
canvas.drawString(PAGE_WIDTH/4, current_y, self.invoice.created.strftime(DATE_FORMAT))
192+
canvas.drawString(PAGE_WIDTH/total_cols, current_y, self.invoice.created.strftime(DATE_FORMAT))
193+
nextrow = 2
194+
if self.invoice.due_date:
195+
canvas.drawString((PAGE_WIDTH/total_cols) * nextrow, current_y, self.invoice.due_date.strftime(DATE_FORMAT))
196+
nextrow = nextrow + 1
179197
#canvas.drawString((PAGE_WIDTH/4) * 2, current_y, currency(self.invoice.amount - calculate_excl_gst(self.invoice.amount)))
180-
canvas.drawString((PAGE_WIDTH/4) * 2, current_y, currency(total_gst_tax))
181-
canvas.drawString((PAGE_WIDTH/4) * 3, current_y, currency(self.invoice.amount))
198+
199+
canvas.drawString((PAGE_WIDTH/total_cols) * nextrow, current_y, currency(total_gst_tax))
200+
nextrow = nextrow + 1
201+
canvas.drawString((PAGE_WIDTH/total_cols) * nextrow, current_y, currency(self.invoice.amount))
182202

183203
def draw(self):
184204
if settings.BPAY_ALLOWED:
@@ -219,26 +239,42 @@ def _create_header(canvas, doc, draw_page_number=True):
219239
canvas.drawString(current_x, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER), invoice.order.organisation.name)
220240
canvas.drawString(current_x, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) *2, invoice.order.organisation.abn)
221241

222-
canvas.drawString(current_x, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 3,invoice.owner.get_full_name())
242+
invoice_name = invoice.owner.get_full_name()
243+
if invoice.invoice_name:
244+
if len(invoice.invoice_name) > 0:
245+
invoice_name = invoice.invoice_name
246+
247+
canvas.drawString(current_x, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 3,invoice_name)
223248
canvas.drawString(current_x, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 4,invoice.owner.username)
224249

225250
current_x += 452
226251
#write Invoice details
252+
nextrowcount = 2
227253
canvas.drawString(current_x, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER),'Date')
228-
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER),invoice.created.strftime(DATE_FORMAT))
229-
canvas.drawString(current_x, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 2, 'Page')
230-
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 2, str(canvas.getPageNumber()))
231-
canvas.drawRightString(current_x + 20, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 3, 'Invoice Number')
232-
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 3, invoice.reference)
233-
canvas.drawRightString(current_x + 20, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 4, 'Total (AUD)')
234-
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 4, currency(invoice.amount))
235-
canvas.drawRightString(current_x + 20, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 5, 'GST included (AUD)')
254+
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER),invoice.created.strftime(DATE_FORMAT))
255+
canvas.drawString(current_x, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, 'Page')
256+
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, str(canvas.getPageNumber()))
257+
nextrowcount = nextrowcount + 1
258+
canvas.drawRightString(current_x + 20, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, 'Invoice Number')
259+
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, invoice.reference)
260+
261+
if invoice.due_date:
262+
nextrowcount = nextrowcount + 1
263+
canvas.drawRightString(current_x + 20, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, 'Due Date')
264+
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, invoice.due_date.strftime(DATE_FORMAT))
265+
nextrowcount = nextrowcount + 1
266+
canvas.drawRightString(current_x + 20, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, 'Total (AUD)')
267+
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, currency(invoice.amount))
268+
nextrowcount = nextrowcount + 1
269+
canvas.drawRightString(current_x + 20, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, 'GST included (AUD)')
236270
#canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 5, currency(invoice.amount - calculate_excl_gst(invoice.amount)))
237-
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 5, currency(total_gst_tax))
238-
canvas.drawRightString(current_x + 20, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 6, 'Paid (AUD)')
239-
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 6, currency(invoice.payment_amount))
240-
canvas.drawRightString(current_x + 20, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 7, 'Outstanding (AUD)')
241-
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * 7, currency(invoice.balance))
271+
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, currency(total_gst_tax))
272+
nextrowcount = nextrowcount + 1
273+
canvas.drawRightString(current_x + 20, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, 'Paid (AUD)')
274+
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, currency(invoice.payment_amount))
275+
nextrowcount = nextrowcount + 1
276+
canvas.drawRightString(current_x + 20, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, 'Outstanding (AUD)')
277+
canvas.drawString(current_x + invoice_details_offset, current_y - (SMALL_FONTSIZE + HEADER_SMALL_BUFFER) * nextrowcount, currency(invoice.balance))
242278
canvas.restoreState()
243279

244280
def _create_invoice(invoice_buffer, invoice):

ledgergw/api.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,19 @@ def process_create_future_invoice(request,apikey):
13061306
basket_id = request.POST.get('basket_id','')
13071307
invoice_text = request.POST.get('invoice_text', '')
13081308
return_preload_url = request.POST.get('return_preload_url', '')
1309+
invoice_name = request.POST.get('invoice_name', '')
1310+
due_date_string = request.POST.get('due_date', None)
1311+
print ("DUE DATE")
1312+
print (due_date_string)
13091313

1314+
due_date = None
1315+
if due_date_string:
1316+
try:
1317+
due_date = datetime.strptime(due_date_string, "%d/%m/%Y")
1318+
print (due_date)
1319+
except Exception as e:
1320+
print (e)
1321+
13101322
basket_obj = basket_models.Basket.objects.filter(id=basket_id)
13111323
if basket_obj.count() > 0:
13121324
get_basket = basket_models.Basket.objects.get(id=basket_id)
@@ -1323,16 +1335,18 @@ def process_create_future_invoice(request,apikey):
13231335
get_basket.notification_url = return_preload_url
13241336
get_basket.save()
13251337

1326-
13271338
crn_string = '{0}{1}'.format(systemid_check(get_basket.system),order_number)
13281339
invoice = invoice_facade.create_invoice_crn(
13291340
order_number,
13301341
order_total.incl_tax,
13311342
crn_string,
13321343
get_basket.system,
13331344
invoice_text,
1334-
None
1345+
None,
1346+
invoice_name,
1347+
due_date
13351348
)
1349+
13361350
LinkedInvoiceCreate(invoice, get_basket.id)
13371351
jsondata['status'] = 200
13381352
jsondata['message'] = 'success'

0 commit comments

Comments
 (0)