Beispiel #1
0
 def _add_total_account(self):
     if self.last_account is not None:
         self.grid.set_value(self.line_idx, 'entry.designation', get_spaces(
             30) + "{[i]}%s{[/i]}" % _('total'))
         self.grid.set_value(self.line_idx, 'debit', "{[i]}%s{[/i]}" % format_devise(
             max((0, -1 * self.last_account.credit_debit_way() * self.last_total)), 0))
         self.grid.set_value(self.line_idx, 'credit', "{[i]}%s{[/i]}" % format_devise(
             max((0, self.last_account.credit_debit_way() * self.last_total)), 0))
         self.line_idx += 1
         self.grid.set_value(self.line_idx, 'entry.designation', '{[br/]}')
         self.line_idx += 1
         self.last_total = 0
Beispiel #2
0
 def _create_custom_for_profit(self, year, custom, val_profit):
     from lucterios.framework.xfercomponents import XferCompImage, XferCompLabelForm, XferCompSelect
     from diacamma.accounting.models import format_devise
     if val_profit > 0.0001:
         type_profit = 'bénéfice'
     else:
         type_profit = 'déficite'
     img = XferCompImage("img")
     img.set_location(0, 0)
     img.set_value(get_icon_path("diacamma.accounting/images/account.png"))
     custom.add_component(img)
     lbl = XferCompLabelForm("title")
     lbl.set_value_as_headername("Bénéfices et Pertes")
     lbl.set_location(1, 0)
     custom.add_component(lbl)
     text = "{[i]}Vous avez un %s de %s.{[br/]}Vous devez definir sur quel compte l'affecter.{[br/]}{[/i]}" % (
         type_profit, format_devise(val_profit, 4))
     text += "{[br/]}En validant, vous commencerez '%s'{[br/]}{[br/]}{[i]}{[u]}Attention:{[/u]} Votre report à nouveau doit être totalement fait.{[/i]}" % six.text_type(
         year)
     lbl = XferCompLabelForm("info")
     lbl.set_value(text)
     lbl.set_location(0, 1, 2)
     custom.add_component(lbl)
     sel_cmpt = []
     for account in year.chartsaccount_set.all().filter(code__startswith='10').order_by('code'):
         sel_cmpt.append((account.id, six.text_type(account)))
     sel = XferCompSelect("profit_account")
     sel.set_select(sel_cmpt)
     sel.set_location(1, 2)
     custom.add_component(sel)
     return custom
Beispiel #3
0
 def calcul_table(self):
     line_idx = 1
     balance_values = self._get_balance_values()
     keys = list(balance_values.keys())
     keys.sort()
     for key in keys:
         self.grid.set_value(
             line_idx, 'designation', balance_values[key][0])
         self.grid.set_value(
             line_idx, 'total_debit', format_devise(balance_values[key][1], 5))
         self.grid.set_value(
             line_idx, 'total_credit', format_devise(balance_values[key][2], 5))
         diff = balance_values[key][1] - balance_values[key][2]
         self.grid.set_value(
             line_idx, 'solde_debit', format_devise(max(0, diff), 0))
         if abs(diff) < 0.0001:
             self.grid.set_value(
                 line_idx, 'solde_credit', format_devise(0, 5))
         else:
             self.grid.set_value(
                 line_idx, 'solde_credit', format_devise(max(0, -1 * diff), 0))
         line_idx += 1
