Exemplo n.º 1
0
 def get_reduce_vat(self):
     if self.vta_rate < -0.001:
         return currency_round(self.reduce * -1 * self.vta_rate / (1 - self.vta_rate))
     elif self.vta_rate > 0.001:
         return currency_round(self.reduce * self.vta_rate)
     else:
         return 0
Exemplo n.º 2
0
 def get_vta(self):
     val = 0
     if self.vta_rate > 0.001:
         val = currency_round(self.price * self.quantity * self.vta_rate)
     elif self.vta_rate < -0.001:
         val = currency_round(
             self.price * self.quantity * -1 * self.vta_rate / (1 - self.vta_rate))
     val -= self.get_reduce_vat()
     return val
Exemplo n.º 3
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()
Exemplo n.º 4
0
 def generate_revenue_for_expense(self, expense, is_asset, fiscal_year):
     if Params.getvalue("condominium-old-accounting"):
         for detail in expense.expensedetail_set.all():
             self._generate_revenue_for_expense_oldaccounting(detail, is_asset, fiscal_year)
     elif len(expense.expensedetail_set.filter(set__type_load=1)) > 0:
         total = 0
         revenue_code = Params.getvalue("condominium-exceptional-revenue-account")
         revenue_account = ChartsAccount.get_account(revenue_code, fiscal_year)
         if revenue_account is None:
             raise LucteriosException(IMPORTANT, _("code account %s unknown!") % revenue_code)
         reserve_code = Params.getvalue("condominium-exceptional-reserve-account")
         reserve_account = ChartsAccount.get_account(reserve_code, fiscal_year)
         if revenue_account is None:
             raise LucteriosException(IMPORTANT, _("code account %s unknown!") % reserve_code)
         new_entry = EntryAccount.objects.create(year=fiscal_year, date_value=expense.expense.date, designation=expense.__str__(), journal=Journal.objects.get(id=3))
         for detail in expense.expensedetail_set.all():
             detail.generate_ratio(is_asset)
             if detail.set.type_load == 1:
                 cost_accounting = detail.set.current_cost_accounting
                 price = currency_round(detail.price)
                 EntryLineAccount.objects.create(account=revenue_account, amount=is_asset * price, entry=new_entry, costaccounting=cost_accounting)
                 total += price
                 detail.entry = new_entry
                 detail.save()
         EntryLineAccount.objects.create(account=reserve_account, amount=-1 * is_asset * total, entry=new_entry)
         no_change, debit_rest, credit_rest = new_entry.serial_control(new_entry.get_serial())
         if not no_change or (abs(debit_rest) > 0.001) or (abs(credit_rest) > 0.001):
             raise LucteriosException(GRAVE, _("Error in accounting generator!") +
                                      "{[br/]} no_change=%s debit_rest=%.3f credit_rest=%.3f" % (no_change, debit_rest, credit_rest))
Exemplo n.º 5
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()
Exemplo n.º 6
0
 def multi_save(cls, supportings, amount, mode, payer, reference, bank_account, date):
     supporting_list = Supporting.objects.filter(id__in=supportings, is_revenu=True)
     amount_sum = 0
     for supporting in supporting_list:
         amount_sum += supporting.get_final_child().get_total_rest_topay()
     if abs(amount_sum) < 0.0001:
         raise LucteriosException(IMPORTANT, _('No-valid selection!'))
     amount_rest = amount
     paypoff_list = []
     for supporting in supporting_list:
         new_paypoff = Payoff(
             supporting=supporting, date=date, payer=payer, mode=mode, reference=reference)
         if bank_account != 0:
             new_paypoff.bank_account = BankAccount.objects.get(
                 id=bank_account)
         new_paypoff.amount = currency_round(
             supporting.get_final_child().get_total_rest_topay() * amount / amount_sum)
         if new_paypoff.amount > 0.0001:
             amount_rest -= new_paypoff.amount
             new_paypoff.save(do_generate=False)
             paypoff_list.append(new_paypoff)
     if abs(amount_rest) > 0.001:
         new_paypoff.amount += amount_rest
         new_paypoff.save(do_generate=False)
     third_amounts = {}
     designation_items = []
     for paypoff_item in paypoff_list:
         if paypoff_item.supporting.third not in third_amounts.keys():
             third_amounts[paypoff_item.supporting.third] = 0
         third_amounts[paypoff_item.supporting.third] += paypoff_item.amount
         designation_items.append(six.text_type(paypoff_item.supporting.get_final_child()))
     designation = _("payoff for %s") % ",".join(designation_items)
     if len(designation) > 190:
         designation = _("payoff for %d multi-pay") % len(designation_items)
     new_entry = paypoff_list[0].generate_accounting(third_amounts.items(), designation)
     for paypoff_item in paypoff_list:
         paypoff_item.entry = new_entry
         paypoff_item.save(do_generate=False)
     new_entry.unlink()
     try:
         entrylines = []
         for supporting in supporting_list:
             supporting = supporting.get_final_child()
             if (abs(supporting.get_total_rest_topay()) < 0.0001) and (supporting.entry_links() is not None) and (len(supporting.payoff_set.filter(supporting.payoff_query)) == 1):
                 entrylines.extend(supporting.entry_links())
         if len(entrylines) == len(supporting_list):
             entrylines.append(new_entry)
             AccountLink.create_link(entrylines)
     except LucteriosException:
         pass
