Skip to content

Commit e46086d

Browse files
[ADD] account_ecotax_accounting
1 parent 332693d commit e46086d

File tree

19 files changed

+947
-2
lines changed

19 files changed

+947
-2
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,17 @@ jobs:
3636
matrix:
3737
include:
3838
- container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest
39-
exclude: "account_product_fiscal_classification"
39+
exclude: "account_product_fiscal_classification,account_ecotax_accounting"
4040
name: test with Odoo
4141
- container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest
42-
exclude: "account_product_fiscal_classification"
42+
exclude: "account_product_fiscal_classification,account_ecotax_accounting"
43+
name: test with OCB
44+
makepot: "true"
45+
- container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest
46+
include: "account_ecotax_accounting"
47+
name: test with Odoo
48+
- container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest
49+
include: "account_ecotax_accounting"
4350
name: test with OCB
4451
makepot: "true"
4552
services:
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
==================
2+
Ecotaxe Accounting
3+
==================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:f50b40a0b44847a416947a1d3ad8506bec06fd47c73e5cda267332e25c602664
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-OCA%2Faccount--fiscal--rule-lightgray.png?logo=github
20+
:target: https://github.com/OCA/account-fiscal-rule/tree/16.0/account_ecotax_accounting
21+
:alt: OCA/account-fiscal-rule
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/account-fiscal-rule-16-0/account-fiscal-rule-16-0-account_ecotax_accounting
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-fiscal-rule&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module will create a Accounting entry to transfer ecotax amount from the product income account to a ecotaxe income account.
32+
For each invoice with ecotax, an other accounting entry is created/linked to it and will re-sunchronize in case of cancelation.
33+
34+
**Table of contents**
35+
36+
.. contents::
37+
:local:
38+
39+
Bug Tracker
40+
===========
41+
42+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-fiscal-rule/issues>`_.
43+
In case of trouble, please check there if your issue has already been reported.
44+
If you spotted it first, help us to smash it by providing a detailed and welcomed
45+
`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**>`_.
46+
47+
Do not contact contributors directly about support or help with technical issues.
48+
49+
Credits
50+
=======
51+
52+
Authors
53+
~~~~~~~
54+
55+
* Akretion
56+
57+
Contributors
58+
~~~~~~~~~~~~
59+
60+
* Florian da Costa <[email protected]>
61+
62+
Maintainers
63+
~~~~~~~~~~~
64+
65+
This module is maintained by the OCA.
66+
67+
.. image:: https://odoo-community.org/logo.png
68+
:alt: Odoo Community Association
69+
:target: https://odoo-community.org
70+
71+
OCA, or the Odoo Community Association, is a nonprofit organization whose
72+
mission is to support the collaborative development of Odoo features and
73+
promote its widespread use.
74+
75+
.. |maintainer-florian-dacosta| image:: https://github.com/florian-dacosta.png?size=40px
76+
:target: https://github.com/florian-dacosta
77+
:alt: florian-dacosta
78+
79+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
80+
81+
|maintainer-florian-dacosta|
82+
83+
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.
84+
85+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
3+
{
4+
"name": "Ecotaxe Accounting",
5+
"summary": "Automatically isolate ecotaxe amount in a dedicated account",
6+
"version": "16.0.1.0.0",
7+
"category": "Fiscale Rules",
8+
"author": "Akretion,Odoo Community Association (OCA)",
9+
"excludes": ["account_ecotax_tax"],
10+
"maintainers": ["florian-dacosta"],
11+
"website": "https://github.com/OCA/account-fiscal-rule",
12+
"license": "AGPL-3",
13+
"depends": ["account_ecotax"],
14+
"data": [
15+
"views/account_ecotax_classification.xml",
16+
"views/res_config_settings.xml",
17+
],
18+
"installable": True,
19+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from . import account_ecotax_classification
2+
from . import res_company
3+
from . import res_config_settings
4+
from . import account_move
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
3+
from odoo import fields, models
4+
5+
6+
class AccountEcotaxClassification(models.Model):
7+
_inherit = "account.ecotax.classification"
8+
9+
ecotax_account_id = fields.Many2one(
10+
"account.account",
11+
string="Ecotaxe Account",
12+
help="In case a customer invoice is validated with ecotax of this "
13+
"classification, the ecotax amount will be transfered from the product "
14+
"account to this account. If this field is not set, the account "
15+
"configured on company level will be used",
16+
)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
3+
from collections import defaultdict
4+
5+
from odoo import _, exceptions, fields, models
6+
7+
8+
class AccountMove(models.Model):
9+
_inherit = "account.move"
10+
11+
ecotax_move_id = fields.Many2one("account.move", readonly=True, copy=False)
12+
13+
def _create_prepare_ecotax_move_vals(self):
14+
self.ensure_one()
15+
ecotax_journal_id = self.company_id.ecotax_journal_id.id
16+
if not ecotax_journal_id:
17+
raise exceptions.UserError(
18+
_(
19+
"Please configure the relative ecotax journal on the company settings"
20+
)
21+
)
22+
return {
23+
"journal_id": ecotax_journal_id,
24+
"move_type": "entry",
25+
"ref": _("Ecotaxe entry for %s") % self.name,
26+
"date": self.date,
27+
"currency_id": self.currency_id.id,
28+
"company_id": self.company_id.id,
29+
}
30+
31+
def _manage_ecotax_isolation(self):
32+
self.ensure_one()
33+
ecotax_lines = self.invoice_line_ids.ecotax_line_ids
34+
account_ecotax_mapping = defaultdict(float)
35+
product_account_mapping = defaultdict(float)
36+
for ecotax_line in ecotax_lines:
37+
account = (
38+
ecotax_line.classification_id.ecotax_account_id
39+
or self.company_id.ecotax_account_id
40+
)
41+
if not account:
42+
continue
43+
account_ecotax_mapping[account] += ecotax_line.amount_total
44+
product_account_mapping[
45+
ecotax_line.account_move_line_id.account_id
46+
] += ecotax_line.amount_total
47+
if not account_ecotax_mapping:
48+
return self.env["account.move"]
49+
ecotax_move = self.ecotax_move_id
50+
if ecotax_move:
51+
if ecotax_move.state != "cancel":
52+
raise exceptions.ValidationError(
53+
_("The linked ecotax entry should be canceled.")
54+
)
55+
ecotax_move.button_draft()
56+
ecotax_move.line_ids.unlink()
57+
else:
58+
vals = self._create_prepare_ecotax_move_vals()
59+
ecotax_move = self.create(vals)
60+
self.write({"ecotax_move_id": ecotax_move.id})
61+
line_vals_list = []
62+
for account, amount_curr in account_ecotax_mapping.items():
63+
line_vals = {
64+
"name": "ecotax for %s" % self.name,
65+
"account_id": account.id,
66+
"currency_id": self.currency_id.id,
67+
"amount_currency": self.move_type == "out_invoice"
68+
and -amount_curr
69+
or amount_curr,
70+
"move_id": ecotax_move.id,
71+
# We never want tax lines here even if the account has a default
72+
# tax set
73+
"tax_ids": False,
74+
}
75+
line_vals_list.append(line_vals)
76+
for account, amount_curr in product_account_mapping.items():
77+
line_vals = {
78+
"account_id": account.id,
79+
"currency_id": self.currency_id.id,
80+
"amount_currency": self.move_type == "out_invoice"
81+
and amount_curr
82+
or -amount_curr,
83+
"move_id": ecotax_move.id,
84+
# We never want tax lines here even if the account has a default
85+
# tax set
86+
"tax_ids": False,
87+
}
88+
line_vals_list.append(line_vals)
89+
ecotax_move.write({"line_ids": [(0, 0, vals) for vals in line_vals_list]})
90+
ecotax_move.action_post()
91+
return ecotax_move
92+
93+
def _post(self, soft=True):
94+
res = super()._post(soft=soft)
95+
for move in self:
96+
if move.move_type in ("out_invoice", "out_refund"):
97+
move._manage_ecotax_isolation()
98+
return res
99+
100+
def button_draft(self):
101+
res = super().button_draft()
102+
if self.ecotax_move_id:
103+
self.ecotax_move_id.button_cancel()
104+
return res
105+
106+
def button_cancel(self):
107+
res = super().button_cancel()
108+
if self.ecotax_move_id:
109+
self.ecotax_move_id.button_cancel()
110+
return res
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
3+
from odoo import fields, models
4+
5+
6+
class ResCompany(models.Model):
7+
_inherit = "res.company"
8+
9+
ecotax_account_id = fields.Many2one("account.account")
10+
ecotax_journal_id = fields.Many2one("account.journal")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 ResConfigSettings(models.TransientModel):
7+
_inherit = "res.config.settings"
8+
9+
ecotax_account_id = fields.Many2one(
10+
"account.account",
11+
string="Ecotaxe Account",
12+
related="company_id.ecotax_account_id",
13+
readonly=False,
14+
help="When a customer invoices with ecotax is validated, if the ecotax "
15+
"classifications do not have any account configured, the ecotax amount "
16+
"will be isolated in this account.",
17+
)
18+
ecotax_journal_id = fields.Many2one(
19+
"account.journal",
20+
string="Ecotaxe Journal",
21+
related="company_id.ecotax_journal_id",
22+
readonly=False,
23+
help="Journal used to create the ecotax isolation accounting entries",
24+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Florian da Costa <[email protected]>

0 commit comments

Comments
 (0)