transfer history added

This commit is contained in:
Ludovic Stephan 2017-03-11 01:41:21 -03:00
parent ab6b0d52f2
commit 66beeb5bd0
3 changed files with 47 additions and 17 deletions

View file

@ -4,7 +4,9 @@ class History {
this.templates = { this.templates = {
'operation': '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>', 'operation': '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>',
'opegroup': '<div class="opegroup"><span class="time"></span><span class="trigramme"></span><span class="amount"></span><span class="valid_by"></span><span class="comment"></span></div>', 'opegroup': '<div class="opegroup"><span class="time"></span><span class="trigramme"></span><span class="amount"></span><span class="valid_by"></span><span class="comment"></span></div>',
'transfergroup': '<div class="opegroup"><span class="time"></span><span class="infos">Transferts</span><span class="valid_by"></span><span class="comment"></span></div>',
'day': '<div class="day"><span class="date"></span></div>', 'day': '<div class="day"><span class="date"></span></div>',
'transfer': '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="glyphicon glyphicon-arrow-right"></span><span class="infos2"></span><span class="canceled"></span></div>',
}; };
this._$container = $('#history'); this._$container = $('#history');

View file

@ -634,12 +634,12 @@ class OperationGroup extends ModelObject {
/** /**
* Properties associated with an opegroup. * Properties associated with an opegroup.
* @default <tt>['id', 'amount', 'at', 'is_cof', * @default <tt>['id', 'amount', 'at', 'is_cof',
* 'comment', 'trigramme', 'valid_by']</tt> * 'comment', 'trigramme', 'valid_by', 'day', 'type']</tt>
* @see {@link Models.ModelObject.props|ModelObject.props} * @see {@link Models.ModelObject.props|ModelObject.props}
*/ */
static get props() { static get props() {
return ['id', 'amount', 'at', 'is_cof', 'comment', 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} * @see {@link Models.ModelObject.default_data|ModelObject.default_data}
*/ */
static get default_data() { static get default_data() {
return {'id': 0, 'amount': 0, 'at': moment(), 'is_cof': false, return {'id': '', 'amount': 0, 'at': moment(), 'is_cof': false,
'comment': '', 'trigramme': '', 'valid_by': '', 'day': new Day()}; 'comment': '', 'trigramme': '', 'valid_by': '', 'day': new Day(),
'type': ''};
} }
/** /**
@ -697,13 +698,17 @@ class Operation extends ModelObject {
* Properties associated to an operation. * Properties associated to an operation.
* @default <tt>['id', 'type', 'amount', 'article_name', 'article_nb', * @default <tt>['id', 'type', 'amount', 'article_name', 'article_nb',
* 'is_checkout', 'addcost_amount', 'addcost_for', 'canceled_at', * 'is_checkout', 'addcost_amount', 'addcost_for', 'canceled_at',
* 'canceled_by']</tt> * 'canceled_by', 'from_acc', 'to_acc', 'opegroup']</tt>
* @see {@link Models.ModelObject.props|ModelObject.props} * @see {@link Models.ModelObject.props|ModelObject.props}
*/ */
static get props() { static get props() {
return ['id', 'type', 'amount', 'article_name', 'article_nb', var common = ['id', 'type', 'amount', 'canceled_at', 'canceled_by',
'is_checkout', 'addcost_amount', 'addcost_for', 'canceled_at', 'is_checkout', 'opegroup'];
'canceled_by', '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} * @see {@link Models.ModelObject.default_data|ModelObject.default_data}
*/ */
static get default_data() { static get default_data() {
return {'id': 0, 'type': '', 'amount': 0, 'article_name': '', 'article_nb': 0, var common = {'id': '', 'type': '', 'amount': 0, 'is_checkout': false,
'is_checkout': false, 'addcost_amount': 0, 'addcost_for': '', 'canceled_at': undefined, 'canceled_by': '',
'canceled_at': undefined, 'canceled_by': '', 'opegroup': new OperationGroup() }; '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'; } static get verbose_name() { return 'operation'; }
@ -724,6 +734,8 @@ class Operation extends ModelObject {
formatter() { formatter() {
if (this.type === 'purchase') if (this.type === 'purchase')
return PurchaseFormatter; return PurchaseFormatter;
else if (this.type == 'transfer')
return TransferFormatter;
else else
return SpecialOpeFormatter; return SpecialOpeFormatter;
} }
@ -847,8 +859,9 @@ class ModelList {
render_element(elt, templates, options) { render_element(elt, templates, options) {
var name = elt.constructor.verbose_name; var name = elt.constructor.verbose_name;
var depth = this.constructor.names.indexOf(name); var depth = this.constructor.names.indexOf(name);
var template = templates[name]; // Allows for more granular template specification
var options = options || {} ; var template = templates[elt.type] || templates[name];
var options = options || {} ;
if (depth == -1) { if (depth == -1) {
return $(); 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;
}
}

View file

@ -1400,7 +1400,7 @@ def history_json(request):
ope_list = [] ope_list = []
for opegroup in opegroups: for opegroup in opegroups:
opegroup_dict = { opegroup_dict = {
'id': opegroup.id, 'id': 'ope'+str(opegroup.id),
'type': 'opegroup', 'type': 'opegroup',
'amount': opegroup.amount, 'amount': opegroup.amount,
'at': opegroup.at, 'at': opegroup.at,
@ -1416,7 +1416,7 @@ def history_json(request):
opegroup.valid_by and opegroup.valid_by.trigramme or None) opegroup.valid_by and opegroup.valid_by.trigramme or None)
for ope in opegroup.opes.all(): for ope in opegroup.opes.all():
ope_dict = { ope_dict = {
'id': ope.id, 'id': 'ope'+str(ope.id),
'type': ope.type, 'type': ope.type,
'amount': ope.amount, 'amount': ope.amount,
'article_nb': ope.article_nb, 'article_nb': ope.article_nb,
@ -1437,7 +1437,7 @@ def history_json(request):
for transfergroup in transfergroups: for transfergroup in transfergroups:
if transfergroup.filtered_transfers: if transfergroup.filtered_transfers:
transfergroup_dict = { transfergroup_dict = {
'id': transfergroup.id, 'id': 'tr'+str(transfergroup.id),
'type': 'transfergroup', 'type': 'transfergroup',
'at': transfergroup.at, 'at': transfergroup.at,
'comment': transfergroup.comment, 'comment': transfergroup.comment,
@ -1452,7 +1452,7 @@ def history_json(request):
for transfer in transfergroup.filtered_transfers: for transfer in transfergroup.filtered_transfers:
transfer_dict = { transfer_dict = {
'id': transfer.id, 'id': 'tr'+str(transfer.id),
'type': 'transfer', 'type': 'transfer',
'amount': transfer.amount, 'amount': transfer.amount,
'canceled_at': transfer.canceled_at, 'canceled_at': transfer.canceled_at,