Skip to content

Commit

Permalink
[16.0][IMP] rename fields in l10n_fr_ecotaxe module
Browse files Browse the repository at this point in the history
[16.0][IMP]  rename fields in l10n_fr_ecotaxe module rest of modif & imp product view
  • Loading branch information
mourad-ehm committed Mar 4, 2024
1 parent cd691c9 commit 38f0f04
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 122 deletions.
2 changes: 1 addition & 1 deletion l10n_fr_ecotaxe/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "France Custom Ecotaxe",
"summary": "Use Ecotaxe in French localisation contexte",
"version": "16.0.1.0.0",
"version": "16.0.2.0.0",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-france",
"category": "Localization/Account Taxes",
Expand Down
201 changes: 201 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
@@ -0,0 +1,201 @@
# 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):
if not openupgrade.column_exists(
env.cr, "account_ecotaxe_classification", "categ_id"
):
openupgrade.rename_fields(
env,
[
(
"account.ecotaxe.classification",
"accoun_tecotaxe_classification",
"account_ecotaxe_categ_id",
"categ_id",
),
],
)
if not openupgrade.column_exists(
env.cr, "account_ecotaxe_classification", "sector_id"
):
openupgrade.rename_fields(
env,
[
(
"account.ecotaxe.classification",
"account_ecotaxe_classification",
"ecotaxe_sector_id",
"sector_id",
),
],
)
if not openupgrade.column_exists(
env.cr, "account_ecotaxe_classification", "collector_id"
):
openupgrade.rename_fields(
env,
[
(
"account.ecotaxe.classification",
"account_ecotaxe_classification",
"ecotaxe_collector_id",
"collector_id",
),
],
)
if not openupgrade.column_exists(
env.cr, "account_ecotaxe_classification", "product_status"
):
openupgrade.rename_fields(
env,
[
(
"account.ecotaxe.classification",
"account_ecotaxe_classification",
"ecotaxe_product_status",
"product_status",
),
],
)
if not openupgrade.column_exists(
env.cr, "account_ecotaxe_classification", "supplier_status"
):
openupgrade.rename_fields(
env,
[
(
"account.ecotaxe.classification",
"account_ecotaxe_classification",
"ecotaxe_supplier_status",
"supplier_status",
),
],
)
if not openupgrade.column_exists(
env.cr, "account_ecotaxe_classification", "emebi_code"
):
openupgrade.rename_fields(
env,
[
(
"account.ecotaxe.classification",
"account_ecotaxe_classification",
"ecotaxe_deb_code",
"emebi_code",
),
],
)
if not openupgrade.column_exists(
env.cr, "account_ecotaxe_classification", "scale_code"
):
openupgrade.rename_fields(
env,
[
(
"account.ecotaxe.classification",
"account_ecotaxe_classification",
"ecotaxe_scale_code",
"scale_code",
),
],
)
if not openupgrade.column_exists(
env.cr, "account_move_line_ecotaxe", "classification_id"
):
openupgrade.rename_fields(
env,
[
(
"account.move.line.ecotaxe",
"account_move_line_ecotaxe",
"ecotaxe_classification_id",
"classification_id",
),
],
)
if not openupgrade.column_exists(
env.cr, "account_move_line_ecotaxe", "amount_unit"
):
openupgrade.rename_fields(
env,
[
(
"account.move.line.ecotaxe",
"account_move_line_ecotaxe",
"ecotaxe_amount_unit",
"amount_unit",
),
],
)
if not openupgrade.column_exists(
env.cr, "account_move_line_ecotaxe", "amount_total"
):
openupgrade.rename_fields(
env,
[
(
"account.move.line.ecotaxe",
"account_move_line_ecotaxe",
"ecotaxe_amount_total",
"amount_total",
),
],
)
if not openupgrade.column_exists(
env.cr, "account_move_line_ecotaxe", "force_amount_unit"
):
openupgrade.rename_fields(
env,
[
(
"account.move.line.ecotaxe",
"account_move_line_ecotaxe",
"force_ecotaxe_unit",
"force_amount_unit",
),
],
)
if not openupgrade.column_exists(
env.cr, "ecotaxe_line_product", "classification_id"
):
openupgrade.rename_fields(
env,
[
(
"ecotaxe.line.product",
"ecotaxe_line_product",
"ecotaxe_classification_id",
"classification_id",
),
],
)
if not openupgrade.column_exists(env.cr, "ecotaxe_line_product", "force_amount"):
openupgrade.rename_fields(
env,
[
(
"ecotaxe.line.product",
"ecotaxe_line_product",
"force_ecotaxe_amount",
"force_amount",
),
],
)
if not openupgrade.column_exists(env.cr, "ecotaxe_line_product", "amount"):
openupgrade.rename_fields(
env,
[
(
"ecotaxe.line.product",
"ecotaxe_line_product",
"ecotaxe_amount",
"amount",
),
],
)
18 changes: 8 additions & 10 deletions l10n_fr_ecotaxe/models/account_ecotaxe_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def _default_company_id(self):
)
ecotaxe_coef = fields.Float(digits="Ecotaxe")
default_fixed_ecotaxe = fields.Float(help="Default fixed ecotaxe amount.")
account_ecotaxe_categ_id = fields.Many2one(
categ_id = fields.Many2one(
comodel_name="account.ecotaxe.category",
string="Ecotaxe category",
string="Category",
)
ecotaxe_sector_id = fields.Many2one(
sector_id = fields.Many2one(
comodel_name="ecotaxe.sector",
string="Ecotaxe sector",
)
ecotaxe_collector_id = fields.Many2one(
collector_id = fields.Many2one(
comodel_name="ecotaxe.collector",
string="Ecotaxe collector",
)
Expand All @@ -45,20 +45,18 @@ def _default_company_id(self):
" company. Otherwise, this Fiscal Classification will be available"
" for all companies.",
)
ecotaxe_product_status = fields.Selection(
product_status = fields.Selection(
[("M", "Menager"), ("P", "Professionnel")],
string="Product Status",
required=True,
)
ecotaxe_supplier_status = fields.Selection(
supplier_status = fields.Selection(
[
("FAB", "Fabricant"),
("REV", "Revendeur sous sa marque"),
("INT", "Introducteur"),
("IMP", "Importateur"),
("DIS", "Vendeur à distance"),
],
string="Supplier Status",
required=True,
help="FAB ==> Fabricant : est établi en France et fabrique des EEE\n"
"sous son propre nom ou sa propre marque, ou fait concevoir ou\n"
Expand All @@ -75,8 +73,8 @@ def _default_company_id(self):
"membre ou dans un pays tiers et vend en France des EEE par\n"
"communication à distance",
)
ecotaxe_deb_code = fields.Char()
ecotaxe_scale_code = fields.Char()
emebi_code = fields.Char()
scale_code = fields.Char()

@api.onchange("ecotaxe_type")
def _onchange_ecotaxe_type(self):
Expand Down
16 changes: 8 additions & 8 deletions l10n_fr_ecotaxe/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class AcountMoveLine(models.Model):
@api.depends(
"move_id.currency_id",
"ecotaxe_line_ids",
"ecotaxe_line_ids.ecotaxe_amount_unit",
"ecotaxe_line_ids.ecotaxe_amount_total",
"ecotaxe_line_ids.amount_unit",
"ecotaxe_line_ids.amount_total",
)
def _compute_ecotaxe(self):
for line in self:
unit = sum(line.ecotaxe_line_ids.mapped("ecotaxe_amount_unit"))
subtotal_ecotaxe = sum(line.ecotaxe_line_ids.mapped("ecotaxe_amount_total"))
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)
Expand All @@ -49,15 +49,15 @@ def _onchange_product_ecotaxe_line(self):
self.ecotaxe_line_ids = [(5,)] # Remove all ecotaxe classification
ecotax_cls_vals = []
for ecotaxeline_prod in self.product_id.all_ecotaxe_line_product_ids:
classif_id = ecotaxeline_prod.ecotaxe_classification_id.id
forced_amount = ecotaxeline_prod.force_ecotaxe_amount
classif_id = ecotaxeline_prod.classification_id.id
forced_amount = ecotaxeline_prod.force_amount
ecotax_cls_vals.append(
(
0,
0,
{
"ecotaxe_classification_id": classif_id,
"force_ecotaxe_unit": forced_amount,
"classification_id": classif_id,
"force_amount_unit": forced_amount,
},
)
)
Expand Down
2 changes: 2 additions & 0 deletions l10n_fr_ecotaxe/models/account_move_line_ecotaxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class AccountMoveLineEcotaxe(models.Model):
_name = "account.move.line.ecotaxe"
_inherit = "ecotaxe.line.mixin"
_description = "Account move line ecotaxe"

account_move_line_id = fields.Many2one(
comodel_name="account.move.line",
string="Account move line",
Expand Down
26 changes: 12 additions & 14 deletions l10n_fr_ecotaxe/models/ecotaxe_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,42 @@ class EcotaxeLineMixin(models.AbstractModel):

product_id = fields.Many2one("product.product", string="Product", readonly=True)
currency_id = fields.Many2one("res.currency", string="Currency")
ecotaxe_classification_id = fields.Many2one(
classification_id = fields.Many2one(
"account.ecotaxe.classification",
string="Ecotaxe Classification",
string="Classification",
)
ecotaxe_amount_unit = fields.Monetary(
amount_unit = fields.Monetary(
compute="_compute_ecotaxe",
help="Ecotaxe Amount computed form Classification or Manuel ecotaxe",
store=True,
)
force_ecotaxe_unit = fields.Monetary(
force_amount_unit = fields.Monetary(
help="Force ecotaxe.\n" "Allow to subtite default Ecotaxe Classification\n"
)
ecotaxe_amount_total = fields.Monetary(
amount_total = fields.Monetary(
compute="_compute_ecotaxe",
help="Ecotaxe Amount total computed form Classification or forced ecotaxe amount",
store=True,
)
quantity = fields.Float(digits="Product Unit of Measure", readonly=True)

@api.depends(
"ecotaxe_classification_id",
"force_ecotaxe_unit",
"classification_id",
"force_amount_unit",
"product_id",
"quantity",
)
def _compute_ecotaxe(self):
for ecotaxeline in self:
ecotax_cls = ecotaxeline.ecotaxe_classification_id
ecotax_cls = ecotaxeline.classification_id

if ecotax_cls.ecotaxe_type == "weight_based":
amt = ecotax_cls.ecotaxe_coef * (ecotaxeline.product_id.weight or 0.0)
else:
amt = ecotax_cls.default_fixed_ecotaxe
# force ecotaxe amount
if ecotaxeline.force_ecotaxe_unit:
amt = ecotaxeline.force_ecotaxe_unit
if ecotaxeline.force_amount_unit:
amt = ecotaxeline.force_amount_unit

ecotaxeline.ecotaxe_amount_unit = amt
ecotaxeline.ecotaxe_amount_total = (
ecotaxeline.ecotaxe_amount_unit * ecotaxeline.quantity
)
ecotaxeline.amount_unit = amt
ecotaxeline.amount_total = ecotaxeline.amount_unit * ecotaxeline.quantity
Loading

0 comments on commit 38f0f04

Please sign in to comment.