Skip to content

Commit

Permalink
Merge pull request #55 from akretion/16-ref-project
Browse files Browse the repository at this point in the history
[REF] project_invoicing_subcontractor : Replace analytic_account_id o…
  • Loading branch information
florian-dacosta authored Nov 15, 2024
2 parents 76686c0 + 408c9e1 commit 017a38e
Show file tree
Hide file tree
Showing 26 changed files with 814 additions and 220 deletions.
60 changes: 60 additions & 0 deletions account_move_line_project/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
=========================
Account Move Line Project
=========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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%2Fsubcontractor-lightgray.png?logo=github
:target: https://github.com/akretion/subcontractor/tree/16.0/account_move_line_project
:alt: akretion/subcontractor

|badge1| |badge2| |badge3|

Add project on accounting entries to allow some analysis based on project

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/akretion/subcontractor/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/subcontractor/issues/new?body=module:%20account_move_line_project%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/subcontractor <https://github.com/akretion/subcontractor/tree/16.0/account_move_line_project>`_ project on GitHub.

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

{
"name": "Account Move Line Project",
"version": "16.0.1.0.0",
"category": "Accounting",
"summary": "Add project on account move line",
"author": "Akretion,Odoo Community Association (OCA)",
"website": "https://github.com/akretion/subcontractor",
"license": "AGPL-3",
"depends": [
"account",
"project",
],
"data": [
"security/security.xml",
"views/account_move.xml",
"views/account_move_line.xml",
],
"installable": True,
}
2 changes: 2 additions & 0 deletions account_move_line_project/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_move_line_project/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"

project_policy = fields.Selection(
selection=[
("optional", "Optional"),
("always", "Always"),
("posted", "Posted moves"),
("never", "Never"),
],
string="Policy for project on accounting entries",
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_project_policy(self):
"""Extension point to obtain simple analytic policy for an account"""
self.ensure_one()
return self.project_policy
57 changes: 57 additions & 0 deletions account_move_line_project/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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"

project_id = fields.Many2one("project.project", string="Project", index="btree")

def _check_project_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
project_policy = self.account_id._get_project_policy()
if project_policy == "always" and not self.project_id:
return _(
"Project policy is set to 'Always' with account "
"'%(account)s' but the project is missing in "
"the account move line with label '%(move)s'."
) % {
"account": self.account_id.display_name,
"move": self.name or "",
}
elif project_policy == "never" and (self.project_id):
project = self.project_id
return _(
"Project policy is set to 'Never' with account "
"'%(account)s' but the account move line with label '%(move)s' "
"has an project '%(project_account)s'."
) % {
"account": self.account_id.display_name,
"move": self.name or "",
"project_account": project.name,
}
elif (
project_policy == "posted"
and not self.project_id
and self.move_id.state == "posted"
):
return _(
"Project policy is set to 'Posted moves' with "
"account '%(account)s' but the project 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("project_id", "account_id", "debit", "credit")
def _check_project_required(self):
for rec in self:
message = rec._check_project_required_msg()
if message:
raise exceptions.ValidationError(message)
1 change: 1 addition & 0 deletions account_move_line_project/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Florian da Costa <florian.dacosta@akretion.com>
1 change: 1 addition & 0 deletions account_move_line_project/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add project on accounting entries to allow some analysis based on project
9 changes: 9 additions & 0 deletions account_move_line_project/security/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_account_move_line_project" model="res.groups">
<field name="name">Project on account move line</field>
<field name="category_id" ref="base.module_category_hidden" />
</record>

</odoo>
Loading

0 comments on commit 017a38e

Please sign in to comment.