Skip to content

Commit

Permalink
[MIG] account_reconcile_restrict_partner_mismatch: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestotejeda committed Nov 27, 2019
1 parent 00c2e52 commit 0b9bf6f
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 61 deletions.
17 changes: 12 additions & 5 deletions account_reconcile_restrict_partner_mismatch/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Reconcile restrict partner mismatch
: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--reconcile-lightgray.png?logo=github
:target: https://github.com/OCA/account-reconcile/tree/12.0/account_reconcile_restrict_partner_mismatch
:target: https://github.com/OCA/account-reconcile/tree/13.0/account_reconcile_restrict_partner_mismatch
:alt: OCA/account-reconcile
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-reconcile-12-0/account-reconcile-12-0-account_reconcile_restrict_partner_mismatch
:target: https://translation.odoo-community.org/projects/account-reconcile-13-0/account-reconcile-13-0-account_reconcile_restrict_partner_mismatch
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/98/12.0
:target: https://runbot.odoo-community.org/runbot/98/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -47,7 +47,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-reconcile/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_reconcile_restrict_partner_mismatch%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_reconcile_restrict_partner_mismatch%0Aversion:%2013.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 All @@ -59,6 +59,13 @@ Authors

* Camptocamp

Contributors
~~~~~~~~~~~~

* `Tecnativa <https://www.tecnativa.com>`_:

* Ernesto Tejeda

Maintainers
~~~~~~~~~~~

Expand All @@ -72,6 +79,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-reconcile <https://github.com/OCA/account-reconcile/tree/12.0/account_reconcile_restrict_partner_mismatch>`_ project on GitHub.
This module is part of the `OCA/account-reconcile <https://github.com/OCA/account-reconcile/tree/13.0/account_reconcile_restrict_partner_mismatch>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Empty file modified account_reconcile_restrict_partner_mismatch/__init__.py
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Reconcile restrict partner mismatch",
"summary": "Restrict reconciliation on receivable "
"and payable accounts to the same partner",
"version": "12.0.1.0.0",
"version": "13.0.1.0.0",
"depends": ["account"],
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "http://www.github.com/OCA/account-reconcile",
Expand Down
Empty file modified account_reconcile_restrict_partner_mismatch/models/__init__.py
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import _, api, models
from odoo import _, models
from odoo.exceptions import UserError
from odoo.tools import config


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

@api.multi
def reconcile(self, writeoff_acc_id=False, writeoff_journal_id=False):
if config["test_enable"] and not self.env.context.get("test_partner_mismatch"):
return super().reconcile(writeoff_acc_id, writeoff_journal_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Tecnativa <https://www.tecnativa.com>`_:

* Ernesto Tejeda
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).


from odoo import api, fields, models, tools
from odoo import fields, models, tools


class AccountReconcilePartnerMismatchReport(models.Model):
Expand All @@ -23,7 +23,6 @@ class AccountReconcilePartnerMismatchReport(models.Model):
credit_amount = fields.Float("Credit amount")
credit_partner_id = fields.Many2one("res.partner", string="Credit partner")

