From 8b7389eb96116d3af34d818cb6f0379495c29d88 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Fri, 19 Jul 2024 11:54:24 +0200 Subject: [PATCH] [ADD] account_analytic_simple --- account_analytic_simple/README.rst | 61 +++ account_analytic_simple/__init__.py | 1 + account_analytic_simple/__manifest__.py | 22 + account_analytic_simple/models/__init__.py | 2 + .../models/account_account.py | 35 ++ .../models/account_move_line.py | 59 +++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 2 + .../security/analytic_security.xml | 9 + .../security/ir.model.access.csv | 5 + .../static/description/index.html | 416 ++++++++++++++++++ .../views/account_move.xml | 31 ++ .../views/account_move_line.xml | 31 ++ account_analytic_simple/views/menu.xml | 25 ++ .../odoo/addons/account_analytic_simple | 1 + setup/account_analytic_simple/setup.py | 6 + 16 files changed, 707 insertions(+) create mode 100644 account_analytic_simple/README.rst create mode 100644 account_analytic_simple/__init__.py create mode 100644 account_analytic_simple/__manifest__.py create mode 100644 account_analytic_simple/models/__init__.py create mode 100644 account_analytic_simple/models/account_account.py create mode 100644 account_analytic_simple/models/account_move_line.py create mode 100644 account_analytic_simple/readme/CONTRIBUTORS.rst create mode 100644 account_analytic_simple/readme/DESCRIPTION.rst create mode 100644 account_analytic_simple/security/analytic_security.xml create mode 100644 account_analytic_simple/security/ir.model.access.csv create mode 100644 account_analytic_simple/static/description/index.html create mode 100644 account_analytic_simple/views/account_move.xml create mode 100644 account_analytic_simple/views/account_move_line.xml create mode 100644 account_analytic_simple/views/menu.xml create mode 120000 setup/account_analytic_simple/odoo/addons/account_analytic_simple create mode 100644 setup/account_analytic_simple/setup.py diff --git a/account_analytic_simple/README.rst b/account_analytic_simple/README.rst new file mode 100644 index 000000000..2c702a250 --- /dev/null +++ b/account_analytic_simple/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Florian da Costa + +Maintainers +~~~~~~~~~~~ + +This module is part of the `akretion/ak-odoo-incubator `_ project on GitHub. + +You are welcome to contribute. diff --git a/account_analytic_simple/__init__.py b/account_analytic_simple/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_analytic_simple/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_analytic_simple/__manifest__.py b/account_analytic_simple/__manifest__.py new file mode 100644 index 000000000..ffb4b5b98 --- /dev/null +++ b/account_analytic_simple/__manifest__.py @@ -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, +} diff --git a/account_analytic_simple/models/__init__.py b/account_analytic_simple/models/__init__.py new file mode 100644 index 000000000..e15138f35 --- /dev/null +++ b/account_analytic_simple/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_move_line +from . import account_account diff --git a/account_analytic_simple/models/account_account.py b/account_analytic_simple/models/account_account.py new file mode 100644 index 000000000..ffef2c1d1 --- /dev/null +++ b/account_analytic_simple/models/account_account.py @@ -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 diff --git a/account_analytic_simple/models/account_move_line.py b/account_analytic_simple/models/account_move_line.py new file mode 100644 index 000000000..339ebd6fb --- /dev/null +++ b/account_analytic_simple/models/account_move_line.py @@ -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) diff --git a/account_analytic_simple/readme/CONTRIBUTORS.rst b/account_analytic_simple/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..0bddb053a --- /dev/null +++ b/account_analytic_simple/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Florian da Costa diff --git a/account_analytic_simple/readme/DESCRIPTION.rst b/account_analytic_simple/readme/DESCRIPTION.rst new file mode 100644 index 000000000..f7cd3f1c6 --- /dev/null +++ b/account_analytic_simple/readme/DESCRIPTION.rst @@ -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. diff --git a/account_analytic_simple/security/analytic_security.xml b/account_analytic_simple/security/analytic_security.xml new file mode 100644 index 000000000..31e34f9a4 --- /dev/null +++ b/account_analytic_simple/security/analytic_security.xml @@ -0,0 +1,9 @@ + + + + + Simple Analytic Accounting + + + + diff --git a/account_analytic_simple/security/ir.model.access.csv b/account_analytic_simple/security/ir.model.access.csv new file mode 100644 index 000000000..4715687b8 --- /dev/null +++ b/account_analytic_simple/security/ir.model.access.csv @@ -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 diff --git a/account_analytic_simple/static/description/index.html b/account_analytic_simple/static/description/index.html new file mode 100644 index 000000000..bae1c70e3 --- /dev/null +++ b/account_analytic_simple/static/description/index.html @@ -0,0 +1,416 @@ + + + + + +Account Analytic Simple + + + +
+

Account Analytic Simple

+ + +

Beta License: AGPL-3 akretion/ak-odoo-incubator

+

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

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the akretion/ak-odoo-incubator project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/account_analytic_simple/views/account_move.xml b/account_analytic_simple/views/account_move.xml new file mode 100644 index 000000000..3edc6280d --- /dev/null +++ b/account_analytic_simple/views/account_move.xml @@ -0,0 +1,31 @@ + + + + + account.move + + + + + + + + + + + + diff --git a/account_analytic_simple/views/account_move_line.xml b/account_analytic_simple/views/account_move_line.xml new file mode 100644 index 000000000..1d4a27063 --- /dev/null +++ b/account_analytic_simple/views/account_move_line.xml @@ -0,0 +1,31 @@ + + + + + account.move.line + + + + + + + + + + account.move.line + + + + + + + + + + + diff --git a/account_analytic_simple/views/menu.xml b/account_analytic_simple/views/menu.xml new file mode 100644 index 000000000..40cfe482d --- /dev/null +++ b/account_analytic_simple/views/menu.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + diff --git a/setup/account_analytic_simple/odoo/addons/account_analytic_simple b/setup/account_analytic_simple/odoo/addons/account_analytic_simple new file mode 120000 index 000000000..c6a11891e --- /dev/null +++ b/setup/account_analytic_simple/odoo/addons/account_analytic_simple @@ -0,0 +1 @@ +../../../../account_analytic_simple \ No newline at end of file diff --git a/setup/account_analytic_simple/setup.py b/setup/account_analytic_simple/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_analytic_simple/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)