Beispiel #4
0
def convert_query_to_account(query1, query2=None, query_budget=None):
    total1 = 0
    total2 = None
    total3 = None
    dict_account = {}
    for data_line in EntryLineAccount.objects.filter(query1).values('account').annotate(data_sum=Sum('amount')):
        account = ChartsAccount.objects.get(id=data_line['account'])
        if abs(data_line['data_sum']) > 0.0001:
            dict_account[correct_accounting_code(account.code)] = [account.get_name(), format_devise(data_line['data_sum'], 5), None, None]
            total1 += data_line['data_sum']
    if query2 is not None:
        total2 = 0
        for data_line in EntryLineAccount.objects.filter(query2).values('account').annotate(data_sum=Sum('amount')):
            account = ChartsAccount.objects.get(id=data_line['account'])
            if abs(data_line['data_sum']) > 0.0001:
                account_code = correct_accounting_code(account.code)
                if account_code not in dict_account.keys():
                    dict_account[account_code] = [account.get_name(), None, 0, None]
                dict_account[account_code][2] = format_devise(data_line['data_sum'], 5)
                total2 += data_line['data_sum']
    if query_budget is not None:
        total3 = 0
        for data_line in Budget.objects.filter(query_budget).values('code').annotate(data_sum=Sum('amount')):
            if abs(data_line['data_sum']) > 0.0001:
                account_code = correct_accounting_code(data_line['code'])
                if account_code not in dict_account.keys():
                    account = ChartsAccount.get_chart_account(account_code)
                    dict_account[account_code] = [account.get_name(), None, None, 0]
                dict_account[account_code][3] = format_devise(data_line['data_sum'], 5)
                total3 += data_line['data_sum']
    res = []
    keys = list(dict_account.keys())
    keys.sort()
    for key in keys:
        res.append(dict_account[key])
    return res, total1, total2, total3
