Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] account_analytic_required: make field non-company-dependant #692

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion account_analytic_required/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Account Analytic Required
|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds an option *analytic policy* on accounts.
You have the choice between 4 policies : *always*, *never*, *posted moves* and *optional*.
You have the choice between 4 policies : *always*, *never*, *posted moves* and empty (*optional*).

**Table of contents**

Expand Down Expand Up @@ -79,6 +79,7 @@ Contributors
* `Trobz <https://trobz.com>`_:

* Nguyễn Minh Chiến <[email protected]>
* Jairo Llopis (`Moduon <https://www.moduon.team/>`__)

Other credits
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion account_analytic_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 Required",
"version": "16.0.1.0.1",
"version": "16.0.2.0.0",
"category": "Analytic Accounting",
"license": "AGPL-3",
"author": "Akretion, Odoo Community Association (OCA)",
Expand Down
32 changes: 32 additions & 0 deletions account_analytic_required/migrations/16.0.2.0.0/post-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2024 Moduon Team S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
"""Convert company-dependant field to normal."""


def migrate(cr, version):
cr.execute(
r"""
UPDATE account_account AS acc
SET analytic_policy = prop.value_text
FROM (
SELECT
substring(res_id FROM '\d+')::int AS account_id,
value_text
FROM ir_property
WHERE
name = 'analytic_policy'
AND res_id LIKE 'account.account,%'
AND value_text != 'optional'
) AS prop
WHERE
acc.id = prop.account_id
"""
)
cr.execute(
"""
DELETE FROM ir_property
WHERE
name = 'analytic_policy'
AND res_id LIKE 'account.account,%'
"""
)
8 changes: 2 additions & 6 deletions account_analytic_required/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,22 @@ class AccountAccount(models.Model):

analytic_policy = fields.Selection(
selection=[
("optional", "Optional"),
("always", "Always"),
("posted", "Posted moves"),
("never", "Never"),
],
string="Policy for analytic account",
default="optional",
company_dependent=True,
help=(
"Sets the policy for analytic accounts.\n"
"If you select:\n"
"- Optional: The accountant is free to put an analytic account "
"- Empty: The accountant is free to put an analytic account "
"on an account move line with this type of account.\n"
"- Always: The accountant will get an error message if "
"there is no analytic account.\n"
"- Posted moves: The accountant will get an error message if no "
"analytic account is defined when the move is posted.\n"
"- Never: The accountant will get an error message if an analytic "
"account is present.\n\n"
"This field is company dependent."
"account is present."
),
)

Expand Down
1 change: 1 addition & 0 deletions account_analytic_required/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
* `Trobz <https://trobz.com>`_:

* Nguyễn Minh Chiến <[email protected]>
* Jairo Llopis (`Moduon <https://www.moduon.team/>`__)
2 changes: 1 addition & 1 deletion account_analytic_required/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This module adds an option *analytic policy* on accounts.
You have the choice between 4 policies : *always*, *never*, *posted moves* and *optional*.
You have the choice between 4 policies : *always*, *never*, *posted moves* and empty (*optional*).
4 changes: 3 additions & 1 deletion account_analytic_required/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ <h1 class="title">Account Analytic Required</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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-analytic/tree/16.0/account_analytic_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 image-reference" href="https://translation.odoo-community.org/projects/account-analytic-16-0/account-analytic-16-0-account_analytic_required"><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-analytic&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 adds an option <em>analytic policy</em> on accounts.
You have the choice between 4 policies : <em>always</em>, <em>never</em>, <em>posted moves</em> and <em>optional</em>.</p>
You have the choice between 4 policies : <em>always</em>, <em>never</em>, <em>posted moves</em> and empty (<em>optional</em>).</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down Expand Up @@ -438,6 +438,8 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
</ul>
</blockquote>
</li>
<li><p class="first">Jairo Llopis (<a class="reference external" href="https://www.moduon.team/">Moduon</a>)</p>
</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _set_analytic_policy(self, policy, account=None):
account.analytic_policy = policy

def test_optional(self):
self._set_analytic_policy("optional")
self._set_analytic_policy(False)
self._create_move(with_analytic=False)
self._create_move(with_analytic=True)

Expand Down
Loading