예제 #1
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))
예제 #2
0
 def generate_entry(self):
     if self.bill_type == 2:
         is_bill = -1
     else:
         is_bill = 1
     third_account = self.get_third_account(
         current_system_account().get_customer_mask(), self.fiscal_year)
     self.entry = EntryAccount.objects.create(
         year=self.fiscal_year, date_value=self.date, designation=self.__str__(),
         journal=Journal.objects.get(id=3), costaccounting=self.cost_accounting)
     EntryLineAccount.objects.create(
         account=third_account, amount=is_bill * self.get_total_incltax(), third=self.third, entry=self.entry)
     remise_total = 0
     detail_list = {}
     for detail in self.detail_set.all():
         if detail.article is not None:
             detail_code = detail.article.sell_account
         else:
             detail_code = Params.getvalue("invoice-default-sell-account")
         detail_account = ChartsAccount.get_account(
             detail_code, self.fiscal_year)
         if detail_account is None:
             raise LucteriosException(
                 IMPORTANT, _("article has code account unknown!"))
         if detail_account.id not in detail_list.keys():
             detail_list[detail_account.id] = [detail_account, 0]
         detail_list[detail_account.id][
             1] += detail.get_total_excltax() + detail.get_reduce_excltax()
         remise_total += detail.get_reduce_excltax()
     if remise_total > 0.001:
         remise_code = Params.getvalue("invoice-reduce-account")
         remise_account = ChartsAccount.get_account(
             remise_code, self.fiscal_year)
         if remise_account is None:
             raise LucteriosException(
                 IMPORTANT, _("reduce-account is not defined!"))
         EntryLineAccount.objects.create(
             account=remise_account, amount=-1 * is_bill * remise_total, entry=self.entry)
     for detail_item in detail_list.values():
         EntryLineAccount.objects.create(
             account=detail_item[0], amount=is_bill * detail_item[1], entry=self.entry)
     if self.get_vta_sum() > 0.001:
         vta_code = Params.getvalue("invoice-vatsell-account")
         vta_account = ChartsAccount.get_account(
             vta_code, self.fiscal_year)
         if vta_account is None:
             raise LucteriosException(
                 IMPORTANT, _("vta-account is not defined!"))
         EntryLineAccount.objects.create(
             account=vta_account, amount=is_bill * self.get_vta_sum(), entry=self.entry)
     no_change, debit_rest, credit_rest = self.entry.serial_control(
         self.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))
예제 #3
0
 def _generate_account_callfunds_by_type(self, new_entry, type_call,
                                         calldetails):
     detail_account_filter = None
     if type_call == 0:
         detail_account_filter = Params.getvalue(
             "condominium-current-revenue-account")
     if type_call == 1:
         detail_account_filter = Params.getvalue(
             "condominium-exceptional-revenue-account")
     if type_call == 2:
         detail_account_filter = Params.getvalue(
             "condominium-advance-revenue-account")
     if type_call == 4:
         detail_account_filter = Params.getvalue(
             "condominium-fundforworks-revenue-account")
     detail_account = ChartsAccount.get_account(detail_account_filter,
                                                new_entry.year)
     if detail_account is None:
         raise LucteriosException(IMPORTANT,
                                  _("incorrect account for call of found"))
     total = 0
     for calldetail in calldetails:
         EntryLineAccount.objects.create(
             account=detail_account,
             amount=calldetail.price,
             entry=new_entry,
             costaccounting=calldetail.set.current_cost_accounting)
         total += calldetail.price
         calldetail.entry = new_entry
         calldetail.save()
     return total
예제 #4
0
def conf_wizard_accounting(wizard_ident, xfer):
    if isinstance(wizard_ident, list) and (xfer is None):
        wizard_ident.append(("accounting_params", 21))
        wizard_ident.append(("accounting_fiscalyear", 22))
        wizard_ident.append(("accounting_journal", 23))
    elif (xfer is not None) and (wizard_ident == "accounting_params"):
        xfer.add_title(_("Diacamma accounting"), _('Parameters'), _('Configuration of accounting parameters'))
        select_account_system(xfer)
        fill_params(xfer, True)
    elif (xfer is not None) and (wizard_ident == "accounting_fiscalyear"):
        xfer.add_title(_("Diacamma accounting"), _('Fiscal year list'), _('Configuration of fiscal years'))
        xfer.fill_grid(5, FiscalYear, 'fiscalyear', FiscalYear.objects.all())
        try:
            current_year = FiscalYear.get_current()
            nb_account = len(ChartsAccount.objects.filter(year=current_year))
            lbl = XferCompLabelForm('nb_account')
            lbl.set_value(_("Total of charts of accounts in current fiscal year: %d") % nb_account)
            lbl.set_location(0, 10)
            xfer.add_component(lbl)
            if nb_account == 0:
                xfer.item = ChartsAccount()
                xfer.item.year = current_year
                btn = XferCompButton('initialfiscalyear')
                btn.set_location(1, 10)
                btn.set_action(xfer.request, ActionsManage.get_action_url(ChartsAccount.get_long_name(), 'AccountInitial', xfer), close=CLOSE_NO)
                xfer.add_component(btn)
        except LucteriosException as lerr:
            lbl = XferCompLabelForm('nb_account')
            lbl.set_value(six.text_type(lerr))
            lbl.set_location(0, 10, 2)
            xfer.add_component(lbl)
    elif (xfer is not None) and (wizard_ident == "accounting_journal"):
        xfer.add_title(_("Diacamma accounting"), _('Journals'), _('Configuration of journals'))
        xfer.fill_grid(5, Journal, 'journal', Journal.objects.all())
