def paramchange_condominium(params): if 'accounting-sizecode' in params: for set_item in Set.objects.all(): if set_item.revenue_account != correct_accounting_code(set_item.revenue_account): set_item.revenue_account = correct_accounting_code(set_item.revenue_account) set_item.save() for exp_item in ExpenseDetail.objects.filter(expense__status=0): if exp_item.expense_account != correct_accounting_code(exp_item.expense_account): exp_item.expense_account = correct_accounting_code(exp_item.expense_account) exp_item.save() accounts = ('condominium-default-owner-account', 'condominium-current-revenue-account', 'condominium-default-owner-account1', 'condominium-default-owner-account2', 'condominium-default-owner-account3', 'condominium-default-owner-account4', 'condominium-default-owner-account5', 'condominium-exceptional-revenue-account', 'condominium-fundforworks-revenue-account', 'condominium-exceptional-reserve-account', 'condominium-advance-reserve-account', 'condominium-fundforworks-reserve-account') for account_item in accounts: has_changed = False if (account_item in params) or ('accounting-sizecode' in params): Parameter.change_value(account_item, correct_accounting_code(Params.getvalue(account_item))) system_condo = current_system_condo() system_condo.owner_account_changed(account_item) has_changed = True if has_changed: Params.clear() if 'accounting-system' in params: clear_system_condo() system_condo = current_system_condo() system_condo.initialize_system()
def before_save(self, xfer): accounts = self.item.third.accountthird_set.filter(code__regex=current_system_account().get_societary_mask()) if len(accounts) == 0: if Params.getvalue("condominium-old-accounting"): AccountThird.objects.create(third=self.item.third, code=correct_accounting_code(Params.getvalue("condominium-default-owner-account"))) else: for num_account in range(1, 5): AccountThird.objects.create(third=self.item.third, code=correct_accounting_code(Params.getvalue("condominium-default-owner-account%d" % num_account))) return SupportingEditor.before_save(self, xfer)
def fillresponse(self, pkname='', new_account=''): contact_id = self.getparam(pkname) last_thirds = Third.objects.filter( contact__pk=contact_id) if len(last_thirds) > 0: self.item = last_thirds[0] else: self.item.contact = AbstractContact.objects.get(id=contact_id) self.item.status = 0 self.item.save() if new_account != '': old_account = self.item.accountthird_set.filter(code=correct_accounting_code(new_account)) if len(old_account) == 0: AccountThird.objects.create(third=self.item, code=correct_accounting_code(new_account)) self.redirect_action(ThirdShow.get_action(), params={'third': self.item.id})
def paramchange_payoff(params): if 'accounting-sizecode' in params: for bank in BankAccount.objects.all(): if bank.account_code != correct_accounting_code(bank.account_code): bank.account_code = correct_accounting_code(bank.account_code) bank.save() if ('payoff-cash-account' in params) or ('accounting-sizecode' in params): Parameter.change_value( 'payoff-cash-account', correct_accounting_code(Params.getvalue('payoff-cash-account'))) if ('payoff-bankcharges-account' in params) or ('accounting-sizecode' in params): pvalue = Params.getvalue('payoff-bankcharges-account') if pvalue != '': Parameter.change_value( 'payoff-bankcharges-account', correct_accounting_code(pvalue)) Params.clear()
def paramchange_invoice(params): invoice_params = ['invoice-default-sell-account', 'invoice-vatsell-account', 'invoice-reduce-account', 'invoice-account-third'] if 'accounting-sizecode' in params: for param_item in invoice_params: Parameter.change_value( param_item, correct_accounting_code(Params.getvalue(param_item))) Params.clear() for art in Article.objects.all(): if art.sell_account != correct_accounting_code(art.sell_account): art.sell_account = correct_accounting_code(art.sell_account) art.save() for invoice_param in invoice_params: if invoice_param in params: Parameter.change_value( invoice_param, correct_accounting_code(Params.getvalue(invoice_param)))
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
def fill_third_convert(self, dlg): lbl = XferCompLabelForm('tle_third') lbl.set_value(_('How do want to convert owner third account?')) lbl.set_location(0, 0, 2) dlg.add_component(lbl) select_account = [('', None)] for num_account in range(1, 6): owner_account = correct_accounting_code(Params.getvalue('condominium-default-owner-account%d' % num_account)) select_account.append((owner_account, owner_account)) row = 1 for code_item in AccountThird.objects.filter(code__regex=r"^45[0-9a-zA-Z]*$", third__status=0).values_list('code').distinct(): sel = XferCompSelect('code_' + code_item[0]) sel.set_location(0, row) sel.description = code_item[0] sel.set_value(dlg.getparam('code_' + code_item[0], "")) sel.set_select(select_account) dlg.add_component(sel) row += 1
def fillresponse(self): if self.getparam("CONVERT") is None: dlg = self.create_custom() img = XferCompImage('img') img.set_value(self.icon_path()) img.set_location(0, 0) dlg.add_component(img) lbl = XferCompLabelForm('title') lbl.set_value_as_title(self.caption) lbl.set_location(1, 0) dlg.add_component(lbl) year_list = ["{[i]} - %s{[/i]}" % year for year in FiscalYear.objects.filter(status__lt=2)] lab = XferCompLabelForm('info') lab.set_value( _("This conversion tool will change your account to respect French law about condominium.{[br/]}For the no-closed fiscal years:{[newline]}%s{[newline]}It will do:{[newline]} - To change accounting code for each owners.{[newline]} - To de-validate all your entity.{[br/]} - To delete all entity link to call of funds or expenses.{[br/]} - To de-archive call of funds or expenses.{[br/]} - To generate correct account for call of funds or expenses.{[br/]}{[center]}{[u]}{[b]}Warning: This action is definitive.{[/b]}{[/u]}{[center]}") % '{[br/]}'.join(year_list)) lab.set_location(0, 1, 4) dlg.add_component(lab) dlg.new_tab(_("Third accounts")) self.fill_third_convert(dlg) dlg.new_tab(_("Parameters")) fill_params(dlg, True, True) dlg.add_action(self.get_action(TITLE_OK, 'images/ok.png'), modal=FORMTYPE_MODAL, close=CLOSE_YES, params={'CONVERT': 'YES'}) dlg.add_action(WrapAction(TITLE_CANCEL, 'images/cancel.png')) else: Parameter.change_value('condominium-old-accounting', False) Params.clear() try: thirds_convert = self.get_thirds_convert() for set_cost in SetCost.objects.filter(year__status=2, cost_accounting__status=0): set_cost.cost_accounting.is_protected = True set_cost.cost_accounting.save() if (set_cost.year.status == 2) and (set_cost.cost_accounting.status == 0): set_cost.cost_accounting.close() for owner in Owner.objects.all(): for num_account in range(1, 5): AccountThird.objects.create(third=owner.third, code=correct_accounting_code(Params.getvalue("condominium-default-owner-account%d" % num_account))) for year in FiscalYear.objects.filter(status__lt=2): convert_accounting(year, thirds_convert) except: Params.clear() raise self.message(_("Data converted"))
def paramchange_accounting(params): if 'accounting-sizecode' in params: for account in AccountThird.objects.all(): if account.code != correct_accounting_code(account.code): account.code = correct_accounting_code(account.code) account.save() for charts_account in ChartsAccount.objects.filter(year__status__in=(0, 1)): if charts_account.code != correct_accounting_code(charts_account.code): charts_account.code = correct_accounting_code( charts_account.code) charts_account.save() for model_line in ModelLineEntry.objects.all(): if model_line.code != correct_accounting_code(model_line.code): model_line.code = correct_accounting_code(model_line.code) model_line.save()
def fill_third_convert(self, dlg): lbl = XferCompLabelForm('tle_third') lbl.set_value(_('How do want to convert owner third account?')) lbl.set_location(0, 0, 2) dlg.add_component(lbl) select_account = [('', None)] for num_account in range(1, 5): owner_account = correct_accounting_code(Params.getvalue('condominium-default-owner-account%d' % num_account)) select_account.append((owner_account, owner_account)) row = 1 for code_item in AccountThird.objects.filter(code__regex=r"^45[0-9a-zA-Z]*$", third__status=0).values_list('code').distinct(): lbl = XferCompLabelForm('lbl_code_' + code_item[0]) lbl.set_value_as_name(code_item[0]) lbl.set_location(0, row) dlg.add_component(lbl) sel = XferCompSelect('code_' + code_item[0]) sel.set_location(1, row) sel.set_value(dlg.getparam('code_' + code_item[0], "")) sel.set_select(select_account) dlg.add_component(sel) row += 1
def initialize_system(self): Parameter.change_value('condominium-default-owner-account', correct_accounting_code('450')) Parameter.change_value('condominium-default-owner-account1', correct_accounting_code('4501')) Parameter.change_value('condominium-default-owner-account2', correct_accounting_code('4502')) Parameter.change_value('condominium-default-owner-account3', correct_accounting_code('4503')) Parameter.change_value('condominium-default-owner-account4', correct_accounting_code('4504')) Parameter.change_value('condominium-default-owner-account5', correct_accounting_code('4505')) Parameter.change_value('condominium-current-revenue-account', correct_accounting_code('701')) Parameter.change_value('condominium-exceptional-revenue-account', correct_accounting_code('702')) Parameter.change_value('condominium-fundforworks-revenue-account', correct_accounting_code('705')) Parameter.change_value('condominium-exceptional-reserve-account', correct_accounting_code('120')) Parameter.change_value('condominium-advance-reserve-account', correct_accounting_code('103')) Parameter.change_value('condominium-fundforworks-reserve-account', correct_accounting_code('105')) Parameter.change_value('condominium-mode-current-callfunds', 0) Params.clear()
def initialize_system(self): Parameter.change_value('accounting-sizecode', 6) Parameter.change_value('condominium-default-owner-account', correct_accounting_code('')) Parameter.change_value('condominium-default-owner-account1', correct_accounting_code('410100')) Parameter.change_value('condominium-default-owner-account2', correct_accounting_code('410000')) Parameter.change_value('condominium-default-owner-account3', correct_accounting_code('410100')) Parameter.change_value('condominium-default-owner-account4', correct_accounting_code('')) Parameter.change_value('condominium-default-owner-account5', correct_accounting_code('410000')) Parameter.change_value('condominium-current-revenue-account', correct_accounting_code('701100')) Parameter.change_value('condominium-exceptional-revenue-account', correct_accounting_code('700100')) Parameter.change_value('condominium-advance-revenue-account', correct_accounting_code('701200')) Parameter.change_value('condominium-fundforworks-revenue-account', correct_accounting_code('700000')) Parameter.change_value('condominium-exceptional-reserve-account', correct_accounting_code('160000')) Parameter.change_value('condominium-advance-reserve-account', correct_accounting_code('100000')) Parameter.change_value('condominium-fundforworks-reserve-account', correct_accounting_code('100000')) Parameter.change_value('condominium-mode-current-callfunds', 1) Params.clear() CustomField.objects.get_or_create(modelname='accounting.Third', name='IBAN', kind=0, args="{'multi': False}") CustomField.objects.get_or_create(modelname='accounting.Third', name='SWIFT', kind=0, args="{'multi': False}")
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): self.account_code = correct_accounting_code(self.account_code) return LucteriosModel.save(self, force_insert=force_insert, force_update=force_update, using=using, update_fields=update_fields)