Skip to content

Commit 8b7389e

Browse files
[ADD] account_analytic_simple
1 parent accdf50 commit 8b7389e

File tree

16 files changed

+707
-0
lines changed

16 files changed

+707
-0
lines changed

account_analytic_simple/README.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
=======================
2+
Account Analytic Simple
3+
=======================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:13f5cce3bbfe28711777d4847ed1a885171306fabc7c34730d113497b7c65b71
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-akretion%2Fak--odoo--incubator-lightgray.png?logo=github
20+
:target: https://github.com/akretion/ak-odoo-incubator/tree/16.0/account_analytic_simple
21+
:alt: akretion/ak-odoo-incubator
22+
23+
|badge1| |badge2| |badge3|
24+
25+
Add analytic account on account move line to be able to do a simple analytic accounting
26+
for those who do not need distribution, multi account.
27+
28+
**Table of contents**
29+
30+
.. contents::
31+
:local:
32+
33+
Bug Tracker
34+
===========
35+
36+
Bugs are tracked on `GitHub Issues <https://github.com/akretion/ak-odoo-incubator/issues>`_.
37+
In case of trouble, please check there if your issue has already been reported.
38+
If you spotted it first, help us to smash it by providing a detailed and welcomed
39+
`feedback <https://github.com/akretion/ak-odoo-incubator/issues/new?body=module:%20account_analytic_simple%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
40+
41+
Do not contact contributors directly about support or help with technical issues.
42+
43+
Credits
44+
=======
45+
46+
Authors
47+
~~~~~~~
48+
49+
* Akretion
50+
51+
Contributors
52+
~~~~~~~~~~~~
53+
54+
* Florian da Costa <florian.dacosta@akretion.com>
55+
56+
Maintainers
57+
~~~~~~~~~~~
58+
59+
This module is part of the `akretion/ak-odoo-incubator <https://github.com/akretion/ak-odoo-incubator/tree/16.0/account_analytic_simple>`_ project on GitHub.
60+
61+
You are welcome to contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
2+
3+
{
4+
"name": "Account Analytic Simple",
5+
"version": "16.0.1.0.0",
6+
"category": "Accounting",
7+
"summary": "Add analytic account on account move line",
8+
"author": "Akretion,Odoo Community Association (OCA)",
9+
"website": "https://github.com/akretion/ak-odoo-incubator",
10+
"license": "AGPL-3",
11+
"depends": [
12+
"account",
13+
],
14+
"data": [
15+
"security/analytic_security.xml",
16+
"security/ir.model.access.csv",
17+
"views/account_move.xml",
18+
"views/account_move_line.xml",
19+
"views/menu.xml",
20+
],
21+
"installable": True,
22+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import account_move_line
2+
from . import account_account
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
2+
3+
from odoo import fields, models
4+
5+
6+
class AccountAccount(models.Model):
7+
_inherit = "account.account"
8+
9+
analytic_simple_policy = fields.Selection(
10+
selection=[
11+
("optional", "Optional"),
12+
("always", "Always"),
13+
("posted", "Posted moves"),
14+
("never", "Never"),
15+
],
16+
string="Policy for analytic account simple",
17+
default="optional",
18+
help=(
19+
"Sets the policy for analytic accounts.\n"
20+
"If you select:\n"
21+
"- Optional: The accountant is free to put an analytic account "
22+
"on an account move line with this type of account.\n"
23+
"- Always: The accountant will get an error message if "
24+
"there is no analytic account.\n"
25+
"- Posted moves: The accountant will get an error message if no "
26+
"analytic account is defined when the move is posted.\n"
27+
"- Never: The accountant will get an error message if an analytic "
28+
"account is present.\n\n"
29+
),
30+
)
31+
32+
def _get_analytic_simple_policy(self):
33+
"""Extension point to obtain simple analytic policy for an account"""
34+
self.ensure_one()
35+
return self.analytic_simple_policy
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
2+
3+
from odoo import _, api, exceptions, fields, models
4+
5+
6+
class AccountMoveLine(models.Model):
7+
_inherit = "account.move.line"
8+
9+
analytic_account_id = fields.Many2one(
10+
"account.analytic.account", string="Analytic Account", index="btree"
11+
)
12+
13+
def _check_analytic_simple_required_msg(self):
14+
self.ensure_one()
15+
company_cur = self.company_currency_id
16+
if company_cur.is_zero(self.debit) and company_cur.is_zero(self.credit):
17+
return None
18+
analytic_policy = self.account_id._get_analytic_simple_policy()
19+
if analytic_policy == "always" and not self.analytic_account_id:
20+
return _(
21+
"Analytic policy is set to 'Always' with account "
22+
"'%(account)s' but the analytic account is missing in "
23+
"the account move line with label '%(move)s'."
24+
) % {
25+
"account": self.account_id.display_name,
26+
"move": self.name or "",
27+
}
28+
elif analytic_policy == "never" and (self.analytic_account_id):
29+
analytic_account = self.analytic_account_id
30+
return _(
31+
"Analytic policy is set to 'Never' with account "
32+
"'%(account)s' but the account move line with label '%(move)s' "
33+
"has an analytic account '%(analytic_account)s'."
34+
) % {
35+
"account": self.account_id.display_name,
36+
"move": self.name or "",
37+
"analytic_account": analytic_account.name,
38+
}
39+
elif (
40+
analytic_policy == "posted"
41+
and not self.analytic_account_id
42+
and self.move_id.state == "posted"
43+
):
44+
return _(
45+
"Analytic policy is set to 'Posted moves' with "
46+
"account '%(account)s' but the analytic account is missing "
47+
"in the account move line with label '%(move)s'."
48+
) % {
49+
"account": self.account_id.display_name,
50+
"move": self.name or "",
51+
}
52+
return None
53+
54+
@api.constrains("analytic_account_id", "account_id", "debit", "credit")
55+
def _check_analytic_simple_required(self):
56+
for rec in self:
57+
message = rec._check_analytic_simple_required_msg()
58+
if message:
59+
raise exceptions.ValidationError(message)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Florian da Costa <florian.dacosta@akretion.com>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add analytic account on account move line to be able to do a simple analytic accounting
2+
for those who do not need distribution, multi account.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
4+
<record id="group_analytic_accounting_simple" model="res.groups">
5+
<field name="name">Simple Analytic Accounting</field>
6+
<field name="category_id" ref="base.module_category_hidden" />
7+
</record>
8+
9+
</odoo>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_account_analytic_account_simple,access_account_analytic_account_simple,analytic.model_account_analytic_account,group_analytic_accounting_simple,1,1,1,1
3+
access_account_analytic_plan_simple,access_account_analytic_plan_simple,analytic.model_account_analytic_plan,group_analytic_accounting_simple,1,1,1,1
4+
access_account_analytic_applicability_simple,access_account_analytic_applicability_simple,analytic.model_account_analytic_applicability,group_analytic_accounting_simple,1,1,1,1
5+
access_account_analytic_distribution_model_simple,access_account_analytic_distribution_model_simple,analytic.model_account_analytic_distribution_model,group_analytic_accounting_simple,1,1,1,1

0 commit comments

Comments
 (0)