diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js
index 599dd9c6..670429f9 100644
--- a/kfet/static/kfet/js/history.js
+++ b/kfet/static/kfet/js/history.js
@@ -4,7 +4,9 @@ class History {
this.templates = {
'operation': '
',
'opegroup': '
',
+ 'transfergroup': 'Transferts
',
'day': '
',
+ 'transfer': '
',
};
this._$container = $('#history');
diff --git a/kfet/static/kfet/js/kfet.api.js b/kfet/static/kfet/js/kfet.api.js
index d94a8b5b..5748c3ee 100644
--- a/kfet/static/kfet/js/kfet.api.js
+++ b/kfet/static/kfet/js/kfet.api.js
@@ -634,12 +634,12 @@ class OperationGroup extends ModelObject {
/**
* Properties associated with an opegroup.
* @default ['id', 'amount', 'at', 'is_cof',
- * 'comment', 'trigramme', 'valid_by']
+ * 'comment', 'trigramme', 'valid_by', 'day', 'type']
* @see {@link Models.ModelObject.props|ModelObject.props}
*/
static get props() {
return ['id', 'amount', 'at', 'is_cof', 'comment',
- 'trigramme', 'valid_by', 'day'];
+ 'trigramme', 'valid_by', 'day', 'type'];
}
/**
@@ -649,8 +649,9 @@ class OperationGroup extends ModelObject {
* @see {@link Models.ModelObject.default_data|ModelObject.default_data}
*/
static get default_data() {
- return {'id': 0, 'amount': 0, 'at': moment(), 'is_cof': false,
- 'comment': '', 'trigramme': '', 'valid_by': '', 'day': new Day()};
+ return {'id': '', 'amount': 0, 'at': moment(), 'is_cof': false,
+ 'comment': '', 'trigramme': '', 'valid_by': '', 'day': new Day(),
+ 'type': ''};
}
/**
@@ -697,13 +698,17 @@ class Operation extends ModelObject {
* Properties associated to an operation.
* @default ['id', 'type', 'amount', 'article_name', 'article_nb',
* 'is_checkout', 'addcost_amount', 'addcost_for', 'canceled_at',
- * 'canceled_by']
+ * 'canceled_by', 'from_acc', 'to_acc', 'opegroup']
* @see {@link Models.ModelObject.props|ModelObject.props}
*/
static get props() {
- return ['id', 'type', 'amount', 'article_name', 'article_nb',
- 'is_checkout', 'addcost_amount', 'addcost_for', 'canceled_at',
- 'canceled_by', 'opegroup']
+ var common = ['id', 'type', 'amount', 'canceled_at', 'canceled_by',
+ 'is_checkout', 'opegroup'];
+ var transfer_only = ['from_acc', 'to_acc'];
+ var purchase_only = ['article_name', 'article_nb', 'addcost_for',
+ 'addcost_amount'];
+
+ return common.concat(transfer_only, purchase_only);
}
/**
@@ -714,9 +719,14 @@ class Operation extends ModelObject {
* @see {@link Models.ModelObject.default_data|ModelObject.default_data}
*/
static get default_data() {
- return {'id': 0, 'type': '', 'amount': 0, 'article_name': '', 'article_nb': 0,
- 'is_checkout': false, 'addcost_amount': 0, 'addcost_for': '',
- 'canceled_at': undefined, 'canceled_by': '', 'opegroup': new OperationGroup() };
+ var common = {'id': '', 'type': '', 'amount': 0, 'is_checkout': false,
+ 'canceled_at': undefined, 'canceled_by': '',
+ 'opegroup': new OperationGroup()};
+ var transfer_only = {'from_acc': '', 'to_acc': ''};
+ var purchase_only = {'article_name': '', 'article_nb': 0,
+ 'addcost_amount': 0, 'addcost_for': 0};
+
+ return $.extend({}, common, transfer_only, purchase_only);
}
static get verbose_name() { return 'operation'; }
@@ -724,6 +734,8 @@ class Operation extends ModelObject {
formatter() {
if (this.type === 'purchase')
return PurchaseFormatter;
+ else if (this.type == 'transfer')
+ return TransferFormatter;
else
return SpecialOpeFormatter;
}
@@ -847,8 +859,9 @@ class ModelList {
render_element(elt, templates, options) {
var name = elt.constructor.verbose_name;
var depth = this.constructor.names.indexOf(name);
- var template = templates[name];
- var options = options || {} ;
+ // Allows for more granular template specification
+ var template = templates[elt.type] || templates[name];
+ var options = options || {} ;
if (depth == -1) {
return $();
@@ -1430,3 +1443,18 @@ class SpecialOpeFormatter extends OperationFormatter {
}
}
}
+
+class TransferFormatter extends OperationFormatter {
+
+ static prop_amount(a) {
+ return a.amount.toFixed(2)+'€';
+ }
+
+ static prop_infos1(a) {
+ return a.from_acc;
+ }
+
+ static prop_infos2(a) {
+ return a.to_acc;
+ }
+}
diff --git a/kfet/views.py b/kfet/views.py
index 760949ea..ca750bc3 100644
--- a/kfet/views.py
+++ b/kfet/views.py
@@ -1400,7 +1400,7 @@ def history_json(request):
ope_list = []
for opegroup in opegroups:
opegroup_dict = {
- 'id': opegroup.id,
+ 'id': 'ope'+str(opegroup.id),
'type': 'opegroup',
'amount': opegroup.amount,
'at': opegroup.at,
@@ -1416,7 +1416,7 @@ def history_json(request):
opegroup.valid_by and opegroup.valid_by.trigramme or None)
for ope in opegroup.opes.all():
ope_dict = {
- 'id': ope.id,
+ 'id': 'ope'+str(ope.id),
'type': ope.type,
'amount': ope.amount,
'article_nb': ope.article_nb,
@@ -1437,7 +1437,7 @@ def history_json(request):
for transfergroup in transfergroups:
if transfergroup.filtered_transfers:
transfergroup_dict = {
- 'id': transfergroup.id,
+ 'id': 'tr'+str(transfergroup.id),
'type': 'transfergroup',
'at': transfergroup.at,
'comment': transfergroup.comment,
@@ -1452,7 +1452,7 @@ def history_json(request):
for transfer in transfergroup.filtered_transfers:
transfer_dict = {
- 'id': transfer.id,
+ 'id': 'tr'+str(transfer.id),
'type': 'transfer',
'amount': transfer.amount,
'canceled_at': transfer.canceled_at,