Skip to content

Commit

Permalink
[ADD] account_analytic_simple
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-dacosta committed Jul 19, 2024
1 parent accdf50 commit 8b7389e
Show file tree
Hide file tree
Showing 16 changed files with 707 additions and 0 deletions.
61 changes: 61 additions & 0 deletions account_analytic_simple/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
=======================
Account Analytic Simple
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:13f5cce3bbfe28711777d4847ed1a885171306fabc7c34730d113497b7c65b71
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-akretion%2Fak--odoo--incubator-lightgray.png?logo=github
:target: https://github.com/akretion/ak-odoo-incubator/tree/16.0/account_analytic_simple
:alt: akretion/ak-odoo-incubator

|badge1| |badge2| |badge3|

Add analytic account on account move line to be able to do a simple analytic accounting
for those who do not need distribution, multi account.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/akretion/ak-odoo-incubator/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`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**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Akretion

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

* Florian da Costa <florian.dacosta@akretion.com>

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

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.

You are welcome to contribute.
1 change: 1 addition & 0 deletions account_analytic_simple/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions account_analytic_simple/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Account Analytic Simple",
"version": "16.0.1.0.0",
"category": "Accounting",
"summary": "Add analytic account on account move line",
"author": "Akretion,Odoo Community Association (OCA)",
"website": "https://github.com/akretion/ak-odoo-incubator",
"license": "AGPL-3",
"depends": [
"account",
],
"data": [
"security/analytic_security.xml",
"security/ir.model.access.csv",
"views/account_move.xml",
"views/account_move_line.xml",
"views/menu.xml",
],
"installable": True,
}
2 changes: 2 additions & 0 deletions account_analytic_simple/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_move_line
from . import account_account
35 changes: 35 additions & 0 deletions account_analytic_simple/models/account_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class AccountAccount(models.Model):
_inherit = "account.account"

analytic_simple_policy = fields.Selection(
selection=[
("optional", "Optional"),
("always", "Always"),
("posted", "Posted moves"),
("never", "Never"),
],
string="Policy for analytic account simple",
default="optional",
help=(
"Sets the policy for analytic accounts.\n"
"If you select:\n"
"- Optional: 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"
),
)

def _get_analytic_simple_policy(self):
"""Extension point to obtain simple analytic policy for an account"""
self.ensure_one()
return self.analytic_simple_policy
59 changes: 59 additions & 0 deletions account_analytic_simple/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, exceptions, fields, models


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

analytic_account_id = fields.Many2one(
"account.analytic.account", string="Analytic Account", index="btree"
)

def _check_analytic_simple_required_msg(self):
self.ensure_one()
company_cur = self.company_currency_id
if company_cur.is_zero(self.debit) and company_cur.is_zero(self.credit):
return None
analytic_policy = self.account_id._get_analytic_simple_policy()
if analytic_policy == "always" and not self.analytic_account_id:
return _(
"Analytic policy is set to 'Always' with account "
"'%(account)s' but the analytic account is missing in "
"the account move line with label '%(move)s'."
) % {
"account": self.account_id.display_name,
"move": self.name or "",
}
elif analytic_policy == "never" and (self.analytic_account_id):
analytic_account = self.analytic_account_id
return _(
"Analytic policy is set to 'Never' with account "
"'%(account)s' but the account move line with label '%(move)s' "
"has an analytic account '%(analytic_account)s'."
) % {
"account": self.account_id.display_name,
"move": self.name or "",
"analytic_account": analytic_account.name,
}
elif (
analytic_policy == "posted"
and not self.analytic_account_id
and self.move_id.state == "posted"
):
return _(
"Analytic policy is set to 'Posted moves' with "
"account '%(account)s' but the analytic account is missing "
"in the account move line with label '%(move)s'."
) % {
"account": self.account_id.display_name,
"move": self.name or "",
}
return None

@api.constrains("analytic_account_id", "account_id", "debit", "credit")
def _check_analytic_simple_required(self):
for rec in self:
message = rec._check_analytic_simple_required_msg()
if message:
raise exceptions.ValidationError(message)
1 change: 1 addition & 0 deletions account_analytic_simple/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Florian da Costa <florian.dacosta@akretion.com>
2 changes: 2 additions & 0 deletions account_analytic_simple/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add analytic account on account move line to be able to do a simple analytic accounting
for those who do not need distribution, multi account.
9 changes: 9 additions & 0 deletions account_analytic_simple/security/analytic_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="group_analytic_accounting_simple" model="res.groups">
<field name="name">Simple Analytic Accounting</field>
<field name="category_id" ref="base.module_category_hidden" />
</record>

</odoo>
5 changes: 5 additions & 0 deletions account_analytic_simple/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_account_analytic_account_simple,access_account_analytic_account_simple,analytic.model_account_analytic_account,group_analytic_accounting_simple,1,1,1,1
access_account_analytic_plan_simple,access_account_analytic_plan_simple,analytic.model_account_analytic_plan,group_analytic_accounting_simple,1,1,1,1
access_account_analytic_applicability_simple,access_account_analytic_applicability_simple,analytic.model_account_analytic_applicability,group_analytic_accounting_simple,1,1,1,1
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
Loading

0 comments on commit 8b7389e

Please sign in to comment.