From 157ae1c708f83061aed5db24de44e3d85266908d Mon Sep 17 00:00:00 2001 From: "Pierrot (prro)" Date: Tue, 19 Jul 2022 13:51:07 +0000 Subject: [PATCH] [IMP] account: improve invoice UX and bank addition When using the wizard to add a bank account, it should be added to an existing journal only if the journal has no bank account set and no journal entries. We also want to be able to remove a set bank account. When using the wizard to add a bank account (Create it button ; not Connect button), it should be added to an existing journal only if the journal has no bank account set and no journal entries. We remove an unwanted constraint on the bank journals that prevented the removal of an Account Number (IBAN). Some UX changes. In the Journal Items list view, specific views open depending on their move type. This commit also changes the "View" button of the invoice payment widget on the Journal Entry's form view in order to align behaviours. The core open_move method is also moved from the account move line model to the account move's one for more flexibility. The "1 Statement" button of the payment's form view now links to the new reconciliation widget. The Journal Items lists accessed from the Journal report now show the partner by default. The "Unreconciled" filter now filter out partial reconciliations which have a residual amount != 0. The Partner column should almost always be shown by default in a Journal Items list view. task-2893208 closes odoo/odoo#94923 Related: odoo/enterprise#29092 Signed-off-by: Florian Gilbert (flg) --- addons/account/models/account_journal.py | 4 +-- addons/account/models/account_move.py | 31 ++++++++----------- .../static/src/js/account_payment_field.js | 28 +++++------------ .../static/src/xml/account_payment.xml | 2 +- .../tests/account_payment_field_tests.js | 30 +++++++----------- addons/account/views/account_move_views.xml | 25 +++++---------- addons/account/wizard/setup_wizards.py | 7 +++-- 7 files changed, 47 insertions(+), 80 deletions(-) diff --git a/addons/account/models/account_journal.py b/addons/account/models/account_journal.py index a924f6a76f1..a3997c3593f 100644 --- a/addons/account/models/account_journal.py +++ b/addons/account/models/account_journal.py @@ -538,9 +538,7 @@ class AccountJournal(models.Model): if journal.bank_account_id: journal.bank_account_id.currency_id = vals['currency_id'] if 'bank_account_id' in vals: - if not vals.get('bank_account_id'): - raise UserError(_('You cannot remove the bank account from the journal once set.')) - else: + if vals.get('bank_account_id'): bank_account = self.env['res.partner.bank'].browse(vals['bank_account_id']) if bank_account.partner_id != company.partner_id: raise UserError(_("The partners of the journal's company and the related bank account mismatch.")) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index ade9543db25..ba6750ac563 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1818,7 +1818,6 @@ class AccountMove(models.Model): 'digits': [69, reconciled_partial['currency'].decimal_places], 'position': reconciled_partial['currency'].position, 'date': counterpart_line.date, - 'payment_id': counterpart_line.id, 'partial_id': reconciled_partial['partial_id'], 'account_payment_id': counterpart_line.payment_id.id, 'payment_method_name': counterpart_line.payment_id.payment_method_line_id.name, @@ -2946,6 +2945,18 @@ class AccountMove(models.Model): 'views': [(self.env.ref('account.view_move_tree').id, 'tree'), (False, 'form')], } + def open_move(self): + if self.payment_id: + return self.open_payment_view() + else: + return { + 'type': 'ir.actions.act_window', + 'res_model': 'account.move', + 'view_mode': 'form', + 'res_id': self.id, + 'views': [(False, 'form')], + } + def post(self): warnings.warn( "RedirectWarning method 'post()' is a deprecated alias to 'action_post()' or _post()", @@ -6068,23 +6079,7 @@ class AccountMoveLine(models.Model): return action def open_move(self): - if self.payment_id: - return { - 'type': 'ir.actions.act_window', - 'res_model': 'account.payment', - 'view_mode': 'form', - 'res_id': self.payment_id.id, - 'views': [(False, 'form')], - } - else: - return { - 'type': 'ir.actions.act_window', - 'res_model': 'account.move', - 'view_mode': 'form', - 'res_id': self.move_id.id, - 'views': [(False, 'form')], - } - + return self.move_id.open_move() def action_automatic_entry(self): action = self.env['ir.actions.act_window']._for_xml_id('account.account_automatic_entry_wizard_action') diff --git a/addons/account/static/src/js/account_payment_field.js b/addons/account/static/src/js/account_payment_field.js index b4918655bc6..b66d90dcd29 100644 --- a/addons/account/static/src/js/account_payment_field.js +++ b/addons/account/static/src/js/account_payment_field.js @@ -88,28 +88,16 @@ var ShowPaymentLineWidget = AbstractField.extend({ * @param {MouseEvent} event */ _onOpenPaymentOrMove: function (event) { - var paymentId = parseInt($(event.target).attr('payment-id')); var moveId = parseInt($(event.target).attr('move-id')); - var resModel; - var id; - if (paymentId !== undefined && !isNaN(paymentId)){ - resModel = "account.payment"; - id = paymentId; - } else if (moveId !== undefined && !isNaN(moveId)){ - resModel = "account.move"; - id = moveId; - } - //Open form view of account.move with id = move_id - //viewAlreadyopened is a flag to prevent the user from clicking on another account.move/account.payment - //while the first one he clicked on is loading - if (!this.viewAlreadyOpened && resModel && id) { + if (!this.viewAlreadyOpened && moveId !== undefined && !isNaN(moveId)) { this.viewAlreadyOpened = true; - this.do_action({ - type: 'ir.actions.act_window', - res_model: resModel, - res_id: id, - views: [[false, 'form']], - target: 'current' + var self = this; + this._rpc({ + model: 'account.move', + method: 'open_move', + args: [moveId], + }).then(function (actionData) { + return self.do_action(actionData); }); } }, diff --git a/addons/account/static/src/xml/account_payment.xml b/addons/account/static/src/xml/account_payment.xml index 26b497f0f08..e2d1f280572 100644 --- a/addons/account/static/src/xml/account_payment.xml +++ b/addons/account/static/src/xml/account_payment.xml @@ -103,7 +103,7 @@ - + diff --git a/addons/account/static/tests/account_payment_field_tests.js b/addons/account/static/tests/account_payment_field_tests.js index 48609728edd..a233c6076ea 100644 --- a/addons/account/static/tests/account_payment_field_tests.js +++ b/addons/account/static/tests/account_payment_field_tests.js @@ -25,7 +25,7 @@ QUnit.module('account', { }, function () { QUnit.module('Reconciliation'); - QUnit.test('Reconciliation form field', async function (assert) { + QUnit.test('Reconciliation form field [REQUIRES FOCUS]', async function (assert) { assert.expect(5); var form = await createView({ @@ -46,37 +46,31 @@ QUnit.module('account', { assert.deepEqual(args.args, [4, 20], "should call js_assign_outstanding_line {warning: required focus}"); return Promise.resolve(); } + if (args.method === 'open_move') { + assert.deepEqual(args.args, [10], "should call open_move {warning: required focus}"); + return Promise.resolve(); + } return this._super.apply(this, arguments); }, - intercepts: { - do_action: function (event) { - assert.deepEqual(event.data.action, { - 'type': 'ir.actions.act_window', - 'res_model': 'account.move', - 'res_id': 10, - 'views': [[false, 'form']], - 'target': 'current' - }, - "should open the form view"); - }, - }, }); assert.strictEqual(form.$('.o_field_widget[name="payments_widget"]').text().replace(/[\s\n\r]+/g, ' '), " Paid on 04/25/2017 $ 555.00 ", "should display payment information"); - form.$('.o_field_widget[name="outstanding_credits_debits_widget"] .outstanding_credit_assign').trigger('click'); + await testUtils.dom.click(form.$('.o_field_widget[name="outstanding_credits_debits_widget"] .outstanding_credit_assign')); assert.strictEqual(form.$('.o_field_widget[name="outstanding_credits_debits_widget"]').text().replace(/[\s\n\r]+/g, ' '), " Outstanding credits Add INV/2017/0004 $ 100.00 ", "should display outstanding information"); - form.$('.o_field_widget[name="payments_widget"] .js_payment_info').trigger('focus'); - form.$('.popover .js_open_payment').trigger('click'); + form.$('.o_field_widget[name="payments_widget"] .js_payment_info').focus(); + await testUtils.nextTick(); + await testUtils.dom.click(form.$('.popover .js_open_payment')); - form.$('.o_field_widget[name="payments_widget"] .js_payment_info').trigger('focus'); - form.$('.popover .js_unreconcile_payment').trigger('click'); + form.$('.o_field_widget[name="payments_widget"] .js_payment_info').focus(); + await testUtils.nextTick(); + await testUtils.dom.click(form.$('.popover .js_unreconcile_payment')); form.destroy(); }); diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml index b52fcbf2a69..e553c210bde 100644 --- a/addons/account/views/account_move_views.xml +++ b/addons/account/views/account_move_views.xml @@ -166,9 +166,9 @@ - + - + @@ -184,8 +184,8 @@ - - + + @@ -194,6 +194,7 @@ +