-
-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] contract: Remove analytic_account_id and add migration
- Loading branch information
1 parent
4924db5
commit f7c4b5c
Showing
7 changed files
with
37 additions
and
38 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
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
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,33 @@ | ||
# © 2023 initOS GmbH | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import json | ||
import logging | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def migrate(cr, version): | ||
"""Migrate analytic account from contract line to analytic distribution""" | ||
|
||
_logger.info("Migrating analytic distribution for contract.line") | ||
cr.execute( | ||
""" | ||
SELECT id, analytic_account_id, analytic_distribution | ||
FROM contract_line | ||
WHERE analytic_account_id IS NOT NULL | ||
""" | ||
) | ||
for line_id, analytic_account_id, analytic_distribution in cr.fetchall(): | ||
analytic_account_id = str(analytic_account_id) | ||
if analytic_distribution: | ||
analytic_distribution[analytic_account_id] = ( | ||
analytic_distribution.get(analytic_account_id, 0) + 100 | ||
) | ||
else: | ||
analytic_distribution = {analytic_account_id: 100} | ||
|
||
cr.execute( | ||
"UPDATE contract_line SET analytic_distribution = %s WHERE id = %s", | ||
(json.dumps(analytic_distribution), line_id), | ||
) |
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
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
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
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