diff --git a/account_invoice_view_payment/models/account_move.py b/account_invoice_view_payment/models/account_move.py index beb35f8541e..b2432677884 100644 --- a/account_invoice_view_payment/models/account_move.py +++ b/account_invoice_view_payment/models/account_move.py @@ -15,10 +15,13 @@ def action_view_payments(self): When only one found, show the payment immediately. """ if self.move_type in ("in_invoice", "in_refund"): - action = self.env.ref("account.action_account_payments_payable") + action = self.env["ir.actions.act_window"]._for_xml_id( + "account.action_account_payments_payable" + ) else: - action = self.env.ref("account.action_account_payments") - result = action.read()[0] + action = self.env["ir.actions.act_window"]._for_xml_id( + "account.action_account_payments" + ) reconciles = self._get_reconciled_info_JSON_values() payment = [] for rec in reconciles: @@ -26,9 +29,9 @@ def action_view_payments(self): # choose the view_mode accordingly if len(reconciles) != 1: - result["domain"] = "[('id', 'in', " + str(payment) + ")]" + action["domain"] = "[('id', 'in', " + str(payment) + ")]" else: res = self.env.ref("account.view_account_payment_form", False) - result["views"] = [(res and res.id or False, "form")] - result["res_id"] = payment and payment[0] or False - return result + action["views"] = [(res and res.id or False, "form")] + action["res_id"] = payment and payment[0] or False + return action diff --git a/account_invoice_view_payment/tests/test_account_invoice_view_payment.py b/account_invoice_view_payment/tests/test_account_invoice_view_payment.py index 5d6fdbd6172..f265ce6b150 100644 --- a/account_invoice_view_payment/tests/test_account_invoice_view_payment.py +++ b/account_invoice_view_payment/tests/test_account_invoice_view_payment.py @@ -13,6 +13,10 @@ class TestAccountInvoiceViewPayment(TransactionCase): def setUp(self): super(TestAccountInvoiceViewPayment, self).setUp() + group_ids = self.env.ref("account.group_account_invoice").ids + self.test_user_1 = self.env["res.users"].create( + {"name": "John", "login": "test1", "groups_id": [(6, 0, group_ids)]} + ) self.par_model = self.env["res.partner"] self.acc_model = self.env["account.account"] self.inv_model = self.env["account.move"] @@ -76,15 +80,17 @@ def _create_invoice(self, partner, invoice_type): def test_account_move_view_payment_out_invoice(self): self.invoice1.action_post() - wiz = self.pay_model.with_context( - active_id=[self.invoice1.id], active_model="account.move" - ).create( - { - "journal_id": self.cash.id, - "payment_method_id": self.payment_method_manual_in.id, - "amount": self.invoice1.amount_residual, - "payment_type": "inbound", - } + wiz = ( + self.pay_model.with_user(self.test_user_1) + .with_context(active_id=[self.invoice1.id], active_model="account.move") + .create( + { + "journal_id": self.cash.id, + "payment_method_id": self.payment_method_manual_in.id, + "amount": self.invoice1.amount_residual, + "payment_type": "inbound", + } + ) ) res = wiz.post_and_open_payment() @@ -107,15 +113,17 @@ def test_account_move_view_payment_out_invoice(self): def test_account_move_view_payment_in_invoice(self): self.invoice2.action_post() - wiz = self.pay_model.with_context( - active_id=[self.invoice2.id], active_model="account.move" - ).create( - { - "journal_id": self.cash.id, - "payment_method_id": self.payment_method_manual_in.id, - "amount": self.invoice2.amount_residual, - "payment_type": "inbound", - } + wiz = ( + self.pay_model.with_user(self.test_user_1) + .with_context(active_id=[self.invoice2.id], active_model="account.move") + .create( + { + "journal_id": self.cash.id, + "payment_method_id": self.payment_method_manual_in.id, + "amount": self.invoice2.amount_residual, + "payment_type": "inbound", + } + ) ) res = wiz.post_and_open_payment() @@ -127,7 +135,7 @@ def test_account_move_view_payment_in_invoice(self): "There was an error and the view couldn't be opened.", ) - view_payment = self.invoice2.action_view_payments() + view_payment = self.invoice2.with_user(self.test_user_1).action_view_payments() expect1 = {"type": "ir.actions.act_window", "res_model": "account.payment"} self.assertDictEqual( expect1, @@ -138,12 +146,17 @@ def test_account_move_view_payment_in_invoice(self): def test_view_account_payment_register_form(self): self.invoice2.action_post() self.invoice3.action_post() - wiz = self.reg_pay_model.with_context( - active_ids=[self.invoice2.id, self.invoice3.id], active_model="account.move" - ).create( - { - "journal_id": self.cash.id, - } + wiz = ( + self.reg_pay_model.with_user(self.test_user_1) + .with_context( + active_ids=[self.invoice2.id, self.invoice3.id], + active_model="account.move", + ) + .create( + { + "journal_id": self.cash.id, + } + ) ) res = wiz.action_create_payments()