forked from OCA/intrastat-extrastat
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] hs_code_id company_dependent=True to False
Migration script provided for product.template and product.category Fixes bug OCA#126
- Loading branch information
1 parent
f7e9563
commit 6f16302
Showing
4 changed files
with
52 additions
and
3 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
45 changes: 45 additions & 0 deletions
45
product_harmonized_system/migrations/14.0.2.0.0/post-migration.py
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,45 @@ | ||
# Copyright 2021 Akretion France (http://www.akretion.com/) | ||
# @author: Alexis de Lattre <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import SUPERUSER_ID, api | ||
|
||
|
||
def migrate(cr, version): | ||
if not version: | ||
return | ||
|
||
with api.Environment.manage(): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
pc_field_id = env.ref( | ||
"product_harmonized_system.field_product_category__hs_code_id" | ||
).id | ||
cr.execute( | ||
""" | ||
UPDATE product_category pc | ||
SET hs_code_id=SUBSTRING(ip.value_reference, 9, 99)::int | ||
FROM ir_property ip | ||
WHERE ip.res_id like 'product.category,%%' AND | ||
SUBSTRING(ip.res_id, 18, 99)::int=pc.id AND | ||
ip.name='hs_code_id' AND | ||
ip.value_reference IS NOT null AND | ||
ip.fields_id=%s | ||
""", | ||
(pc_field_id,), | ||
) | ||
pt_field_id = env.ref( | ||
"product_harmonized_system.field_product_template__hs_code_id" | ||
).id | ||
cr.execute( | ||
""" | ||
UPDATE product_template pt | ||
SET hs_code_id=SUBSTRING(ip.value_reference, 9, 99)::int | ||
FROM ir_property ip | ||
WHERE ip.res_id like 'product.template,%%' AND | ||
SUBSTRING(ip.res_id, 18, 99)::int=pt.id AND | ||
ip.name='hs_code_id' AND | ||
ip.value_reference IS NOT null AND | ||
ip.fields_id=%s | ||
""", | ||
(pt_field_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