Skip to content

Commit e0bfa2e

Browse files
committed
Allows linking of cash adjustment transactions when adding (Issue 131)
1 parent f2a8f59 commit e0bfa2e

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

frano/static/js/transactions.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ $(function() {
1212
var val = $(this).val();
1313
var isCash = (val == 'DEPOSIT' || val == 'WITHDRAW' || val == 'ADJUST');
1414
var wasCash = (lastTransactionType == 'DEPOSIT' || lastTransactionType == 'WITHDRAW' || lastTransactionType == 'ADJUST');
15-
lastTransactionType = val;
1615

1716
if(isCash != wasCash) {
1817
if(isCash) {
@@ -26,6 +25,14 @@ $(function() {
2625

2726
$(".securitiesField").each(function (idx, obj) { $.validationEngine.closePrompt(obj) });
2827
$(".cashField").each(function (idx, obj) { $.validationEngine.closePrompt(obj) });
28+
29+
if(lastTransactionType != val && val == 'ADJUST') {
30+
$(".securitiesField[name=symbol]").attr("disabled", "").val("").css("background-color", "#FFFFFF");
31+
$(".cashField[name=symbol]").attr("disabled", "disabled").val("").css("background-color", "#CCCCCC");
32+
}
33+
34+
lastTransactionType = val;
35+
2936
});
3037

3138
$("#addTransactionForm input").keypress(function(e) {
@@ -35,8 +42,8 @@ $(function() {
3542
}
3643
});
3744

38-
$("#quantity, #price, #comission").change(function() {
39-
$('#total').val((valueToFloat('#quantity', 0.0) * valueToFloat('#price', 0.0)) + valueToFloat('#comission', 0.0));
45+
$("#quantity, #price, #commission").change(function() {
46+
$('#total').val((valueToFloat('#quantity', 0.0) * valueToFloat('#price', 0.0)) + valueToFloat('#commission', 0.0));
4047
});
4148

4249
$("#addTransaction").click(function () {
@@ -79,10 +86,10 @@ $(function() {
7986
return;
8087
}
8188

82-
$.getJSON('/priceQuote.json', { day: asOf.getDate(), month: asOf.getMonth() + 1, year: asOf.getFullYear(), symbol: symbol }, function(data, textStatus) {
89+
$.getJSON('/priceQuote.json', { day: asOf.getDate(), month: asOf.getMonth() + 1, year: asOf.getFullYear(), symbol: symbol.toUpperCase() }, function(data, textStatus) {
8390
if(textStatus == 'success' && data.price > 0) {
8491
$('#price').val(data.price);
85-
$('#total').val((valueToFloat('#quantity', 0.0) * valueToFloat('#price', 0.0)) + valueToFloat('#comission', 0.0));
92+
$('#total').val((valueToFloat('#quantity', 0.0) * valueToFloat('#price', 0.0)) + valueToFloat('#commission', 0.0));
8693
}
8794
});
8895

frano/transactions/views.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,27 @@ def add(request, portfolio, is_sample, read_only):
6161

6262
type = form.cleaned_data.get('type').encode('UTF-8')
6363

64-
transaction = Transaction()
65-
transaction.portfolio = portfolio
66-
transaction.type = type
67-
transaction.as_of_date = form.cleaned_data.get('as_of_date')
68-
transaction.symbol = form.cleaned_data.get('symbol').encode('UTF-8').upper()
69-
transaction.quantity = form.cleaned_data.get('quantity')
70-
transaction.price = form.cleaned_data.get('price')
71-
transaction.total = (transaction.quantity * transaction.price) + commission
72-
transaction.save()
64+
symbol = form.cleaned_data.get('symbol').encode('UTF-8').upper()
65+
linked_symbol = None
66+
if type == 'ADJUST':
67+
linked_symbol = symbol
68+
69+
if type in ['DEPOSIT', 'WITHDRAW', 'ADJUST']:
70+
symbol = CASH_SYMBOL
7371

74-
refresh_positions(portfolio, force = True)
72+
if symbol != None and len(symbol) > 0:
73+
transaction = Transaction()
74+
transaction.portfolio = portfolio
75+
transaction.type = type
76+
transaction.as_of_date = form.cleaned_data.get('as_of_date')
77+
transaction.symbol = symbol
78+
transaction.quantity = form.cleaned_data.get('quantity')
79+
transaction.price = form.cleaned_data.get('price')
80+
transaction.total = (transaction.quantity * transaction.price) + commission
81+
transaction.linked_symbol = linked_symbol
82+
transaction.save()
83+
84+
refresh_positions(portfolio, force = True)
7585

7686
return redirect_to_portfolio_action('transactions', portfolio)
7787

@@ -269,7 +279,7 @@ def request_import_type(request, portfolio, is_sample, read_only):
269279
class TransactionForm(forms.Form):
270280
type = forms.ChoiceField(choices = TRANSACTION_TYPES)
271281
as_of_date = forms.DateField()
272-
symbol = forms.CharField(min_length = 1, max_length = 10)
282+
symbol = forms.CharField(min_length = 1, max_length = 10, required = False)
273283
quantity = forms.FloatField()
274284
price = forms.FloatField(min_value = 0.01)
275285
commission = forms.FloatField(min_value = 0.01, required = False)

0 commit comments

Comments
 (0)