forked from OCA/account-analytic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DONTMERGE/MIG] Client-specific migration
For the client in question, we do not need to handle analytic tags, so this migration can be very straightforward.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logging | ||
|
||
from odoo.tools import SQL, table_exists | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
def migrate(cr, installed_version): | ||
_logger.info("Migrating stock analytic data...") | ||
need_tag_migration = ( | ||
table_exists(cr, "account_analytic_tag_stock_move_rel") | ||
and cr.execute( | ||
SQL( | ||
""" | ||
SELECT COUNT(*) | ||
FROM account_analytic_tag_stock_move_rel | ||
""", | ||
), | ||
) | ||
and cr.fetchall()[0][0] == 0 | ||
) | ||
assert not need_tag_migration, "analytic tag migration not implemented" | ||
cr.execute(""" | ||
UPDATE stock_move | ||
SET analytic_distribution = ('{"' || analytic_account_id || '": 100' || '}')::jsonb | ||
""") | ||
cr.execute(""" | ||
UPDATE stock_move_line | ||
SET analytic_distribution = ('{"' || analytic_account_id || '": 100' || '}')::jsonb | ||
""") |