Exemplo n.º 7
0
 def generate_expense_for_expense(self, expense, is_asset, fiscal_year):
     third_account = expense.get_third_account(current_system_account().get_provider_mask(), fiscal_year)
     new_entry = EntryAccount.objects.create(year=fiscal_year, date_value=expense.date, designation=expense.__str__(), journal=Journal.objects.get(id=2))
     total = 0
     for detail in expense.expensedetail_set.all():
         detail_account = ChartsAccount.get_account(detail.expense_account, fiscal_year)
         if detail_account is None:
             raise LucteriosException(IMPORTANT, _("code account %s unknown!") % detail.expense_account)
         price = currency_round(detail.price)
         EntryLineAccount.objects.create(account=detail_account, amount=is_asset * price, entry=new_entry, costaccounting_id=detail.set.current_cost_accounting.id)
         total += price
     EntryLineAccount.objects.create(account=third_account, amount=is_asset * total, third=expense.third, entry=new_entry)
     no_change, debit_rest, credit_rest = new_entry.serial_control(new_entry.get_serial())
     if not no_change or (abs(debit_rest) > 0.001) or (abs(credit_rest) > 0.001):
         raise LucteriosException(GRAVE, _("Error in accounting generator!") +
                                  "{[br/]} no_change=%s debit_rest=%.3f credit_rest=%.3f" % (no_change, debit_rest, credit_rest))
     expense.entries.set(EntryAccount.objects.filter(id=new_entry.id))
Exemplo n.º 8
0
 def _generate_revenue_for_expense_oldaccounting(self, expense_detail, is_asset, fiscal_year):
     revenue_code = expense_detail.set.revenue_account
     cost_accounting = expense_detail.set.current_cost_accounting
     revenue_account = ChartsAccount.get_account(revenue_code, fiscal_year)
     if revenue_account is None:
         raise LucteriosException(IMPORTANT, _("code account %s unknown!") % revenue_code)
     price = currency_round(expense_detail.price)
     new_entry = EntryAccount.objects.create(year=fiscal_year, date_value=expense_detail.expense.date, designation=expense_detail.__str__(), journal=Journal.objects.get(id=3))
     EntryLineAccount.objects.create(account=revenue_account, amount=is_asset * price, entry=new_entry, costaccounting=cost_accounting)
     for ratio in expense_detail.expenseratio_set.all():
         third_account = expense_detail.expense.get_third_account(current_system_account().get_societary_mask(), fiscal_year, ratio.owner.third)
         EntryLineAccount.objects.create(account=third_account, amount=ratio.value, entry=new_entry, third=ratio.owner.third)
     no_change, debit_rest, credit_rest = new_entry.serial_control(new_entry.get_serial())
     if not no_change or (abs(debit_rest) > 0.001) or (abs(credit_rest) > 0.001):
         raise LucteriosException(GRAVE, _("Error in accounting generator!") +
                                  "{[br/]} no_change=%s debit_rest=%.3f credit_rest=%.3f" % (no_change, debit_rest, credit_rest))
     expense_detail.entry = new_entry
     expense_detail.save()
Exemplo n.º 9
0
 def get_total_payed(self, ignore_payoff=-1):
     val = 0
     for payoff in self.payoff_set.filter(self.payoff_query):
         if payoff.id != ignore_payoff:
             val += currency_round(payoff.amount)
     return val
Exemplo n.º 10
0
 def get_reduce_excltax(self):
     if self.vta_rate < -0.001:
         return currency_round(self.reduce) - self.get_reduce_vat()
     else:
         return currency_round(self.reduce)
Exemplo n.º 11
0
 def get_total(self):
     return currency_round(self.price * self.quantity - self.reduce)
Exemplo n.º 12
0
 def get_reduce(self):
     if (Params.getvalue("invoice-vat-mode") == 2) and (self.vta_rate > 0.001):
         return currency_round(self.reduce * self.vta_rate)
     if (Params.getvalue("invoice-vat-mode") == 1) and (self.vta_rate < -0.001):
         return currency_round(self.reduce * -1 * self.vta_rate / (1 - self.vta_rate))
     return float(self.reduce)
Exemplo n.º 13
0
 def get_tax(self):
     return currency_round(self.get_tax_sum() * self.get_total_rest_topay() / self.get_total_incltax())