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

[17.0][MIG] account_ecotax: Migration to 17.0 #450

Closed
wants to merge 14 commits into from
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
128 changes: 128 additions & 0 deletions account_ecotax/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
=================
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 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
=====

Add ecotaxe classification via the menu *Accounting > configuration > Taxes > Ecotaxe Classification*.
Ecotaxe classification is either a fixed ecotaxe or weight based ecotaxe.
ecotaxe classification Infos can be used for legal declarations.
For fixed ecotaxe, ecotaxe amount is used as default value. We can for ecotaxe amount on product.

For weight based ecotaxe, we should define one ecotaxe by coef applied for the weight (depending on product materials).

Assign one or more ecotaxe classification to a product.

we can also force amount ecotaxe on account move line by classification.

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]>

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

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

|maintainer-mourad-ehm|

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
32 changes: 32 additions & 0 deletions account_ecotax/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# © 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 furniture",
"version": "17.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"],
"depends": [
"account",
"account_tax_python",
],
"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",
"views/account_tax_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)
108 changes: 108 additions & 0 deletions account_ecotax/models/account_ecotax_classification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# © 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()
sale_ecotax_ids = fields.Many2many(
"account.tax",
"ecotax_classif_taxes_rel",
"ecotax_classif_id",
"tax_id",
string="Sale EcoTax",
domain=[("is_ecotax", "=", True), ("type_tax_use", "=", "sale")],
)
purchase_ecotax_ids = fields.Many2many(
"account.tax",
"ecotax_classif_purchase_taxes_rel",
"ecotax_classif_id",
"tax_id",
string="Purchase EcoTax",
domain=[("is_ecotax", "=", True), ("type_tax_use", "=", "purchase")],
)

@api.depends("ecotax_type")
def _compute_ecotax_vals(self):
for classif in self:
if classif.ecotax_type == "weight_based":
classif.default_fixed_ecotax = 0
elif classif.ecotax_type == "fixed":
classif.ecotax_coef = 0
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(
partner, tax_lines_data, amount_total, amount_untaxed, currency
)
if len(self) != 1:
return res

base_amt = self.amount_total
ecotax_amt = self.amount_ecotax
if not ecotax_amt:
return res

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(
{
"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
Loading
Loading