Example #1
0
 def ventilate_result(self, fiscal_year, ventilate):
     Owner.throw_not_allowed()
     self.check_account_config()
     result = fiscal_year.total_revenue - fiscal_year.total_expense
     if abs(result) > 0.001:
         total_part = PropertyLot.get_total_part()
         if total_part > 0:
             close_entry = EntryAccount(
                 year=fiscal_year,
                 designation=_("Ventilation for %s") % fiscal_year.toText,
                 journal_id=5)
             close_entry.check_date()
             close_entry.save()
             if ventilate == 0:
                 amount = 0
                 biggerowner_val = 0
                 biggerowner_line = None
                 for owner in Owner.objects.all():
                     total = owner.propertylot_set.aggregate(
                         sum=Sum('value'))
                     if ('sum' in total.keys()) and (total['sum']
                                                     is not None):
                         value = currency_round(result * total['sum'] /
                                                total_part)
                         if abs(value) > 0.0001:
                             owner_account = owner.third.get_account(
                                 fiscal_year, owner.get_third_mask(1))
                             last_line = EntryLineAccount.objects.create(
                                 account=owner_account,
                                 amount=-1 * value,
                                 entry=close_entry,
                                 third=owner.third)
                             if biggerowner_val < total['sum']:
                                 biggerowner_val = total['sum']
                                 biggerowner_line = last_line
                             amount += value
                 diff = currency_round(result - amount)
                 if abs(diff) > 0.0001:
                     biggerowner_line.amount -= diff
                     biggerowner_line.save()
             else:
                 EntryLineAccount.objects.create(account_id=ventilate,
                                                 amount=result,
                                                 entry=close_entry)
             reserve_account = ChartsAccount.get_account(
                 Params.getvalue("condominium-current-revenue-account"),
                 fiscal_year)
             EntryLineAccount.objects.create(account=reserve_account,
                                             amount=-1 * result,
                                             entry=close_entry)
             close_entry.closed()
Example #2
0
 def ventilate_costaccounting(self, own_set, cost_accounting, type_owner,
                              initial_code):
     if type_owner == 2:
         result = currency_round(
             CallDetail.objects.filter(set=own_set).aggregate(
                 sum=Sum('price'))['sum'])
     else:
         result = cost_accounting.get_total_revenue()
     result -= cost_accounting.get_total_expense()
     if abs(result) > 0.0001:
         fiscal_year = FiscalYear.get_current()
         close_entry = EntryAccount(year=fiscal_year,
                                    designation=_("Ventilation for %s") %
                                    own_set,
                                    journal_id=5)
         close_entry.check_date()
         close_entry.save()
         amount = 0
         last_line = None
         for part in own_set.partition_set.all().order_by('value'):
             value = currency_round(result * part.get_ratio() / 100.0)
             if abs(value) > 0.0001:
                 owner_account = part.owner.third.get_account(
                     fiscal_year, part.owner.get_third_mask(type_owner))
                 last_line = EntryLineAccount.objects.create(
                     account=owner_account,
                     amount=-1 * value,
                     entry=close_entry,
                     third=part.owner.third)
                 amount += value
         if last_line is None:
             raise LucteriosException(
                 IMPORTANT,
                 _('The class load %s has no owner') % own_set)
         diff = currency_round(result - amount)
         if abs(diff) > 0.0001:
             last_line.amount -= diff
             last_line.save()
         reserve_account = ChartsAccount.get_account(
             initial_code, fiscal_year)
         EntryLineAccount.objects.create(account=reserve_account,
                                         amount=-1 * result,
                                         entry=close_entry,
                                         costaccounting=cost_accounting)
         close_entry.closed()