Skip to content
Closed
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
4 changes: 3 additions & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ odoo_test_flavor: Both
odoo_version: 16.0
org_name: Odoo Community Association (OCA)
org_slug: OCA
rebel_module_groups: []
rebel_module_groups:
- account_product_fiscal_classification
- account_ecotax_accounting
repo_description: Odoo Accounting Taxe and Fiscal Features
repo_name: account-fiscal-rule
repo_slug: account-fiscal-rule
Expand Down
21 changes: 19 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,24 @@ jobs:
matrix:
include:
- container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest
exclude: "account_product_fiscal_classification"
include: "account_product_fiscal_classification"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest
exclude: "account_product_fiscal_classification"
include: "account_product_fiscal_classification"
name: test with OCB
makepot: "true"
- container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest
include: "account_ecotax_accounting"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest
include: "account_ecotax_accounting"
name: test with OCB
makepot: "true"
- container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest
exclude: "account_product_fiscal_classification,account_ecotax_accounting"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest
exclude: "account_product_fiscal_classification,account_ecotax_accounting"
name: test with OCB
makepot: "true"
services:
Expand All @@ -51,6 +65,9 @@ jobs:
POSTGRES_DB: odoo
ports:
- 5432:5432
env:
INCLUDE: "${{ matrix.include }}"
EXCLUDE: "${{ matrix.exclude }}"
steps:
- uses: actions/checkout@v4
with:
Expand Down
85 changes: 85 additions & 0 deletions account_ecotax_accounting/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
==================
Ecotaxe Accounting
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f50b40a0b44847a416947a1d3ad8506bec06fd47c73e5cda267332e25c602664
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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-OCA%2Faccount--fiscal--rule-lightgray.png?logo=github
:target: https://github.com/OCA/account-fiscal-rule/tree/16.0/account_ecotax_accounting
:alt: OCA/account-fiscal-rule
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-fiscal-rule-16-0/account-fiscal-rule-16-0-account_ecotax_accounting
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-fiscal-rule&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module will create a Accounting entry to transfer ecotax amount from the product income account to a ecotaxe income account.
For each invoice with ecotax, an other accounting entry is created/linked to it and will re-sunchronize in case of cancelation.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-fiscal-rule/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/OCA/account-fiscal-rule/issues/new?body=module:%20account_ecotax_accounting%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 <[email protected]>

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

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-florian-dacosta| image:: https://github.com/florian-dacosta.png?size=40px
:target: https://github.com/florian-dacosta
:alt: florian-dacosta

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-florian-dacosta|

