From b30fed7a7bd9a26406c23b7ef19590df50be6c06 Mon Sep 17 00:00:00 2001 From: Olivier Colson Date: Fri, 8 Jun 2018 17:48:03 +0200 Subject: [PATCH] [IMP] account: facilitate bank account and bank journal config With this change, * some modules are now set to be automatically installed by default * the setup bar of accounting has been changed in order to allow more easiliy the configuration of bank accounts/journals (and the step to oversee the opening entry has been removed) * the kanban view in the dashboard has been enhanced (mostly for bank journals, but not only) Was task: 32668 Was PR #23049 --- addons/account/__init__.py | 3 +- addons/account/models/account.py | 45 +++++---- .../models/account_journal_dashboard.py | 1 - addons/account/models/account_move.py | 9 +- addons/account/models/company.py | 27 ++--- .../src/js/account_dashboard_setup_bar.js | 8 ++ .../src/xml/account_dashboard_setup_bar.xml | 7 +- addons/account/tests/__init__.py | 1 - addons/account/tests/test_setup_bar.py | 77 --------------- .../views/account_journal_dashboard_view.xml | 16 ++- addons/account/views/account_view.xml | 40 ++++---- addons/account/wizard/setup_wizards.py | 98 +++++++++++-------- addons/account/wizard/setup_wizards_view.xml | 96 +++++------------- .../account_bank_statement_import_view.xml | 18 ++-- .../account_journal.py | 16 ++- .../wizard/__init__.py | 1 + .../wizard/setup_wizards.py | 14 +++ addons/base_iban/models/res_partner_bank.py | 17 ++-- .../views/account_journal_dashboard.xml | 2 +- addons/l10n_ch/models/res_bank.py | 22 +++-- odoo/addons/base/models/res_bank.py | 22 ++++- .../test_main_flows/static/src/js/tour.js | 45 ++++++++- 22 files changed, 280 insertions(+), 305 deletions(-) delete mode 100644 addons/account/tests/test_setup_bar.py create mode 100644 addons/account_bank_statement_import/wizard/setup_wizards.py diff --git a/addons/account/__init__.py b/addons/account/__init__.py index 46a5df4eaa9..5c2e72f503c 100644 --- a/addons/account/__init__.py +++ b/addons/account/__init__.py @@ -42,7 +42,7 @@ def _auto_install_l10n(cr, registry): if country_code in ['US', 'AU', 'NZ', 'CA', 'CO', 'EC', 'ES', 'FR', 'IN', 'MX', 'UK']: module_list.append('account_yodlee') if country_code in SYSCOHADA_LIST + [ - 'AT', 'BE', 'CA', 'CO', 'DE', 'EC', 'ES', 'ET', 'FR', 'GR', 'IT', 'LU', 'MX', 'NL', 'NO', + 'AT', 'BE', 'CA', 'CO', 'DE', 'EC', 'ES', 'ET', 'FR', 'GR', 'IT', 'LU', 'MX', 'NL', 'NO', 'PL', 'PT', 'RO', 'SI', 'TR', 'UK', 'VE', 'VN' ]: module_list.append('base_vat') @@ -53,5 +53,6 @@ def _auto_install_l10n(cr, registry): europe_country_codes = [x.code for x in europe.country_ids] if country_code in europe_country_codes: module_list.append('account_sepa') + module_list.append('account_bank_statement_import_camt') module_ids = env['ir.module.module'].search([('name', 'in', module_list), ('state', '=', 'uninstalled')]) module_ids.sudo().button_install() diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 75dbc29b6d4..e8fdcb36466 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -358,6 +358,12 @@ class AccountJournal(models.Model): def _default_outbound_payment_methods(self): return self.env.ref('account.account_payment_method_manual_out') + def __get_bank_statements_available_sources(self): + return [('undefined', _('Undefined Yet'))] + + def _get_bank_statements_available_sources(self): + return self.__get_bank_statements_available_sources() + name = fields.Char(string='Journal Name', required=True) code = fields.Char(string='Short Code', size=5, required=True, help="The journal entries of this journal will be named using this prefix.") active = fields.Boolean(default=True, help="Set active to false to hide the Journal without removing it.") @@ -405,12 +411,12 @@ class AccountJournal(models.Model): refund_sequence = fields.Boolean(string='Dedicated Credit Note Sequence', help="Check this box if you don't want to share the same sequence for invoices and credit notes made from this journal", default=False) inbound_payment_method_ids = fields.Many2many('account.payment.method', 'account_journal_inbound_payment_method_rel', 'journal_id', 'inbound_payment_method', - domain=[('payment_type', '=', 'inbound')], string='Debit Methods', default=lambda self: self._default_inbound_payment_methods(), + domain=[('payment_type', '=', 'inbound')], string='For Incoming Payments', default=lambda self: self._default_inbound_payment_methods(), help="Manual: Get paid by cash, check or any other method outside of Odoo.\n"\ "Electronic: Get paid automatically through a payment acquirer by requesting a transaction on a card saved by the customer when buying or subscribing online (payment token).\n"\ "Batch Deposit: Encase several customer checks at once by generating a batch deposit to submit to your bank. When encoding the bank statement in Odoo,you are suggested to reconcile the transaction with the batch deposit. Enable this option from the settings.") outbound_payment_method_ids = fields.Many2many('account.payment.method', 'account_journal_outbound_payment_method_rel', 'journal_id', 'outbound_payment_method', - domain=[('payment_type', '=', 'outbound')], string='Payment Methods', default=lambda self: self._default_outbound_payment_methods(), + domain=[('payment_type', '=', 'outbound')], string='For Outgoing Payments', default=lambda self: self._default_outbound_payment_methods(), help="Manual:Pay bill by cash or any other method outside of Odoo.\n"\ "Check:Pay bill by check and print it from Odoo.\n"\ "SEPA Credit Transfer: Pay bill from a SEPA Credit Transfer file you submit to your bank. Enable this option from the settings.") @@ -424,7 +430,7 @@ class AccountJournal(models.Model): # Bank journals fields company_partner_id = fields.Many2one('res.partner', related='company_id.partner_id', string='Account Holder', readonly=True, store=False) bank_account_id = fields.Many2one('res.partner.bank', string="Bank Account", ondelete='restrict', copy=False, domain="[('partner_id','=', company_partner_id)]") - bank_statements_source = fields.Selection([('undefined', 'Undefined'),('manual', 'Record Manually')], string='Bank Feeds', default='undefined') + bank_statements_source = fields.Selection(selection=_get_bank_statements_available_sources, string='Bank Feeds', default='undefined', help="Defines how the bank statements will be registered") bank_acc_number = fields.Char(related='bank_account_id.acc_number') bank_id = fields.Many2one('res.bank', related='bank_account_id.bank_id') @@ -681,6 +687,16 @@ class AccountJournal(models.Model): 'company_id': company.id, } + @api.model + def get_next_bank_cash_default_code(self, journal_type, company_id): + journal_code_base = (journal_type == 'cash' and 'CSH' or 'BNK') + journals = self.env['account.journal'].search([('code', 'like', journal_code_base + '%'), ('company_id', '=', company_id)]) + for num in range(1, 100): + # journal_code has a maximal size of 5, hence we can enforce the boundary num < 100 + journal_code = journal_code_base + str(num) + if journal_code not in journals.mapped('code'): + return journal_code + @api.model def create(self, vals): company_id = vals.get('company_id', self.env.user.company_id.id) @@ -691,15 +707,8 @@ class AccountJournal(models.Model): # If no code provided, loop to find next available journal code if not vals.get('code'): - journal_code_base = (vals['type'] == 'cash' and 'CSH' or 'BNK') - journals = self.env['account.journal'].search([('code', 'like', journal_code_base + '%'), ('company_id', '=', company_id)]) - for num in range(1, 100): - # journal_code has a maximal size of 5, hence we can enforce the boundary num < 100 - journal_code = journal_code_base + str(num) - if journal_code not in journals.mapped('code'): - vals['code'] = journal_code - break - else: + vals['code'] = self.get_next_bank_cash_default_code(vals['type'], company_id) + if not vals['code']: raise UserError(_("Cannot generate an unused journal code. Please fill the 'Shortcode' field.")) # Create a default debit/credit account if not given @@ -780,14 +789,12 @@ class AccountJournal(models.Model): journal.at_least_one_inbound = bool(len(journal.inbound_payment_method_ids)) journal.at_least_one_outbound = bool(len(journal.outbound_payment_method_ids)) - def setup_save_journal_and_create_more(self): - """ This function is triggered by the button allowing to create more - bank accounts, displayed in the "Bank Accounts" wizard of the setup bar. - - Button execution is done in Python, so that the model is validated and saved - before executing the action. + def action_configure_bank_journal(self): + """ This function is called by the "configure" button of bank journals, + visible on dashboard if no bank statement source has been defined yet """ - return self.env.ref('account.action_account_bank_journal_form').read()[0] + # We simply call the setup bar function. + return self.env['res.company'].setting_init_bank_account_action() class ResPartnerBank(models.Model): diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py index af8e26b27ab..38483053dd4 100644 --- a/addons/account/models/account_journal_dashboard.py +++ b/addons/account/models/account_journal_dashboard.py @@ -411,7 +411,6 @@ class account_journal(models.Model): @api.multi def create_bank_statement(self): """return action to create a bank statements. This button should be called only on journals with type =='bank'""" - self.bank_statements_source = 'manual' action = self.env.ref('account.action_bank_statement_tree').read()[0] action.update({ 'views': [[False, 'form']], diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index d2e555dcdbc..d9cba8c87ba 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -622,9 +622,6 @@ class AccountMoveLine(models.Model): help="Technical field used to mark a tax line as exigible in the vat report or not (only exigible journal items are displayed). By default all new journal items are directly exigible, but with the feature cash_basis on taxes, some will become exigible only when the payment is recorded.") parent_state = fields.Char(compute="_compute_parent_state", help="State of the parent account.move") - #Needed for setup, as a decoration attribute needs to know that for a tree view in one of the popups, and there's no way to reference directly a xml id from there - is_unaffected_earnings_line = fields.Boolean(string="Is Unaffected Earnings Line", compute="_compute_is_unaffected_earnings_line", help="Tells whether or not this line belongs to an unaffected earnings account") - recompute_tax_line = fields.Boolean(store=False, help="Technical field used to know if the tax_ids field has been modified in the UI.") tax_line_grouping_key = fields.Char(store=False, string='Old Taxes', help="Technical field used to store the old values of fields used to compute tax lines (in account.move form view) between the moment the user changed it and the moment the ORM reflects that change in its one2many") @@ -730,7 +727,7 @@ class AccountMoveLine(models.Model): multiple_currency = True else: currency = list(currency)[0] - # Get the sum(debit, credit, amount_currency) of all amls involved + # Get the sum(debit, credit, amount_currency) of all amls involved total_debit = 0 total_credit = 0 total_amount_currency = 0 @@ -802,7 +799,7 @@ class AccountMoveLine(models.Model): amount_reconcile = min(debit_move[field], -credit_move[field]) #Remove from recordset the one(s) that will be totally reconciled - # For optimization purpose, the creation of the partial_reconcile are done at the end, + # For optimization purpose, the creation of the partial_reconcile are done at the end, # therefore during the process of reconciling several move lines, there are actually no recompute performed by the orm # and thus the amount_residual are not recomputed, hence we have to do it manually. if amount_reconcile == debit_move[field]: @@ -836,7 +833,7 @@ class AccountMoveLine(models.Model): 'currency_id': currency, }) - part_rec = self.env['account.partial.reconcile'] + part_rec = self.env['account.partial.reconcile'] index = 0 with self.env.norecompute(): for partial_rec_dict in to_create: diff --git a/addons/account/models/company.py b/addons/account/models/company.py index 785e67e4719..2561f400821 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -246,27 +246,16 @@ Best Regards,''')) @api.model def setting_init_bank_account_action(self): """ Called by the 'Bank Accounts' button of the setup bar.""" - company = self.env.user.company_id - view_id = self.env.ref('account.setup_bank_journal_form').id - - res = { - 'type': 'ir.actions.act_window', - 'name': _('Bank Account'), - 'view_mode': 'form', - 'res_model': 'account.journal', - 'target': 'new', - 'views': [[view_id, 'form']], + view_id = self.env.ref('account.setup_bank_account_wizard').id + return {'type': 'ir.actions.act_window', + 'name': _('Create a Bank Account'), + 'res_model': 'account.setup.bank.manual.config', + 'target': 'new', + 'view_mode': 'form', + 'view_type': 'form', + 'views': [[view_id, 'form']], } - # If some bank journal already exists, we open it in the form, so the user can edit it. - # Otherwise, we just open the form in creation mode. - bank_journal = self.env['account.journal'].search([('company_id','=', company.id), ('type','=','bank')], limit=1) - if bank_journal: - res['res_id'] = bank_journal.id - else: - res['context'] = {'default_type': 'bank'} - return res - @api.model def setting_init_fiscal_year_action(self): """ Called by the 'Fiscal Year Opening' button of the setup bar.""" diff --git a/addons/account/static/src/js/account_dashboard_setup_bar.js b/addons/account/static/src/js/account_dashboard_setup_bar.js index 1af9416008f..17aa1bad174 100644 --- a/addons/account/static/src/js/account_dashboard_setup_bar.js +++ b/addons/account/static/src/js/account_dashboard_setup_bar.js @@ -160,6 +160,14 @@ var AccountSetupBarController = KanbanController.extend({ company_button_action: '_triggerCompanyButtonAction', }), + start: function () { + this._super(); + var self = this; + core.bus.on('refresh_account_dashboard', this, function (){ + self.trigger_up('reload') + }); + }, + //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- diff --git a/addons/account/static/src/xml/account_dashboard_setup_bar.xml b/addons/account/static/src/xml/account_dashboard_setup_bar.xml index 069927bf9ae..7666753f26b 100644 --- a/addons/account/static/src/xml/account_dashboard_setup_bar.xml +++ b/addons/account/static/src/xml/account_dashboard_setup_bar.xml @@ -5,11 +5,6 @@