Skip to content

Commit

Permalink
[MIG] account_invoice_view_payment: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anusriNPS committed Nov 27, 2024
1 parent 352ca40 commit 61876fc
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 52 deletions.
10 changes: 5 additions & 5 deletions account_invoice_view_payment/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Account Invoice View Payment
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github
:target: https://github.com/OCA/account-invoicing/tree/15.0/account_invoice_view_payment
:target: https://github.com/OCA/account-invoicing/tree/16.0/account_invoice_view_payment
:alt: OCA/account-invoicing
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-invoicing-15-0/account-invoicing-15-0-account_invoice_view_payment
:target: https://translation.odoo-community.org/projects/account-invoicing-16-0/account-invoicing-16-0-account_invoice_view_payment
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -66,7 +66,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoicing/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_invoice_view_payment%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_invoice_view_payment%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -100,6 +100,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/account-invoicing <https://github.com/OCA/account-invoicing/tree/15.0/account_invoice_view_payment>`_ project on GitHub.
This module is part of the `OCA/account-invoicing <https://github.com/OCA/account-invoicing/tree/16.0/account_invoice_view_payment>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_invoice_view_payment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Account Invoice View Payment",
"summary": "Access to the payment from an invoice",
"version": "15.0.1.1.1",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"website": "https://github.com/OCA/account-invoicing",
"author": "ForgeFlow, " "Odoo Community Association (OCA)",
Expand Down
58 changes: 58 additions & 0 deletions account_invoice_view_payment/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,68 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import models
from odoo.tools import formatLang


class AccountMove(models.Model):
_inherit = "account.move"

def _get_reconciled_info_JSON_values(self):
self.ensure_one()
reconciled_vals = []
for move in self:
if move.state == "posted" and move.is_invoice(include_receipts=True):
reconciled_partials = move._get_all_reconciled_invoice_partials()
for reconciled_partial in reconciled_partials:
counterpart_line = reconciled_partial["aml"]

Check warning on line 19 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#L19

Added line #L19 was not covered by tests
if counterpart_line.move_id.ref:
reconciliation_ref = "%s (%s)" % (

Check warning on line 21 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#L21

Added line #L21 was not covered by tests
counterpart_line.move_id.name,
counterpart_line.move_id.ref,
)
else:
reconciliation_ref = counterpart_line.move_id.name

Check warning on line 26 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#L26

Added line #L26 was not covered by tests
if (
counterpart_line.amount_currency
and counterpart_line.currency_id
!= counterpart_line.company_id.currency_id
):
foreign_currency = counterpart_line.currency_id

Check warning on line 32 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#L32

Added line #L32 was not covered by tests
else:
foreign_currency = False

Check warning on line 34 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#L34

Added line #L34 was not covered by tests

reconciled_vals.append(

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#L36

Added line #L36 was not covered by tests
{
"name": counterpart_line.name,
"journal_name": counterpart_line.journal_id.name,
"amount": reconciled_partial["amount"],
"currency_id": move.company_id.currency_id.id
if reconciled_partial["is_exchange"]
else reconciled_partial["currency"].id,
"date": counterpart_line.date,
"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, # noqa: B950
"move_id": counterpart_line.move_id.id,
"ref": reconciliation_ref,
# these are necessary for the views to change
# depending on the values
"is_exchange": reconciled_partial["is_exchange"],
"amount_company_currency": formatLang(
self.env,
abs(counterpart_line.balance),
currency_obj=counterpart_line.company_id.currency_id,
),
"amount_foreign_currency": foreign_currency
and formatLang(
self.env,
abs(counterpart_line.amount_currency),
currency_obj=foreign_currency,
),
}
)
return reconciled_vals

def action_view_payments(self):
"""
This function returns an action that display existing payments of given
Expand All @@ -22,6 +79,7 @@ def action_view_payments(self):
action = self.env["ir.actions.act_window"]._for_xml_id(

Check warning on line 79 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#L79

Added line #L79 was not covered by tests
"account.action_account_payments"
)
# import wdb; wdb.set_trace()
reconciles = self._get_reconciled_info_JSON_values()
payment = []
for rec in reconciles:
Expand Down
6 changes: 3 additions & 3 deletions account_invoice_view_payment/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Account Invoice View Payment</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0cca4874ac9c8da20233b28a13917e68e208348a2a0575f94b7bf241aa5bcea2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-invoicing/tree/15.0/account_invoice_view_payment"><img alt="OCA/account-invoicing" src="https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-invoicing-15-0/account-invoicing-15-0-account_invoice_view_payment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/account-invoicing/tree/16.0/account_invoice_view_payment"><img alt="OCA/account-invoicing" src="https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/account-invoicing-16-0/account-invoicing-16-0-account_invoice_view_payment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows users to access directly to the payment from an invoice
when registering a payment or afterwards.</p>
<p>The option to open the payment when it’s being registered is useful
Expand Down Expand Up @@ -413,7 +413,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-invoicing/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_invoice_view_payment%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_invoice_view_payment%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -443,7 +443,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-invoicing/tree/15.0/account_invoice_view_payment">OCA/account-invoicing</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-invoicing/tree/16.0/account_invoice_view_payment">OCA/account-invoicing</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,89 +6,113 @@
from odoo.tests.common import TransactionCase


# @tagged("post_install", "-at_install")
class TestAccountInvoiceViewPayment(TransactionCase):
"""
Tests for Account Invoice View Payment.
"""

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(
@classmethod
def setUpClass(cls):
super().setUpClass()
group_ids = cls.env.ref("account.group_account_invoice").ids
cls.test_user_1 = cls.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"]
self.inv_line_model = self.env["account.move.line"]
self.pay_model = self.env["account.payment"]
self.reg_pay_model = self.env["account.payment.register"]

self.cash = self.env["account.journal"].create(
cls.par_model = cls.env["res.partner"]
cls.acc_model = cls.env["account.account"]
cls.inv_model = cls.env["account.move"]
cls.inv_line_model = cls.env["account.move.line"]
cls.pay_model = cls.env["account.payment"]
cls.reg_pay_model = cls.env["account.payment.register"]

cls.cash = cls.env["account.journal"].create(
{"name": "Cash Test", "type": "cash", "code": "CT"}
)
self.payment_method_manual_in = self.env.ref(
cls.payment_method_manual_in = cls.env.ref(
"account.account_payment_method_manual_in"
)

self.partner1 = self._create_partner()

self.invoice_account = self.acc_model.search(
[
(
"user_type_id",
"=",
self.env.ref("account.data_account_type_revenue").id,
)
],
limit=1,
cls.default_line_account = cls.acc_model.create(
{
"name": "TESTACC",
"code": "TESTACC",
"account_type": "income",
"deprecated": False,
"company_id": cls.env.user.company_id.id,
}
)

self.invoice1 = self._create_invoice(self.partner1, "out_invoice")
self.invoice2 = self._create_invoice(self.partner1, "in_invoice")
self.invoice3 = self._create_invoice(self.partner1, "in_invoice")
self.invoice2.invoice_date = self.invoice3.invoice_date = fields.Date.today()
cls.inbound_payment_method_line = cls.cash.inbound_payment_method_line_ids[0]
cls.outbound_payment_method_line = cls.cash.outbound_payment_method_line_ids[0]

cls.partner = cls._create_partner()
cls.invoice1 = cls._create_invoice(cls.partner, "out_invoice")
cls.invoice2 = cls._create_invoice(cls.partner, "in_invoice")
cls.invoice3 = cls._create_invoice(cls.partner, "in_invoice")
cls.invoice2.invoice_date = cls.invoice3.invoice_date = fields.Date.today()

def _create_partner(self):
partner = self.par_model.create(
@classmethod
def _create_partner(cls):
partner = cls.par_model.create(
{"name": "Test Partner", "company_type": "company"}
)
return partner

def _create_invoice(self, partner, invoice_type):
inv_line = [
@classmethod
def _create_invoice(cls, partner, invoice_type):
cls.invoice_lines = [
(
0,
False,
{
"name": "Test section",
"display_type": "line_section",
},
),
(
0,
False,
{
"product_id": self.env.ref("product.product_product_8").id,
"name": "Test Invoice Line",
"account_id": self.invoice_account.id,
"name": "Test description #1",
"account_id": cls.default_line_account.id,
"quantity": 1.0,
"price_unit": 3.0,
"price_unit": 100.0,
},
)
),
(
0,
False,
{
"name": "Test description #2",
"account_id": cls.default_line_account.id,
"quantity": 2.0,
"price_unit": 25.0,
},
),
]
invoice = self.inv_model.create(
cls.invoice = cls.env["account.move"].create(
{
"partner_id": partner.id,
"partner_id": cls.partner.id,
"move_type": invoice_type,
"invoice_line_ids": inv_line,
"invoice_line_ids": cls.invoice_lines,
}
)
return invoice
return cls.invoice

def test_account_move_view_payment_out_invoice(self):
self.invoice1.action_post()
wiz = (
self.pay_model.with_user(self.test_user_1)
self.env["account.payment"]
.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",
"payment_method_line_id": self.inbound_payment_method_line.id,
}
)
)
Expand All @@ -102,7 +126,7 @@ def test_account_move_view_payment_out_invoice(self):
"There was an error and the view couldn't be opened.",
)

view_payment = self.invoice1.action_view_payments()
view_payment = self.invoice.action_view_payments()

expect1 = {"type": "ir.actions.act_window", "res_model": "account.payment"}
self.assertDictEqual(
Expand All @@ -122,6 +146,7 @@ def test_account_move_view_payment_in_invoice(self):
"payment_method_id": self.payment_method_manual_in.id,
"amount": self.invoice2.amount_residual,
"payment_type": "inbound",
"payment_method_line_id": self.inbound_payment_method_line.id,
}
)
)
Expand Down

0 comments on commit 61876fc

Please sign in to comment.