예제 #5
0
 def get_info_state(self):
     info = []
     if self.status == 0:
         info = Supporting.get_info_state(
             self, current_system_account().get_customer_mask())
     details = self.detail_set.all()
     if len(details) == 0:
         info.append(six.text_type(_("no detail")))
     else:
         for detail in details:
             if detail.article is not None:
                 detail_code = detail.article.sell_account
             else:
                 detail_code = Params.getvalue(
                     "invoice-default-sell-account")
             detail_account = None
             if match(current_system_account().get_revenue_mask(), detail_code) is not None:
                 try:
                     detail_account = ChartsAccount.get_account(
                         detail_code, FiscalYear.get_current())
                 except LucteriosException:
                     break
             if detail_account is None:
                 info.append(
                     six.text_type(_("article has code account unknown!")))
                 break
     try:
         info.extend(self.check_date(self.date.isoformat()))
     except LucteriosException:
         pass
     return "{[br/]}".join(info)
예제 #6
0
 def generate_accounting(self, third_amounts, designation=None):
     supporting = self.supporting.get_final_child()
     if self.supporting.is_revenu:
         is_revenu = -1
     else:
         is_revenu = 1
     fiscal_year = FiscalYear.get_current()
     if designation is None:
         designation = _("payoff for %s") % six.text_type(supporting)
     new_entry = EntryAccount.objects.create(
         year=fiscal_year, date_value=self.date, designation=designation,
         journal=Journal.objects.get(id=4), costaccounting=supporting.default_costaccounting())
     amount_to_bank = 0
     for third, amount in third_amounts:
         third_account = third.get_account(fiscal_year, supporting.get_third_mask())
         if third_account.type_of_account == 0:
             is_liability = 1
         else:
             is_liability = -1
         EntryLineAccount.objects.create(account=third_account, amount=is_liability * is_revenu * amount, third=third, entry=new_entry)
         amount_to_bank += float(amount)
     if self.bank_account is None:
         bank_code = Params.getvalue("payoff-cash-account")
     else:
         bank_code = self.bank_account.account_code
     bank_account = ChartsAccount.get_account(bank_code, fiscal_year)
     if bank_account is None:
         raise LucteriosException(
             IMPORTANT, _("account is not defined!"))
     fee_code = Params.getvalue("payoff-bankcharges-account")
     if (fee_code != '') and (float(self.bank_fee) > 0.001):
         fee_account = ChartsAccount.get_account(fee_code, fiscal_year)
         if fee_account is not None:
             EntryLineAccount.objects.create(account=fee_account,
                                             amount=-1 * is_revenu * float(self.bank_fee), entry=new_entry)
             amount_to_bank -= float(self.bank_fee)
     EntryLineAccount.objects.create(account=bank_account,
                                     amount=-1 * is_revenu * amount_to_bank, entry=new_entry)
     return new_entry
예제 #7
0
 def get_third_account(self, third_mask, fiscalyear, third=None):
     if third is None:
         third = self.third
     accounts = third.accountthird_set.filter(code__regex=third_mask)
     if len(accounts) == 0:
         raise LucteriosException(
             IMPORTANT, _("third has not correct account"))
     third_account = ChartsAccount.get_account(
         accounts[0].code, fiscalyear)
     if third_account is None:
         raise LucteriosException(
             IMPORTANT, _("third has not correct account"))
     return third_account
예제 #8
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()
예제 #9
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))
예제 #10
0
 def get_info_state(self, third_mask=None):
     info = []
     if third_mask is None:
         third_mask = self.get_third_mask()
     if self.status == 0:
         if self.third is None:
             info.append(six.text_type(_("no third selected")))
         else:
             accounts = self.third.accountthird_set.filter(
                 code__regex=third_mask)
             try:
                 if (len(accounts) == 0) or (ChartsAccount.get_account(accounts[0].code, FiscalYear.get_current()) is None):
                     info.append(
                         six.text_type(_("third has not correct account")))
             except LucteriosException as err:
                 info.append(six.text_type(err))
     return info
예제 #11
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()
예제 #12
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()
예제 #13
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
예제 #14
0
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Lucterios.  If not, see <http://www.gnu.org/licenses/>.
"""

from __future__ import unicode_literals

from django.utils.translation import ugettext_lazy as _

from diacamma.accounting.models import ChartsAccount

name = _("listing")
kind = 0
modelname = ChartsAccount.get_long_name()
value = """210
297
10//%s//#code
25//%s//#name
15//%s//#last_year_total
15//%s//#current_total
15//%s//#current_validated
""" % (
    _("code"),
    _("name"),
    _("total of last year"),
    _("total current"),
    _("total validated"),
)
예제 #15
0
 def fillresponse(self, confirme):
     account_list = []
     signal_and_lock.Signal.call_signal("initial_account", account_list)
     if self.confirme(_('Do you want to import initial accounts?')):
         ChartsAccount.import_initial(FiscalYear.get_current(self.getparam('year')), account_list)
예제 #16
0
 def __init__(self, **kwargs):
     ObjectMerge.__init__(self, **kwargs)
     self.params['modelname'] = ChartsAccount.get_long_name()