mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[IMP] account_asset_management: black, isort
This commit is contained in:
committed by
João Marques
parent
3747902a7e
commit
22b491e1c0
@@ -3,6 +3,7 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from openupgradelib import openupgrade
|
||||
from psycopg2 import sql
|
||||
|
||||
from odoo.tools import float_is_zero
|
||||
|
||||
|
||||
@@ -12,31 +13,33 @@ def adjust_asset_values(env):
|
||||
"""
|
||||
# Copy analytic account value
|
||||
openupgrade.logged_query(
|
||||
env.cr, """
|
||||
env.cr,
|
||||
"""
|
||||
UPDATE account_asset aa
|
||||
SET account_analytic_id = aap.account_analytic_id
|
||||
FROm account_asset_profile aap
|
||||
WHERE aa.profile_id = aap.id""",
|
||||
)
|
||||
# Adjust method_time, method_number and method_period
|
||||
number = sql.Identifier(openupgrade.get_legacy_name('method_number'))
|
||||
period = sql.Identifier(openupgrade.get_legacy_name('method_period'))
|
||||
for table in ['account_asset_profile', 'account_asset']:
|
||||
number = sql.Identifier(openupgrade.get_legacy_name("method_number"))
|
||||
period = sql.Identifier(openupgrade.get_legacy_name("method_period"))
|
||||
for table in ["account_asset_profile", "account_asset"]:
|
||||
table = sql.Identifier(table)
|
||||
openupgrade.logged_query(
|
||||
env.cr, sql.SQL("""
|
||||
env.cr,
|
||||
sql.SQL(
|
||||
"""
|
||||
UPDATE {table}
|
||||
SET method_time = 'year',
|
||||
method_number = ({number} * {period}) / 12
|
||||
WHERE MOD({number} * {period}, 12) = 0
|
||||
""").format(
|
||||
number=number,
|
||||
period=period,
|
||||
table=table,
|
||||
),
|
||||
"""
|
||||
).format(number=number, period=period, table=table),
|
||||
)
|
||||
openupgrade.logged_query(
|
||||
env.cr, sql.SQL("""
|
||||
env.cr,
|
||||
sql.SQL(
|
||||
"""
|
||||
UPDATE {table}
|
||||
SET method_period = (CASE
|
||||
WHEN {period} = 1 THEN 'month'
|
||||
@@ -44,16 +47,15 @@ def adjust_asset_values(env):
|
||||
WHEN {period} = 12 THEN 'year'
|
||||
END)
|
||||
WHERE {period} IN (1, 3, 12)
|
||||
""").format(
|
||||
period=period,
|
||||
table=table,
|
||||
),
|
||||
"""
|
||||
).format(period=period, table=table),
|
||||
)
|
||||
|
||||
|
||||
def adjust_aml_values(env):
|
||||
openupgrade.logged_query(
|
||||
env.cr, """
|
||||
env.cr,
|
||||
"""
|
||||
UPDATE account_move_line aml
|
||||
SET asset_id = aa.id,
|
||||
asset_profile_id = aa.profile_id
|
||||
@@ -70,29 +72,31 @@ def handle_account_asset_disposal_migration(env):
|
||||
In this phase we set the last asset line to the type remove on the
|
||||
corresponding assets.
|
||||
"""
|
||||
column_name = openupgrade.get_legacy_name('disposal_move_id')
|
||||
if not openupgrade.column_exists(env.cr, 'account_asset', column_name):
|
||||
column_name = openupgrade.get_legacy_name("disposal_move_id")
|
||||
if not openupgrade.column_exists(env.cr, "account_asset", column_name):
|
||||
return
|
||||
env.cr.execute(
|
||||
sql.SQL(
|
||||
"SELECT id FROM account_asset WHERE {col} IS NOT NULL"
|
||||
).format(col=sql.Identifier(column_name))
|
||||
sql.SQL("SELECT id FROM account_asset WHERE {col} IS NOT NULL").format(
|
||||
col=sql.Identifier(column_name)
|
||||
)
|
||||
)
|
||||
assets = env['account.asset'].with_context(
|
||||
allow_asset_line_update=True,
|
||||
).browse(x[0] for x in env.cr.fetchall())
|
||||
assets.mapped('depreciation_line_ids').filtered(
|
||||
assets = (
|
||||
env["account.asset"]
|
||||
.with_context(allow_asset_line_update=True)
|
||||
.browse(x[0] for x in env.cr.fetchall())
|
||||
)
|
||||
assets.mapped("depreciation_line_ids").filtered(
|
||||
lambda x: float_is_zero(
|
||||
x.remaining_value,
|
||||
precision_rounding=x.asset_id.company_currency_id.rounding,
|
||||
)
|
||||
).write({'type': 'remove'})
|
||||
).write({"type": "remove"})
|
||||
|
||||
|
||||
@openupgrade.migrate()
|
||||
def migrate(env, version):
|
||||
copied_column = openupgrade.get_legacy_name('method_time')
|
||||
if not openupgrade.column_exists(env.cr, 'account_asset', copied_column):
|
||||
copied_column = openupgrade.get_legacy_name("method_time")
|
||||
if not openupgrade.column_exists(env.cr, "account_asset", copied_column):
|
||||
# We avoid this migration if `account_asset` was not installed in v11
|
||||
return
|
||||
adjust_asset_values(env)
|
||||
|
||||
Reference in New Issue
Block a user