Esempio n. 1
0
 def to_representation(self, instance):
     timestamp_ms = time.mktime(instance.date.timetuple()) * 1000
     return {
         "id": instance.pk,
         "url": self._context['request'].build_absolute_uri(
             reverse('banktransactions:banktransaction-detail', kwargs={
                 'pk': instance.pk,
             }),
         ),
         "title": "{label}, {amount}".format(
             label=instance.label,
             amount=localize_signed_amount_currency(
                 instance.amount,
                 instance.currency,
             ),
         ),
         "class": "event-important" if instance.amount < 0 else "event-success",
         "start": timestamp_ms,
         "end": timestamp_ms,
         "extra_data": {
             "label": instance.label,
             "balance_total": instance.balance_total,
             "balance_total_view": localize_signed_amount(
                 instance.balance_total,
             ) if instance.balance_total is not None else None,
             "balance_reconciled": instance.balance_reconciled,
             "balance_reconciled_view": localize_signed_amount(
                 instance.balance_reconciled,
             ) if instance.balance_reconciled is not None else None,
         },
     }
Esempio n. 2
0
    def to_representation(self, instance):
        ret = super(
            BankTransactionDetailSerializer, self).to_representation(instance)

        ret['date_view'] = date_format(instance.date, 'SHORT_DATE_FORMAT')
        ret['amount_localized'] = localize_signed_amount(instance.amount)
        ret['amount_currency'] = localize_signed_amount_currency(
            instance.amount, instance.currency)
        ret['payment_method_display'] = instance.get_payment_method_display()
        ret['status_display'] = instance.get_status_display()

        return ret
Esempio n. 3
0
    def to_representation(self, instance):
        ret = super(
            BankTransactionDetailExtraSerializer, self).to_representation(instance)

        fields = ('balance_total', 'balance_reconciled')
        for field in fields:
            attr = getattr(instance, field)
            key = field + '_view'
            if attr is not None:
                ret[key] = localize_signed_amount(attr)
            else:
                ret[key] = None

        return ret
Esempio n. 4
0
 def test_localize_signed_amount_fr_fr(self):
     self.assertEqual(
         localize_signed_amount(Decimal('15.23')),
         '+15,23',
     )