Skip to content

Commit

Permalink
[IMP] account_analytic_distribution_required: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernesto Tejeda committed Jan 17, 2022
1 parent 4a1b008 commit b09eda9
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 174 deletions.
1 change: 0 additions & 1 deletion account_analytic_distribution_required/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
23 changes: 10 additions & 13 deletions account_analytic_distribution_required/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Acsone - Stéphane Bidoul <stephane.bidoul@acsone.eu>
# Copyright 2017 Tecnativa - Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Account Analytic Distribution Required',
'version': '12.0.2.0.0',
'category': 'Analytic Accounting',
'license': 'AGPL-3',
'author': "ACSONE SA/NV, "
"Tecnativa, "
"Odoo Community Association (OCA)",
'website': 'http://www.acsone.eu/',
'depends': [
'account_analytic_required',
"name": "Account Analytic Distribution Required",
"version": "12.0.2.0.0",
"category": "Analytic Accounting",
"license": "AGPL-3",
"author": "ACSONE SA/NV, " "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": [
"account_analytic_required",
],
'application': False,
'installable': True,
"application": False,
"installable": True,
}
1 change: 0 additions & 1 deletion account_analytic_distribution_required/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import account
91 changes: 52 additions & 39 deletions account_analytic_distribution_required/models/account.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Acsone - Stéphane Bidoul <stephane.bidoul@acsone.eu>
# Copyright 2017 Tecnativa - Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
Expand All @@ -11,9 +10,8 @@ class AccountAccountType(models.Model):

property_analytic_policy = fields.Selection(
selection_add=[
('always_plan', 'Always (analytic distribution)'),
('always_plan_or_account',
'Always (analytic account or distribution)')
("always_plan", "Always (analytic distribution)"),
("always_plan_or_account", "Always (analytic account or distribution)"),
],
)

Expand All @@ -25,46 +23,61 @@ class AccountMoveLine(models.Model):
def _check_analytic_distribution_required_msg(self):
for move_line in self:
analytic_distribution = move_line.analytic_tag_ids.filtered(
"active_analytic_distribution")
"active_analytic_distribution"
)
if move_line.analytic_account_id and analytic_distribution:
return _('Analytic account and analytic distribution '
'are mutually exclusive')
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)
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')
@api.constrains(
"analytic_account_id", "analytic_tag_ids", "account_id", "debit", "credit"
)
def _check_analytic_required(self):
for rec in self:
message = rec._check_analytic_distribution_required_msg()
Expand Down
1 change: 0 additions & 1 deletion account_analytic_distribution_required/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_account_analytic_plan_required
Loading

0 comments on commit b09eda9

Please sign in to comment.