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.0][IMP] rename fields in l10n_fr_ecotaxe module #11

Closed
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
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
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)
""",
)
216 changes: 216 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,216 @@
# 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 = 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"
):
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",
),
],
)
22 changes: 11 additions & 11 deletions l10n_fr_ecotaxe/models/account_ecotaxe_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ def _default_company_id(self):
"the weight unit of measure (kg by default)",
)
ecotaxe_coef = fields.Float(digits="Ecotaxe")
default_fixed_ecotaxe = fields.Float(help="Default fixed ecotaxe amount.")
account_ecotaxe_categ_id = fields.Many2one(
default_fixed_ecotaxe = fields.Float(
digits="Ecotaxe", help="Default fixed ecotaxe amount."
)
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 +47,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 +75,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
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
24 changes: 12 additions & 12 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 @@ -24,17 +27,14 @@ 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)
subtotal_ecotaxe = line.move_id.currency_id.round(subtotal_ecotaxe)
line.update(
{
"ecotaxe_amount_unit": 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
Loading