forked from DGNum/gestioCOF
transfer history added
This commit is contained in:
parent
ab6b0d52f2
commit
66beeb5bd0
3 changed files with 47 additions and 17 deletions
|
@ -4,7 +4,9 @@ class History {
|
|||
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>',
|
||||
'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>',
|
||||
'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');
|
||||
|
|
|
@ -634,12 +634,12 @@ class OperationGroup extends ModelObject {
|
|||
/**
|
||||
* Properties associated with an opegroup.
|
||||
* @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}
|
||||
*/
|
||||
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 <tt>['id', 'type', 'amount', 'article_name', 'article_nb',
|
||||
* '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}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue