Skip to content

Commit

Permalink
Merge PR #1828 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by JordiBForgeFlow
  • Loading branch information
OCA-git-bot committed Nov 1, 2024
2 parents c0b253d + eabd43f commit 458753a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 32 deletions.
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 @@ 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:
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
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

0 comments on commit 458753a

Please sign in to comment.