Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16][REF] account_ecotax split #454

Open
wants to merge 15 commits into
base: 16.0
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ jobs:
matrix:
include:
- container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest
exclude: "account_product_fiscal_classification"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest
exclude: "account_product_fiscal_classification"
name: test with OCB
makepot: "true"
services:
Expand Down
142 changes: 142 additions & 0 deletions account_ecotax/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
=================
Ecotax Management
=================

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

.. |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
: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
: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 applies to companies based in France mainland. It doesn't apply to
companies based in the DOM-TOMs (Guadeloupe, Martinique, Guyane, Réunion,
Mayotte).

It add Ecotaxe amount on invoice line.
furthermore, a total ecotaxe are added at the footer of each document.

To make easy ecotaxe management and to factor the data, ecotaxe are set on products via ECOTAXE classifications.
ECOTAXE classification can either a fixed or weight based ecotaxe.

A product can have one or serveral ecotaxe classifications. For exemple wooden window blinds equipped with electric motor can
have ecotaxe for wood and ecotaxe for electric motor.

This module has some limits :
- The ecotax amount is always included in the price of the product.
- The ecotax amount is not isolated in an specific accounting account but is included in the product income account.

If one of these limits is an issue, you could install the submodule account_ecotax_tax.
This second module lets you manage the ecotax as a tax, so you can configure if you want it to be included or excluded of product price and also configuring an accounting account to isolate it.
The main consequence of this approach is that the ecotax won't be considered in the turnover, since it is considered as a tax.

This module version add the possibility to manage several ecotaxe classification by product.
A migration script is necessary to update from previous versions.

There is the main change to manage in migration script:

renamed field
model old field new field
account.move.line unit_ecotaxe_amount ecotaxe_amount_unit
product.template manual_fixed_ecotaxe force_ecotaxe_amount

changed fields
model old field new field
product.template ecotaxe_classification_id ecotaxe_classification_ids

added fields
model new field
account.move.line ecotaxe_line_ids
product.template ecotaxe_line_product_ids

**Table of contents**

.. contents::
:local:

Usage
=====

1. Add an ecotax classification via the menu **Accounting > Configuration > Taxes > Ecotax Classification**.