@api.model_cr
def init(self):
"""Select lines which violate defined rules"""
tools.drop_view_if_exists(self.env.cr, self._table)
Expand All @@ -45,8 +44,10 @@ def init(self):
ON daml.id = pr.debit_move_id
LEFT JOIN account_move_line caml
ON caml.id = pr.credit_move_id
LEFT JOIN account_account aa
ON daml.account_id = aa.id
LEFT JOIN account_account_type aat
ON daml.user_type_id = aat.id
ON aa.user_type_id = aat.id
WHERE aat.type in ('receivable', 'payable')
AND (daml.partner_id <> caml.partner_id
OR (daml.partner_id IS NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Reconcile restrict partner mismatch</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" 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" 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" href="https://github.com/OCA/account-reconcile/tree/12.0/account_reconcile_restrict_partner_mismatch"><img alt="OCA/account-reconcile" src="https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-reconcile-12-0/account-reconcile-12-0-account_reconcile_restrict_partner_mismatch"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/98/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" 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" 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" href="https://github.com/OCA/account-reconcile/tree/13.0/account_reconcile_restrict_partner_mismatch"><img alt="OCA/account-reconcile" src="https://img.shields.io/badge/github-OCA%2Faccount--reconcile-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-reconcile-13-0/account-reconcile-13-0-account_reconcile_restrict_partner_mismatch"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/98/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module restricts reconciliation between journal items when:</p>
<blockquote>
<ul class="simple">
Expand All @@ -385,7 +385,8 @@ <h1 class="title">Reconcile restrict partner mismatch</h1>
<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id3">Authors</a></li>
<li><a class="reference internal" href="#maintainers" id="id4">Maintainers</a></li>
<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id5">Maintainers</a></li>
</ul>
</li>
</ul>
Expand All @@ -395,7 +396,7 @@ <h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-reconcile/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 smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/account-reconcile/issues/new?body=module:%20account_reconcile_restrict_partner_mismatch%0Aversion:%2012.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-reconcile/issues/new?body=module:%20account_reconcile_restrict_partner_mismatch%0Aversion:%2013.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 All @@ -406,14 +407,23 @@ <h2><a class="toc-backref" href="#id3">Authors</a></h2>
<li>Camptocamp</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id4">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Ernesto Tejeda</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id4">Maintainers</a></h2>
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<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-reconcile/tree/12.0/account_reconcile_restrict_partner_mismatch">OCA/account-reconcile</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-reconcile/tree/13.0/account_reconcile_restrict_partner_mismatch">OCA/account-reconcile</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 @@ -2,67 +2,66 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.exceptions import UserError
from odoo.tests.common import SavepointCase

from odoo.addons.account.tests.account_test_classes import AccountingTestCase


class TestReconciliation(AccountingTestCase):
def setUp(self):
super().setUp()
self.env = self.env(
class TestReconciliation(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(
self.env.context, tracking_disable=True, test_partner_mismatch=True
cls.env.context, tracking_disable=True, test_partner_mismatch=True
)
)

self.partner = self.env.ref("base.res_partner_2")
self.partner_id = self.partner.id
rec_type = self.env["account.account"].search(
[
(
"user_type_id",
"=",
self.env.ref("account.data_account_type_receivable").id,
)
],
limit=1,
cls.partner = cls.env.ref("base.res_partner_2")
cls.partner_id = cls.partner.id
cls.account_rcv = cls.env["account.account"].create(
{
"code": "RA1000",
"name": "Test Receivable Account",
"user_type_id": cls.env.ref("account.data_account_type_receivable").id,
"reconcile": True,
}
)
pay_type = self.env["account.account"].search(
[
(
"user_type_id",
"=",
self.env.ref("account.data_account_type_payable").id,
)
],
limit=1,
cls.account_rsa = cls.env["account.account"].create(
{
"code": "PA1000",
"name": "Test Payable Account",
"user_type_id": cls.env.ref("account.data_account_type_payable").id,
"reconcile": True,
}
)
self.account_rcv = self.partner.property_account_receivable_id or rec_type
self.account_rsa = self.partner.property_account_payable_id or pay_type

self.bank_journal = self.env["account.journal"].create(
cls.bank_journal = cls.env["account.journal"].create(
{"name": "Bank", "type": "bank", "code": "BNK67"}
)
self.aml = self.init_moves()
cls.aml = cls.init_moves()

def create_move(self, name, amount):
@classmethod
def create_move(cls, name, amount):
debit_line_vals = {
"name": name,
"debit": amount > 0 and amount or 0.0,
"credit": amount < 0 and -amount or 0.0,
"account_id": self.account_rcv.id,
"account_id": cls.account_rcv.id,
}
credit_line_vals = debit_line_vals.copy()
credit_line_vals["debit"] = debit_line_vals["credit"]
credit_line_vals["credit"] = debit_line_vals["debit"]
credit_line_vals["account_id"] = self.account_rsa.id
credit_line_vals["account_id"] = cls.account_rsa.id
vals = {
"journal_id": self.bank_journal.id,
"journal_id": cls.bank_journal.id,
"line_ids": [(0, 0, debit_line_vals), (0, 0, credit_line_vals)],
}
return self.env["account.move"].create(vals).id
return (
cls.env["account.move"]
.with_context(default_journal_id=cls.bank_journal.id)
.create(vals)
.id
)

def init_moves(self):
@classmethod
def init_moves(cls):
move_list_vals = [
("1", -1.83),
("2", 728.35),
Expand All @@ -73,9 +72,9 @@ def init_moves(self):
]
move_ids = []
for name, amount in move_list_vals:
move_ids.append(self.create_move(name, amount))
aml_recs = self.env["account.move.line"].search(
[("move_id", "in", move_ids), ("account_id", "=", self.account_rcv.id)]
move_ids.append(cls.create_move(name, amount))
aml_recs = cls.env["account.move.line"].search(
[("move_id", "in", move_ids), ("account_id", "=", cls.account_rcv.id)]
)
return aml_recs

Expand All @@ -97,10 +96,16 @@ def test_reconcile_accounts_excluded(self):
with self.assertRaises(UserError):
self.aml.reconcile()
# reconciliation forbiden only for certain types of accounts
account = self.env["account.account"].search(
[("user_type_id.type", "=", "other")], limit=1
account = self.env["account.account"].create(
{
"code": "CAA1000",
"name": "Test Current Assets Account",
"user_type_id": self.env.ref(
"account.data_account_type_current_assets"
).id,
"reconcile": True,
}
)
account.reconcile = True
self.aml[0].account_id = account.id
with self.assertRaises(UserError):
self.aml.reconcile()
Expand Down

0 comments on commit 0b9bf6f

Please sign in to comment.