Exemple #1
0
 def _create_thirds_ending_entry(self, year):
     from diacamma.accounting.models import get_amount_sum, Journal, EntryAccount, EntryLineAccount, ChartsAccount, Third
     from django.db.models.aggregates import Sum
     sum40 = get_amount_sum(EntryLineAccount.objects.filter(
         account__code__startswith='401', account__year=year).aggregate(Sum('amount')))
     sum41 = get_amount_sum(EntryLineAccount.objects.filter(
         account__code__startswith='411', account__year=year).aggregate(Sum('amount')))
     sum42 = get_amount_sum(EntryLineAccount.objects.filter(
         account__code__startswith='421', account__year=year).aggregate(Sum('amount')))
     sum45 = get_amount_sum(EntryLineAccount.objects.filter(
         account__code__startswith='450', account__year=year).aggregate(Sum('amount')))
     if (abs(sum40) > 0.001) or (abs(sum41) > 0.001) or (abs(sum42) > 0.001) or (abs(sum45) > 0.001):
         end_journ = Journal.objects.get(id=5)
         end_desig = "Cloture d'exercice - Résultat"
         new_entry = EntryAccount.objects.create(
             year=year, journal=end_journ, designation=end_desig, date_value=year.end)
         for data_line in EntryLineAccount.objects.filter(account__code__regex=THIRD_MASK, account__year=year).values('account', 'third').annotate(data_sum=Sum('amount')):
             if abs(data_line['data_sum']) > 0.0001:
                 new_line = EntryLineAccount()
                 new_line.entry = new_entry
                 new_line.amount = -1 * data_line['data_sum']
                 new_line.account = ChartsAccount.objects.get(
                     id=data_line['account'])
                 if data_line['third'] is not None:
                     new_line.third = Third.objects.get(
                         id=data_line['third'])
                 new_line.save()
         new_entry.add_entry_line(sum40, '401')
         new_entry.add_entry_line(sum41, '411')
         new_entry.add_entry_line(sum42, '421')
         new_entry.add_entry_line(sum45, '450')
         new_entry.closed()
Exemple #2
0
 def _create_profit_entry(self, year, profit_account):
     from diacamma.accounting.models import Journal, EntryAccount, EntryLineAccount, ChartsAccount
     from django.db.models import Q
     paym_journ = Journal.objects.get(id=1)
     paym_desig = 'Affectation des bénéfices/pertes'
     new_entry = EntryAccount.objects.create(
         year=year, journal=paym_journ, designation=paym_desig, date_value=year.begin)
     query = Q(account__code__startswith='110') | Q(
         account__code__startswith='119')
     query &= Q(account__year=year)
     sum_profit = 0
     for new_line in EntryLineAccount.objects.filter(query):
         sum_profit += new_line.amount
         new_line.id = None
         new_line.entry = new_entry
         new_line.amount = -1 * new_line.amount
         new_line.save()
     new_line = EntryLineAccount()
     new_line.entry = new_entry
     new_line.amount = sum_profit
     new_line.account = ChartsAccount.objects.get(
         id=profit_account)
     new_line.save()
     new_entry.closed()
     return True