From 2ca59c06849b5fbcf30a98b9afcce252ff458bdd Mon Sep 17 00:00:00 2001 From: Yingtong Li Date: Wed, 19 Jun 2019 17:03:52 +1000 Subject: [PATCH] Minor budget edit/view cosmetic improvements --- sstreasury/jinja2/sstreasury/budget_edit.html | 48 ++++++++++--------- sstreasury/jinja2/sstreasury/budget_view.html | 18 +++---- sstreasury/models.py | 5 +- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/sstreasury/jinja2/sstreasury/budget_edit.html b/sstreasury/jinja2/sstreasury/budget_edit.html index 392603a..7b6c9d5 100644 --- a/sstreasury/jinja2/sstreasury/budget_edit.html +++ b/sstreasury/jinja2/sstreasury/budget_edit.html @@ -32,7 +32,7 @@ -
+
@@ -139,11 +139,11 @@ }, onSuccess: function(event, fields) { var revenue_data = []; - $('#revenue_grid .jsgrid-grid-body tr:not(.totalrow)').each(function(i, el) { + $('#revenue_grid .jsgrid-grid-body tr:not(.totalrow):not(.jsgrid-nodata-row)').each(function(i, el) { var row = $(el).data('JSGridItem'); revenue_data.push({ 'Description': row['Description'], - 'Unit cost': row['Unit cost'], + 'Unit price': row['Unit price'], 'Units': row['Units'], 'IWT': row['IWT'], }); @@ -151,11 +151,11 @@ $('#revenue_input').val(JSON.stringify(revenue_data)); var expense_data = []; - $('#expense_grid .jsgrid-grid-body tr:not(.totalrow)').each(function(i, el) { + $('#expense_grid .jsgrid-grid-body tr:not(.totalrow):not(.jsgrid-nodata-row)').each(function(i, el) { var row = $(el).data('JSGridItem'); expense_data.push({ 'Description': row['Description'], - 'Unit cost': row['Unit cost'], + 'Unit price': row['Unit price'], 'Units': row['Units'], }); }); @@ -166,7 +166,7 @@ // Interferes with jsGrid $('.ui.form').on('keyup keypress', function(e) { var keyCode = e.keyCode || e.which; - if (keyCode === 13) { + if (keyCode === 13) { e.preventDefault(); return false; } @@ -177,9 +177,9 @@ var total = 0; var totalIWT = 0; for (var row of args.grid.data) { - total += row['Unit cost'] * row['Units']; - if (row['Unit cost'] > 0 && row['IWT']) { - totalIWT += (row['Unit cost'] - (row['Unit cost'] - 0.8) / 1.019) * row['Units']; + total += row['Unit price'] * row['Units']; + if (row['Unit price'] > 0 && row['IWT']) { + totalIWT += (row['Unit price'] - (row['Unit price'] - 0.8) / 1.019) * row['Units']; } } @@ -203,7 +203,7 @@ function recalcExpTotal(args) { var total = 0; for (var row of args.grid.data) { - total += row['Unit cost'] * row['Units']; + total += row['Unit price'] * row['Units']; } $(args.grid._body).find('.totalrow').remove(); @@ -244,15 +244,15 @@ height: '20em', inserting: true, editing: true, - noDataContent: 'No entries', + noDataContent: 'No entries. Click the green plus icon at the top right to add a new row.', data: revenue_data, fields: [ - { name: 'Description', type: 'text', width: '55%', validate: 'required' }, - { name: 'Unit cost', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } }, - { name: 'Units', type: 'float', width: '10%', validate: 'required' }, - { name: 'IWT', type: 'checkbox', width: '5%' }, - { name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit cost'] * item['Units']).toFixed(2); } }, - { type: 'control', width: '10%' }, + { name: 'Description', type: 'text', width: '50%', validate: 'required' }, + { name: 'Unit price', type: 'float', width: '12.5%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } }, + { name: 'Units', type: 'float', width: '12.5%', validate: 'required' }, + { name: 'IWT', type: 'checkbox', width: '5%', insertTemplate: function() { var result = jsGrid.fields.checkbox.prototype.insertTemplate.call(this); result.prop('checked', true); return result; } }, + { name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit price'] * item['Units']).toFixed(2); } }, + { type: 'control', width: '10%', modeSwitchButton: false }, ], onItemUpdated: recalcRevTotal, onRefreshed: recalcRevTotal, @@ -264,14 +264,14 @@ height: '20em', inserting: true, editing: true, - noDataContent: 'No entries', + noDataContent: 'No entries. Click the green plus icon at the top right to add a new row.', data: expense_data, fields: [ - { name: 'Description', type: 'text', width: '55%', validate: 'required' }, - { name: 'Unit cost', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } }, - { name: 'Units', type: 'float', width: '10%', validate: 'required' }, - { name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit cost'] * item['Units']).toFixed(2); } }, - { type: 'control', width: '10%' }, + { name: 'Description', type: 'text', width: '50%', validate: 'required' }, + { name: 'Unit price', type: 'float', width: '12.5%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } }, + { name: 'Units', type: 'float', width: '12.5%', validate: 'required' }, + { name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit price'] * item['Units']).toFixed(2); } }, + { type: 'control', width: '10%', modeSwitchButton: false }, ], onItemUpdated: recalcExpTotal, onRefreshed: recalcExpTotal, @@ -293,5 +293,7 @@ return el.classList.contains('totalrow'); } }); + + //$('.jsgrid-insert-mode-button').click(); {% endblock %} diff --git a/sstreasury/jinja2/sstreasury/budget_view.html b/sstreasury/jinja2/sstreasury/budget_view.html index c6172e5..1ba3ed2 100644 --- a/sstreasury/jinja2/sstreasury/budget_view.html +++ b/sstreasury/jinja2/sstreasury/budget_view.html @@ -25,7 +25,7 @@ {% if is_latest %}
- Status: {{ import('sstreasury.models').BudgetState(revision.state).description }} + Status: {{ revision.get_state_display() }} Edit
{% else %} @@ -198,9 +198,9 @@ var total = 0; var totalIWT = 0; for (var row of args.grid.data) { - total += row['Unit cost'] * row['Units']; - if (row['Unit cost'] > 0 && row['IWT']) { - totalIWT += (row['Unit cost'] - (row['Unit cost'] - 0.8) / 1.019) * row['Units']; + total += row['Unit price'] * row['Units']; + if (row['Unit price'] > 0 && row['IWT']) { + totalIWT += (row['Unit price'] - (row['Unit price'] - 0.8) / 1.019) * row['Units']; } } @@ -222,7 +222,7 @@ function recalcExpTotal(args) { var total = 0; for (var row of args.grid.data) { - total += row['Unit cost'] * row['Units']; + total += row['Unit price'] * row['Units']; } $(args.grid._body).find('.totalrow').remove(); @@ -263,10 +263,10 @@ data: revenue_data, fields: [ { name: 'Description', type: 'text', width: '55%', validate: 'required' }, - { name: 'Unit cost', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } }, + { name: 'Unit price', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } }, { name: 'Units', type: 'float', width: '10%', validate: 'required' }, { name: 'IWT', type: 'checkbox', width: '5%' }, - { name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit cost'] * item['Units']).toFixed(2); } }, + { name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit price'] * item['Units']).toFixed(2); } }, ], onRefreshed: recalcRevTotal, }); @@ -279,9 +279,9 @@ data: expense_data, fields: [ { name: 'Description', type: 'text', width: '55%', validate: 'required' }, - { name: 'Unit cost', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } }, + { name: 'Unit price', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } }, { name: 'Units', type: 'float', width: '10%', validate: 'required' }, - { name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit cost'] * item['Units']).toFixed(2); } }, + { name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit price'] * item['Units']).toFixed(2); } }, ], onRefreshed: recalcExpTotal, }); diff --git a/sstreasury/models.py b/sstreasury/models.py index 0749812..67dfe66 100644 --- a/sstreasury/models.py +++ b/sstreasury/models.py @@ -50,15 +50,14 @@ class BudgetState(Enum): class BudgetRevision(models.Model): budget = models.ForeignKey(Budget, on_delete=models.CASCADE) name = models.CharField(max_length=100) - date = models.DateField(null=True) + date = models.DateField() contributors = models.ManyToManyField(User, related_name='+') comments = models.TextField() author = models.ForeignKey(User, on_delete=models.PROTECT, related_name='+') time = models.DateTimeField() - #state = models.IntegerField(choices=[(v.value, v.description) for v in BudgetState]) - state = models.IntegerField() + state = models.IntegerField(choices=[(v.value, v.description) for v in BudgetState]) revenue = JSONField(default=[]) revenue_comments = models.TextField()