Beispiel #5
0
 def _add_left_right_accounting(self, left_filter, rigth_filter, total_in_left):
     data_line_left, total1_left, total2_left, totalb_left = convert_query_to_account(
         self.filter & left_filter, self.lastfilter & left_filter if self.lastfilter is not None else None, self.budgetfilter_left)
     data_line_right, total1_right, total2_right, totalb_right = convert_query_to_account(
         self.filter & rigth_filter, self.lastfilter & rigth_filter if self.lastfilter is not None else None, self.budgetfilter_right)
     line_idx = 0
     for line_idx in range(max(len(data_line_left), len(data_line_right))):
         if line_idx < len(data_line_left):
             self.grid.set_value(
                 line_idx, 'left', data_line_left[line_idx][0])
             self.grid.set_value(
                 line_idx, 'left_n', data_line_left[line_idx][1])
             if self.lastfilter is not None:
                 self.grid.set_value(
                     line_idx, 'left_n_1', data_line_left[line_idx][2])
             if self.budgetfilter_left is not None:
                 self.grid.set_value(
                     line_idx, 'left_b', data_line_left[line_idx][3])
         if line_idx < len(data_line_right):
             self.grid.set_value(
                 line_idx, 'right', data_line_right[line_idx][0])
             self.grid.set_value(
                 line_idx, 'right_n', data_line_right[line_idx][1])
             if self.lastfilter is not None:
                 self.grid.set_value(
                     line_idx, 'right_n_1', data_line_right[line_idx][2])
             if self.budgetfilter_right is not None:
                 self.grid.set_value(
                     line_idx, 'right_b', data_line_right[line_idx][3])
     line_idx += 1
     self.grid.set_value(line_idx, 'left', '')
     self.grid.set_value(line_idx, 'right', '')
     line_idx += 1
     if (abs(total1_left - total1_right) > 0.0001) or ((total2_left is not None) and (total2_right is not None) and (abs(total2_left - total2_right) > 0.0001)):
         if total_in_left:
             self.grid.set_value(line_idx, 'left', get_spaces(5) + "{[i]}%s{[/i]}" % _('result (profit)'))
             self.grid.set_value(line_idx, 'right', get_spaces(5) + "{[i]}%s{[/i]}" % _('result (deficit)'))
         else:
             self.grid.set_value(line_idx, 'left', get_spaces(5) + "{[i]}%s{[/i]}" % _('result (deficit)'))
             self.grid.set_value(line_idx, 'right', get_spaces(5) + "{[i]}%s{[/i]}" % _('result (profit)'))
         self.grid.set_value(line_idx, 'right_n', '')
         self.grid.set_value(line_idx, 'right_n_1', '')
         self.grid.set_value(line_idx, 'right_b', '')
         self.grid.set_value(line_idx, 'left_n', '')
         self.grid.set_value(line_idx, 'left_n_1', '')
         self.grid.set_value(line_idx, 'left_b', '')
         result_n = total1_right - total1_left
         if (total2_left is not None) and (total2_right is not None):
             result_n_1 = total2_right - total2_left
         else:
             result_n_1 = 0.0
         if (totalb_left is not None) and (totalb_right is not None):
             result_b = totalb_right - totalb_left
         else:
             result_b = 0.0
         if total_in_left:
             if result_n > 0:
                 pos_n = 'left_n'
             else:
                 pos_n = 'right_n'
             if result_n_1 > 0:
                 pos_n_1 = 'left_n_1'
             else:
                 pos_n_1 = 'right_n_1'
             if result_b > 0:
                 pos_b = 'left_b'
             else:
                 pos_b = 'right_b'
         else:
             result_n = -1 * result_n
             result_n_1 = -1 * result_n
             if result_n > 0:
                 pos_n = 'right_n'
             else:
                 pos_n = 'left_n'
             if result_n_1 > 0:
                 pos_n_1 = 'right_n_1'
             else:
                 pos_n_1 = 'left_n_1'
             if result_b > 0:
                 pos_b = 'right_b'
             else:
                 pos_b = 'left_b'
         self.grid.set_value(line_idx, pos_n, format_devise(abs(result_n), 5))
         if (totalb_left is not None) and (abs(result_b) > 0.0001):
             self.grid.set_value(line_idx, pos_b, format_devise(abs(result_b), 5))
         else:
             pos_b = ""
         if (self.lastfilter is not None) and (abs(result_n_1) > 0.0001):
             self.grid.set_value(line_idx, pos_n_1, format_devise(abs(result_n_1), 5))
         else:
             pos_n_1 = ""
         if (pos_n != 'left_n') and (pos_n_1 != 'left_n_1') and (pos_b != 'left_b'):
             self.grid.set_value(line_idx, 'left', '')
         if (pos_n != 'right_n') and (pos_n_1 != 'right_n_1') and (pos_b != 'right_b'):
             self.grid.set_value(line_idx, 'right', '')
         line_idx += 1
     self.grid.set_value(
         line_idx, 'left', get_spaces(10) + "{[u]}{[b]}%s{[/b]}{[/u]}" % _('total'))
     self.grid.set_value(
         line_idx, 'left_n', "{[u]}{[b]}%s{[/b]}{[/u]}" % format_devise(max(total1_left, total1_right), 5))
     if self.lastfilter is not None:
         self.grid.set_value(
             line_idx, 'left_n_1', "{[u]}{[b]}%s{[/b]}{[/u]}" % format_devise(max(total2_left, total2_right), 5))
     if self.budgetfilter_left is not None:
         self.grid.set_value(
             line_idx, 'left_b', "{[u]}{[b]}%s{[/b]}{[/u]}" % format_devise(max(totalb_left, totalb_right), 5))
     self.grid.set_value(
         line_idx, 'right', get_spaces(10) + "{[u]}{[b]}%s{[/b]}{[/u]}" % _('total'))
     self.grid.set_value(
         line_idx, 'right_n', "{[u]}{[b]}%s{[/b]}{[/u]}" % format_devise(max(total1_left, total1_right), 5))
     if self.lastfilter is not None:
         self.grid.set_value(
             line_idx, 'right_n_1', "{[u]}{[b]}%s{[/b]}{[/u]}" % format_devise(max(total2_left, total2_right), 5))
     if self.budgetfilter_right is not None:
         self.grid.set_value(
             line_idx, 'right_b', "{[u]}{[b]}%s{[/b]}{[/u]}" % format_devise(max(totalb_left, totalb_right), 5))