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 @@ +