Skip to content

Commit

Permalink
[16.0][FIX] replace onchange by compute
Browse files Browse the repository at this point in the history
  • Loading branch information
mourad-ehm committed Mar 4, 2024
1 parent afe3a00 commit fcb0249
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 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
23 changes: 15 additions & 8 deletions l10n_fr_ecotaxe/models/account_ecotaxe_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ 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")
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."
digits="Ecotaxe",
help="Default fixed ecotaxe amount.",
compute="_compute_ecotaxe_vals",
readonly=False,
store=True,
)
categ_id = fields.Many2one(
comodel_name="account.ecotaxe.category",
Expand Down Expand Up @@ -78,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
2 changes: 2 additions & 0 deletions l10n_fr_ecotaxe/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ 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.Float(
digits="Ecotaxe",
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

0 comments on commit fcb0249

Please sign in to comment.