- The ecotax classification can be either a fixed ecotax or a weight-based ecotax.
- Ecotax classification information can be used for legal declarations.
- For the fixed ecotax, the ecotax amount is used as a default value, which can be overridden on the product.
- For the weight-based ecotax, define one ecotax by a coefficient applied to the weight (depending on the product's materials).

2. Assign one or more ecotax classifications to a product.

- The ecotax amount can also be manually overridden on the product.

3. Create an invoice with this product

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%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
~~~~~~~~~~~~

* Mourad EL HADJ MIMOUNE <[email protected]>
* 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-mourad-ehm| image:: https://github.com/mourad-ehm.png?size=40px
:target: https://github.com/mourad-ehm
:alt: mourad-ehm
.. |maintainer-florian-dacosta| image:: https://github.com/florian-dacosta.png?size=40px
:target: https://github.com/florian-dacosta
:alt: florian-dacosta

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

|maintainer-mourad-ehm| |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>`_ 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/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
30 changes: 30 additions & 0 deletions account_ecotax/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# © 2014-2023 Akretion (http://www.akretion.com)
# @author Mourad EL HADJ MIMOUNE <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Ecotax Management",
"summary": "Ecotax Management: in French context is a 'cost' "
"added to the sale price of electrical or electronic appliances or furnishing items",
"version": "16.0.1.0.0",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-fiscal-rule",
"category": "Localization/Account Taxes",
"license": "AGPL-3",
"maintainers": ["mourad-ehm", "florian-dacosta"],
"depends": [
"account",
],
"data": [
"data/decimal_precision.xml",
"security/ir_rule.xml",
"security/ir.model.access.csv",
"views/account_ecotax_category_view.xml",
"views/ecotax_sector_view.xml",
"views/ecotax_collector_view.xml",
"views/account_ecotax_classification_view.xml",
"views/account_move_view.xml",
"views/product_template_view.xml",
"views/product_view.xml",
],
"installable": True,
}
7 changes: 7 additions & 0 deletions account_ecotax/data/decimal_precision.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="ecotaxe_decimal" model="decimal.precision">
<field name="name">Ecotax</field>
<field name="digits">4</field>
</record>
</odoo>
12 changes: 12 additions & 0 deletions account_ecotax/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from . import account_ecotax_category
from . import account_ecotax_classification
from . import account_move
from . import account_move_line
from . import ecotax_line_product
from . import product_template
from . import ecotax_line_mixin
from . import account_move_line_ecotax
from . import product_product
from . import ecotax_sector
from . import ecotax_collector
from . import account_tax
15 changes: 15 additions & 0 deletions account_ecotax/models/account_ecotax_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2021 Camptocamp
# @author Silvio Gregorini <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class AccountEcotaxCategory(models.Model):
_name = "account.ecotax.category"
_description = "Account Ecotax Category"

name = fields.Char(required=True)
code = fields.Char(required=True)
description = fields.Char()
active = fields.Boolean(default=True)
92 changes: 92 additions & 0 deletions account_ecotax/models/account_ecotax_classification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# © 2014-2023 Akretion (http://www.akretion.com)
# @author Mourad EL HADJ MIMOUNE <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class AccountEcotaxClassification(models.Model):
_name = "account.ecotax.classification"
_description = "Account Ecotax Classification"

name = fields.Char(required=True)
code = fields.Char()
ecotax_type = fields.Selection(
[("fixed", "Fixed"), ("weight_based", "Weight based")],
required=True,
help="If ecotax is weight based,"
"the ecotax coef must take into account\n"
"the weight unit of measure (kg by default)",
)
ecotax_coef = fields.Float(
digits="Ecotax", compute="_compute_ecotax_vals", readonly=False, store=True
)
default_fixed_ecotax = fields.Float(
digits="Ecotax",
help="Default fixed ecotax amount.",
compute="_compute_ecotax_vals",
readonly=False,
store=True,
)
categ_id = fields.Many2one(
comodel_name="account.ecotax.category",
string="Category",
)
sector_id = fields.Many2one(
comodel_name="ecotax.sector",
string="Ecotax sector",
)
collector_id = fields.Many2one(
comodel_name="ecotax.collector",
string="Ecotax collector",
)
active = fields.Boolean(default=True)
company_id = fields.Many2one(
comodel_name="res.company",
default=lambda self: self.env.company,
help="Specify a company"
" if you want to define this Ecotax Classification only for specific"
" company. Otherwise, this Fiscal Classification will be available"
" for all companies.",
)
product_status = fields.Selection(
[("M", "Menager"), ("P", "Professionnel")],
required=True,
)
supplier_status = fields.Selection(
[
("MAN", "Manufacturer"),
("RES", "Reseller, under their own brand"),
("INT", "Introducer"),
("IMP", "Importer"),
("REM", "Remote vendor"),
],
required=True,
help="MAN ==> Manufacturer: is locally established in the country, "
"and manufactures goods which are subject to ecotaxes\n"
"under their own name and brand, or designs such goods, "
"subcontracts the manufacturing and then sells them under "
"their own name and brand\n"
"RES ==> Reseller, under their own brand: is locally established "
"in the country, and sells under their own name or brand goods"
" subject to ecotax manufactured by others\n"
"INT ==> Introducer: is locally established and sells on the local "
"market goods subject to ecotax coming from other countries "
"of the European Union\n"
"IMP ==> Importer: is established in France, and sells on the local"
" market goods subject to ecotax coming from countries outside"
"the European Union\n"
"REM ==> Remote vendor: is established in another country of "
"the European Union or outside the EU, and remotely sells good "
"subject to ecotaxes to customers in the country",
)
intrastat_code = fields.Char()
scale_code = fields.Char()

@api.depends("ecotax_type")
def _compute_ecotax_vals(self):
for classif in self:
if classif.ecotax_type == "weight_based":
classif.default_fixed_ecotax = 0

Check warning on line 90 in account_ecotax/models/account_ecotax_classification.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/account_ecotax_classification.py#L90

Added line #L90 was not covered by tests
elif classif.ecotax_type == "fixed":
classif.ecotax_coef = 0

Check warning on line 92 in account_ecotax/models/account_ecotax_classification.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/account_ecotax_classification.py#L92

Added line #L92 was not covered by tests
61 changes: 61 additions & 0 deletions account_ecotax/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# © 2014-2023 Akretion (http://www.akretion.com)
# @author Mourad EL HADJ MIMOUNE <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, fields, models
from odoo.tools.misc import formatLang


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

amount_ecotax = fields.Float(
digits="Ecotax",
string="Included Ecotax",
store=True,
compute="_compute_ecotax",
)

@api.depends("invoice_line_ids.subtotal_ecotax")
def _compute_ecotax(self):
for move in self:
move.amount_ecotax = sum(move.line_ids.mapped("subtotal_ecotax"))

@api.model
def _get_tax_totals(
self, partner, tax_lines_data, amount_total, amount_untaxed, currency
):
"""Include Ecotax when this method is called upon a single invoice

NB: `_get_tax_totals()` is called when field `tax_totals_json` is
computed, which is used in invoice form view to display taxes and
totals.
"""
res = super()._get_tax_totals(

Check warning on line 34 in account_ecotax/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/account_move.py#L34

Added line #L34 was not covered by tests
partner, tax_lines_data, amount_total, amount_untaxed, currency
)
if len(self) != 1:
return res

Check warning on line 38 in account_ecotax/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/account_move.py#L38

Added line #L38 was not covered by tests

base_amt = self.amount_total
ecotax_amt = self.amount_ecotax

Check warning on line 41 in account_ecotax/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/account_move.py#L40-L41

Added lines #L40 - L41 were not covered by tests
if not ecotax_amt:
return res

Check warning on line 43 in account_ecotax/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/account_move.py#L43

Added line #L43 was not covered by tests

env = self.with_context(lang=partner.lang).env
fmt_ecotax_amt = formatLang(env, ecotax_amt, currency_obj=currency)
fmt_base_amt = formatLang(env, base_amt, currency_obj=currency)
data = list(res["groups_by_subtotal"].get(_("Untaxed Amount")) or [])
data.append(

Check warning on line 49 in account_ecotax/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/account_move.py#L45-L49

Added lines #L45 - L49 were not covered by tests
{
"tax_group_name": _("Included Ecotax"),
"tax_group_amount": ecotax_amt,
"formatted_tax_group_amount": fmt_ecotax_amt,
"tax_group_base_amount": base_amt,
"formatted_tax_group_base_amount": fmt_base_amt,
"tax_group_id": False, # Not an actual tax
"group_key": "Included Ecotax",
}
)
res["groups_by_subtotal"][_("Untaxed Amount")] = data
return res

Check warning on line 61 in account_ecotax/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_ecotax/models/account_move.py#L60-L61

Added lines #L60 - L61 were not covered by tests
Loading
Loading