Skip to content

Commit

Permalink
[16.0][FIX] fix amount digits precision & view update error
Browse files Browse the repository at this point in the history
[16.0][FIX] fix psot-migration view load bug

[16.0][FIX] fix digits precision for ecotaxe amount on invoice & product & fixed ecotaxe

[16.0][FIX] tests

[16.0][FIX] replace onchange by compute

[16.0][FIX] pre-commit
  • Loading branch information
mourad-ehm committed Mar 4, 2024
1 parent 38f0f04 commit a046ea6
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 38 deletions.
15 changes: 7 additions & 8 deletions l10n_fr_ecotaxe/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ France Custom Ecotaxe
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:03df899941b30a17bd699f852929cc53708980e5cc79667d57c41486f8f809b9
!! source digest: sha256:23479e79cea1c7653013329021c55bf27b1d6fa0d64734b13f53ca3209feaffa
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -38,29 +38,28 @@ 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
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:
There is the main change to manage in migration script:

renamed field
model old field new field
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
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::
Expand Down
2 changes: 1 addition & 1 deletion l10n_fr_ecotaxe/data/decimal_precision.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<odoo noupdate="1">
<record id="ecotaxe_decimal" model="decimal.precision">
<field name="name">Ecotaxe</field>
<field name="digits">3</field>
<field name="digits">4</field>
</record>
</odoo>
35 changes: 35 additions & 0 deletions l10n_fr_ecotaxe/migrations/16.0.2.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2024 Akretion France (http://www.akretion.com/)
# @author Mourad EL HADJ MIMOUNE <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
# Due to the bug of update module we need to deactivate view
openupgrade.logged_query(
env.cr,
"""
UPDATE ir_ui_view set
active = True
WHERE id in (
SELECT "ir_ui_view".id FROM "ir_ui_view"
WHERE (("ir_ui_view"."active" = False)
AND (unaccent(COALESCE("ir_ui_view"."arch_db"->>'fr_FR',
"ir_ui_view"."arch_db"->>'en_US')) ilike unaccent('%classification_id%')))
)
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE ir_ui_view set
active = False WHERE id in (
SELECT "ir_ui_view".id FROM "ir_ui_view"
WHERE (("ir_ui_view"."active" = true)
AND (unaccent(COALESCE("ir_ui_view"."arch_db"->>'fr_FR',
"ir_ui_view"."arch_db"->>'en_US')) ilike unaccent('%ecotaxe_classification_id%')))
ORDER BY "ir_ui_view"."priority" ASC LIMIT 80)
""",
)
15 changes: 15 additions & 0 deletions l10n_fr_ecotaxe/migrations/16.0.2.0.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@

@openupgrade.migrate()
def migrate(env, version):
# Due to the bug of update module we need to deactivate view
openupgrade.logged_query(
env.cr,
"""
UPDATE ir_ui_view set
active = False
WHERE id in (
SELECT "ir_ui_view".id FROM "ir_ui_view"
WHERE (("ir_ui_view"."active" = true)
AND (unaccent(COALESCE("ir_ui_view"."arch_db"->>'fr_FR',
"ir_ui_view"."arch_db"->>'en_US')) ilike unaccent('%ecotaxe_classification_id%')))
ORDER BY "ir_ui_view"."priority" ASC LIMIT 80
)
""",
)
if not openupgrade.column_exists(
env.cr, "account_ecotaxe_classification", "categ_id"
):
Expand Down
25 changes: 17 additions & 8 deletions l10n_fr_ecotaxe/models/account_ecotaxe_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ def _default_company_id(self):
"the ecotaxe coef must take into account\n"
"the weight unit of measure (kg by default)",
)
ecotaxe_coef = fields.Float(digits="Ecotaxe")
default_fixed_ecotaxe = fields.Float(help="Default fixed ecotaxe amount.")
ecotaxe_coef = fields.Float(
digits="Ecotaxe", compute="_compute_ecotaxe_vals", readonly=False, store=True
)
default_fixed_ecotaxe = fields.Float(
digits="Ecotaxe",
help="Default fixed ecotaxe amount.",
compute="_compute_ecotaxe_vals",
readonly=False,
store=True,
)
categ_id = fields.Many2one(
comodel_name="account.ecotaxe.category",
string="Category",
Expand Down Expand Up @@ -76,9 +84,10 @@ def _default_company_id(self):
emebi_code = fields.Char()
scale_code = fields.Char()

@api.onchange("ecotaxe_type")
def _onchange_ecotaxe_type(self):
if self.ecotaxe_type == "weight_based":
self.default_fixed_ecotaxe = 0
if self.ecotaxe_type == "fixed":
self.ecotaxe_coef = 0
@api.depends("ecotaxe_type")
def _compute_ecotaxe_vals(self):
for classif in self:
if classif.ecotaxe_type == "weight_based":
classif.default_fixed_ecotaxe = 0
if classif.ecotaxe_type == "fixed":
classif.ecotaxe_coef = 0
7 changes: 5 additions & 2 deletions l10n_fr_ecotaxe/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
class AccountMove(models.Model):
_inherit = "account.move"

amount_ecotaxe = fields.Monetary(
string="Included Ecotaxe", store=True, compute="_compute_ecotaxe"
amount_ecotaxe = fields.Float(
digits="Ecotaxe",
string="Included Ecotaxe",
store=True,
compute="_compute_ecotaxe",
)

@api.depends("invoice_line_ids.subtotal_ecotaxe")
Expand Down
8 changes: 4 additions & 4 deletions l10n_fr_ecotaxe/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ class AcountMoveLine(models.Model):
string="Ecotaxe lines",
copy=True,
)
subtotal_ecotaxe = fields.Float(store=True, compute="_compute_ecotaxe")
subtotal_ecotaxe = fields.Float(
digits="Ecotaxe", store=True, compute="_compute_ecotaxe"
)
ecotaxe_amount_unit = fields.Float(
digits="Ecotaxe",
string="Ecotaxe Unit.",
store=True,
compute="_compute_ecotaxe",
Expand All @@ -32,9 +35,6 @@ def _compute_ecotaxe(self):
unit = sum(line.ecotaxe_line_ids.mapped("amount_unit"))
subtotal_ecotaxe = sum(line.ecotaxe_line_ids.mapped("amount_total"))

if line.move_id.currency_id:
unit = line.move_id.currency_id.round(unit)
subtotal_ecotaxe = line.move_id.currency_id.round(subtotal_ecotaxe)
line.update(
{
"ecotaxe_amount_unit": unit,
Expand Down
11 changes: 7 additions & 4 deletions l10n_fr_ecotaxe/models/ecotaxe_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ class EcotaxeLineMixin(models.AbstractModel):
"account.ecotaxe.classification",
string="Classification",
)
amount_unit = fields.Monetary(
amount_unit = fields.Float(
digits="Ecotaxe",
compute="_compute_ecotaxe",
help="Ecotaxe Amount computed form Classification or Manuel ecotaxe",
store=True,
)
force_amount_unit = fields.Monetary(
help="Force ecotaxe.\n" "Allow to subtite default Ecotaxe Classification\n"
force_amount_unit = fields.Float(
digits="Ecotaxe",
help="Force ecotaxe.\n" "Allow to subtite default Ecotaxe Classification\n",
)
amount_total = fields.Monetary(
amount_total = fields.Float(
digits="Ecotaxe",
compute="_compute_ecotaxe",
help="Ecotaxe Amount total computed form Classification or forced ecotaxe amount",
store=True,
Expand Down
8 changes: 5 additions & 3 deletions l10n_fr_ecotaxe/models/ecotaxe_line_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class EcotaxeLineProduct(models.Model):
"account.ecotaxe.classification",
string="Classification",
)
force_amount = fields.Monetary(
force_amount = fields.Float(
digits="Ecotaxe",
help="Force ecotaxe amount.\n"
"Allow to substitute default Ecotaxe Classification\n"
"Allow to substitute default Ecotaxe Classification\n",
)
amount = fields.Monetary(
amount = fields.Float(
digits="Ecotaxe",
compute="_compute_ecotaxe",
help="Ecotaxe Amount computed form Classification or forced ecotaxe amount",
store=True,
Expand Down
7 changes: 6 additions & 1 deletion l10n_fr_ecotaxe/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ class ProductProduct(models.Model):
compute="_compute_all_ecotaxe_line_product_ids",
search="_search_all_ecotaxe_line_product_ids",
string="All ecotaxe lines",
help="Contain all ecotaxes classification defined in product template"
"and the additionnal\n"
"ecotaxes defined in product variant. For more details"
"see the product variant accounting tab",
)
ecotaxe_amount = fields.Monetary(
ecotaxe_amount = fields.Float(
digits="Ecotaxe",
compute="_compute_product_ecotaxe",
help="Ecotaxe Amount computed form all ecotaxe line classification",
store=True,
Expand Down
3 changes: 2 additions & 1 deletion l10n_fr_ecotaxe/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class ProductTemplate(models.Model):
string="Ecotaxe lines",
copy=True,
)
ecotaxe_amount = fields.Monetary(
ecotaxe_amount = fields.Float(
digits="Ecotaxe",
compute="_compute_ecotaxe",
help="Ecotaxe Amount computed form Classification",
store=True,
Expand Down
2 changes: 1 addition & 1 deletion l10n_fr_ecotaxe/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">France Custom Ecotaxe</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:03df899941b30a17bd699f852929cc53708980e5cc79667d57c41486f8f809b9
!! source digest: sha256:23479e79cea1c7653013329021c55bf27b1d6fa0d64734b13f53ca3209feaffa
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-france/tree/16.0/l10n_fr_ecotaxe"><img alt="OCA/l10n-france" src="https://img.shields.io/badge/github-OCA%2Fl10n--france-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-france-16-0/l10n-france-16-0-l10n_fr_ecotaxe"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-france&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module applies to companies based in France mainland. It doesn’t apply to
Expand Down
8 changes: 4 additions & 4 deletions l10n_fr_ecotaxe/tests/test_ecotaxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def setUpClass(cls, chart_template_ref="l10n_fr.l10n_fr_pcg_chart_template"):
"name": "Fixed Ecotax",
"ecotaxe_type": "fixed",
"default_fixed_ecotaxe": 5.0,
"ecotaxe_product_status": "M",
"ecotaxe_supplier_status": "FAB",
"product_status": "M",
"supplier_status": "FAB",
}
)
# 2- Weight-based ecotax
Expand All @@ -35,8 +35,8 @@ def setUpClass(cls, chart_template_ref="l10n_fr.l10n_fr_pcg_chart_template"):
"name": "Weight Based Ecotax",
"ecotaxe_type": "weight_based",
"ecotaxe_coef": 0.04,
"ecotaxe_product_status": "P",
"ecotaxe_supplier_status": "FAB",
"product_status": "P",
"supplier_status": "FAB",
}
)

Expand Down
2 changes: 1 addition & 1 deletion l10n_fr_ecotaxe/views/product_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<field name="inherit_id" ref="account.product_template_form_view" />
<field name="arch" type="xml">
<group name="properties" position="after">
<group name="ecotaxe" colspan="2">
<group name="ecotaxe" col="4">
<label
for="ecotaxe_line_product_ids"
string="Product Template Ecotaxe classif"
Expand Down

0 comments on commit a046ea6

Please sign in to comment.