Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FIX] account_invoice_view_payment: fix permissions issue when accessing to view payments from invoice #1828

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions account_invoice_view_payment/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@
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:
payment.append(rec["account_payment_id"])

# 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

Check warning on line 36 in account_invoice_view_payment/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_view_payment/models/account_move.py#L35-L36

Added lines #L35 - L36 were not covered by tests
return action
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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,
Expand All @@ -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()
Expand Down
Loading