Skip to content

Commit

Permalink
[MIG] account_analytic_distribution_required: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernesto Tejeda committed Jan 17, 2022
1 parent b09eda9 commit 14b4bb3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 67 deletions.
10 changes: 5 additions & 5 deletions account_analytic_distribution_required/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Account Analytic Distribution Required
: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--analytic-lightgray.png?logo=github
:target: https://github.com/OCA/account-analytic/tree/12.0/account_analytic_distribution_required
:target: https://github.com/OCA/account-analytic/tree/14.0/account_analytic_distribution_required
:alt: OCA/account-analytic
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-analytic-12-0/account-analytic-12-0-account_analytic_distribution_required
:target: https://translation.odoo-community.org/projects/account-analytic-14-0/account-analytic-14-0-account_analytic_distribution_required
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/87/12.0
:target: https://runbot.odoo-community.org/runbot/87/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -69,7 +69,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-analytic/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-analytic/issues/new?body=module:%20account_analytic_distribution_required%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/account-analytic/issues/new?body=module:%20account_analytic_distribution_required%0Aversion:%2014.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 @@ -104,6 +104,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-analytic <https://github.com/OCA/account-analytic/tree/12.0/account_analytic_distribution_required>`_ project on GitHub.
This module is part of the `OCA/account-analytic <https://github.com/OCA/account-analytic/tree/14.0/account_analytic_distribution_required>`_ 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_analytic_distribution_required/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Analytic Distribution Required",
"version": "12.0.2.0.0",
"version": "14.0.1.0.0",
"category": "Analytic Accounting",
"license": "AGPL-3",
"author": "ACSONE SA/NV, " "Tecnativa, " "Odoo Community Association (OCA)",
Expand Down
102 changes: 46 additions & 56 deletions account_analytic_distribution_required/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,69 +19,59 @@ class AccountAccountType(models.Model):
class AccountMoveLine(models.Model):
_inherit = "account.move.line"

@api.multi
def _check_analytic_distribution_required_msg(self):
for move_line in self:
analytic_distribution = move_line.analytic_tag_ids.filtered(
"active_analytic_distribution"
self.ensure_one()
analytic_distribution = self.analytic_tag_ids.filtered(
"active_analytic_distribution"
)
if self.analytic_account_id and analytic_distribution:
return _(
"Analytic account and analytic distribution are mutually exclusive"
)
analytic_policy = self.account_id._get_analytic_policy()
if analytic_policy == "always_plan" and not analytic_distribution:
return _(
"Analytic policy is set to "
"'Always (analytic distribution)' with account "
"'%s' but the analytic distribution is "
"missing in the account move line with "
"label '%s'."
) % (
self.account_id.display_name,
self.name or "",
)
if (
analytic_policy == "always_plan_or_account"
and not self.analytic_account_id
and not analytic_distribution
):
return _(
"Analytic policy is set to "
"'Always (analytic account or distribution)' "
"with account '%s' but the analytic "
"distribution and the analytic account are "
"missing in the account move line "
"with label '%s'."
) % (
self.account_id.display_name,
self.name or "",
)
elif analytic_policy == "never" and analytic_distribution:
return _(
"Analytic policy is set to 'Never' with account "
"'%s' but the account move line with label "
"'%s' has an analytic distribution"
) % (
self.account_id.display_name,
self.name or "",
)
if move_line.analytic_account_id and analytic_distribution:
return _(
"Analytic account and analytic distribution "
"are mutually exclusive"
)
if move_line.debit == 0 and move_line.credit == 0:
continue
analytic_policy = self._get_analytic_policy(move_line.account_id)
if analytic_policy == "always_plan" and not analytic_distribution:
return _(
"Analytic policy is set to "
"'Always (analytic distribution)' with account "
"%s '%s' but the analytic distribution is "
"missing in the account move line with "
"label '%s'."
) % (
move_line.account_id.code,
move_line.account_id.name,
move_line.name,
)
if (
analytic_policy == "always_plan_or_account"
and not move_line.analytic_account_id
and not analytic_distribution
):
return _(
"Analytic policy is set to "
"'Always (analytic account or distribution)' "
"with account %s '%s' but the analytic "
"distribution and the analytic account are "
"missing in the account move line "
"with label '%s'."
) % (
move_line.account_id.code,
move_line.account_id.name,
move_line.name,
)
elif analytic_policy == "never" and analytic_distribution:
return _(
"Analytic policy is set to 'Never' with account "
"%s '%s' but the account move line with label "
"'%s' has an analytic distribution %s '%s'."
) % (
move_line.account_id.code,
move_line.account_id.name,
move_line.name,
move_line.analytic_account_id.code,
move_line.analytic_account_id.name,
)

@api.constrains(
"analytic_account_id", "analytic_tag_ids", "account_id", "debit", "credit"
)
def _check_analytic_required(self):
for rec in self:
for rec in self.filtered(lambda r: r.debit or r.credit):
message = rec._check_analytic_distribution_required_msg()
if message:
raise exceptions.ValidationError(message)
else:
super(AccountMoveLine, self)._check_analytic_required()
super()._check_analytic_required()
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Account Analytic Distribution Required</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Account Analytic Distribution Required</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-analytic/tree/12.0/account_analytic_distribution_required"><img alt="OCA/account-analytic" src="https://img.shields.io/badge/github-OCA%2Faccount--analytic-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-analytic-12-0/account-analytic-12-0-account_analytic_distribution_required"><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/87/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-analytic/tree/14.0/account_analytic_distribution_required"><img alt="OCA/account-analytic" src="https://img.shields.io/badge/github-OCA%2Faccount--analytic-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-analytic-14-0/account-analytic-14-0-account_analytic_distribution_required"><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/87/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module extends account_analytic_required and adds 2 policies to
control the use of analytic distributions. The policies behave as follow</p>
<ul class="simple">
Expand Down Expand Up @@ -419,7 +419,7 @@ <h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-analytic/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-analytic/issues/new?body=module:%20account_analytic_distribution_required%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-analytic/issues/new?body=module:%20account_analytic_distribution_required%0Aversion:%2014.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 @@ -449,7 +449,7 @@ <h2><a class="toc-backref" href="#id7">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-analytic/tree/12.0/account_analytic_distribution_required">OCA/account-analytic</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-analytic/tree/14.0/account_analytic_distribution_required">OCA/account-analytic</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 @@ -24,7 +24,9 @@ def setUpClass(cls):
"name": "test aa",
}
)
cls.account_type = cls.account_type_obj.create({"name": "Test account_type"})
cls.account_type = cls.account_type_obj.create(
{"name": "Test account type", "type": "other", "internal_group": "equity"}
)
cls.account_id = cls.account_obj.create(
{
"name": "Test account",
Expand Down

0 comments on commit 14b4bb3

Please sign in to comment.