Exemplo n.º 1
0
def totals_row(cl):
    total_functions = getattr(cl.model_admin, 'total_functions', {})
    totals = []
    for field_name in cl.list_display:
        field_name = field_name.replace('_', '')
        #print("[ H e Y ] -> ", field_name)
        if field_name in total_functions:
            # result_list: és el QuerySet del ModelAdmin.
            #         Exemple:  <QuerySet [<MaterialsStock: M67 - 121 - 27 - BOB - [3.00]>,
            # values: array amb els valors del camp a totalitzar.
            #         Exemple:  [Decimal('3.00'), Decimal('4.00'), Decimal('5.00')]
            values = [getattr(i, field_name) for i in cl.result_list]
            # Totals: array amb una fila per cada columna del QuerySet,
            #         on apliquem per a cada columna de total_functions la funció
            #         que té associada, per exemple sum, a l'array de valors (values)
            total_str = get_currency_representation(
                total_functions[field_name](values),
                positive_color='aqua',
                negative_color='fuchsia')
            totals.append(total_str)
        elif field_name == 'actioncheckbox' and total_functions:
            totals.append('Totals')
        else:
            totals.append('')
    return {
        'cl': cl,
        'totals_row': totals,
        'totals_count': len(total_functions)
    }
Exemplo n.º 2
0
 def agosto_(self):
     return get_currency_representation(self.agosto)
Exemplo n.º 3
0
 def total_(self):
     return get_currency_representation(self.total,
                                        positive_color='aqua',
                                        negative_color='fuchsia')
Exemplo n.º 4
0
 def mayo_(self):
     return get_currency_representation(self.mayo)
Exemplo n.º 5
0
 def julio_(self):
     return get_currency_representation(self.julio)
Exemplo n.º 6
0
 def febrero_(self):
     return get_currency_representation(self.febrero)
Exemplo n.º 7
0
 def abril_(self):
     return get_currency_representation(self.abril)
Exemplo n.º 8
0
 def enero_(self):
     return get_currency_representation(self.enero)
Exemplo n.º 9
0
 def diciembre_(self):
     return get_currency_representation(self.diciembre)
Exemplo n.º 10
0
 def noviembre_(self):
     return get_currency_representation(self.noviembre)
Exemplo n.º 11
0
 def octubre_(self):
     return get_currency_representation(self.octubre)
Exemplo n.º 12
0
 def setiembre_(self):
     return get_currency_representation(self.setiembre)