This module is part of the `OCA/account-fiscal-rule <https://github.com/OCA/account-fiscal-rule/tree/16.0/account_ecotax_accounting>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions account_ecotax_accounting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions account_ecotax_accounting/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Ecotaxe Accounting",
"summary": "Automatically isolate ecotaxe amount in a dedicated account",
"version": "16.0.1.0.0",
"category": "Fiscale Rules",
"author": "Akretion,Odoo Community Association (OCA)",
"excludes": ["account_ecotax_tax"],
"maintainers": ["florian-dacosta"],
"website": "https://github.com/OCA/account-fiscal-rule",
"license": "AGPL-3",
"depends": ["account_ecotax"],
"data": [
"views/account_ecotax_classification.xml",
"views/res_config_settings.xml",
],
"installable": True,
}
4 changes: 4 additions & 0 deletions account_ecotax_accounting/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import account_ecotax_classification
from . import res_company
from . import res_config_settings
from . import account_move
16 changes: 16 additions & 0 deletions account_ecotax_accounting/models/account_ecotax_classification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class AccountEcotaxClassification(models.Model):
_inherit = "account.ecotax.classification"

ecotax_account_id = fields.Many2one(
"account.account",
string="Ecotaxe Account",
help="In case a customer invoice is validated with ecotax of this "
"classification, the ecotax amount will be transfered from the product "
"account to this account. If this field is not set, the account "
"configured on company level will be used",
)
110 changes: 110 additions & 0 deletions account_ecotax_accounting/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from collections import defaultdict

from odoo import _, exceptions, fields, models


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

ecotax_move_id = fields.Many2one("account.move", readonly=True, copy=False)

def _create_prepare_ecotax_move_vals(self):
self.ensure_one()
ecotax_journal_id = self.company_id.ecotax_journal_id.id
if not ecotax_journal_id:
raise exceptions.UserError(
_(
"Please configure the relative ecotax journal on the company settings"
)
)
return {
"journal_id": ecotax_journal_id,
"move_type": "entry",
"ref": _("Ecotaxe entry for %s") % self.name,
"date": self.date,
"currency_id": self.currency_id.id,
"company_id": self.company_id.id,
}

def _manage_ecotax_isolation(self):
self.ensure_one()
ecotax_lines = self.invoice_line_ids.ecotax_line_ids
account_ecotax_mapping = defaultdict(float)
product_account_mapping = defaultdict(float)
for ecotax_line in ecotax_lines:
account = (
ecotax_line.classification_id.ecotax_account_id
or self.company_id.ecotax_account_id
)
if not account:
continue
account_ecotax_mapping[account] += ecotax_line.amount_total
product_account_mapping[
ecotax_line.account_move_line_id.account_id
] += ecotax_line.amount_total
if not account_ecotax_mapping:
return self.env["account.move"]
ecotax_move = self.ecotax_move_id
if ecotax_move:
if ecotax_move.state != "cancel":
raise exceptions.ValidationError(
_("The linked ecotax entry should be canceled.")
)
ecotax_move.button_draft()
ecotax_move.line_ids.unlink()
else:
vals = self._create_prepare_ecotax_move_vals()
ecotax_move = self.create(vals)
self.write({"ecotax_move_id": ecotax_move.id})
line_vals_list = []
for account, amount_curr in account_ecotax_mapping.items():
line_vals = {
"name": "ecotax for %s" % self.name,
"account_id": account.id,
"currency_id": self.currency_id.id,
"amount_currency": self.move_type == "out_invoice"
and -amount_curr
or amount_curr,
"move_id": ecotax_move.id,
# We never want tax lines here even if the account has a default
# tax set
"tax_ids": False,
}
line_vals_list.append(line_vals)
for account, amount_curr in product_account_mapping.items():
line_vals = {
"account_id": account.id,
"currency_id": self.currency_id.id,
"amount_currency": self.move_type == "out_invoice"
and amount_curr
or -amount_curr,
"move_id": ecotax_move.id,
# We never want tax lines here even if the account has a default
# tax set
"tax_ids": False,
}
line_vals_list.append(line_vals)
ecotax_move.write({"line_ids": [(0, 0, vals) for vals in line_vals_list]})
ecotax_move.action_post()
return ecotax_move

def _post(self, soft=True):
res = super()._post(soft=soft)
for move in self:
if move.move_type in ("out_invoice", "out_refund"):
move._manage_ecotax_isolation()
return res

def button_draft(self):
res = super().button_draft()
if self.ecotax_move_id:
self.ecotax_move_id.button_cancel()
return res

def button_cancel(self):
res = super().button_cancel()
if self.ecotax_move_id:
self.ecotax_move_id.button_cancel()
return res
10 changes: 10 additions & 0 deletions account_ecotax_accounting/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

ecotax_account_id = fields.Many2one("account.account")
ecotax_journal_id = fields.Many2one("account.journal")
24 changes: 24 additions & 0 deletions account_ecotax_accounting/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

ecotax_account_id = fields.Many2one(
"account.account",
string="Ecotaxe Account",
related="company_id.ecotax_account_id",
readonly=False,
help="When a customer invoices with ecotax is validated, if the ecotax "
"classifications do not have any account configured, the ecotax amount "
"will be isolated in this account.",
)
ecotax_journal_id = fields.Many2one(
"account.journal",
string="Ecotaxe Journal",
related="company_id.ecotax_journal_id",
readonly=False,
help="Journal used to create the ecotax isolation accounting entries",
)
1 change: 1 addition & 0 deletions account_ecotax_accounting/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Florian da Costa <[email protected]>
2 changes: 2 additions & 0 deletions account_ecotax_accounting/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module will create a Accounting entry to transfer ecotax amount from the product income account to a ecotaxe income account.
For each invoice with ecotax, an other accounting entry is created/linked to it and will re-sunchronize in case of cancelation.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading