-
-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4766 from Tecnativa/17.0-mig-base_vat
[17.0][OU-ADD] base_vat: Migration to 17.0.
- Loading branch information
Showing
4 changed files
with
70 additions
and
1 deletion.
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
44 changes: 44 additions & 0 deletions
44
openupgrade_scripts/scripts/base_vat/17.0.1.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,44 @@ | ||
# Copyright 2025 Tecnativa - Carlos Lopez | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openupgradelib import openupgrade | ||
|
||
|
||
def _partner_fill_vies_valid(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
WITH check_vies_enabled AS ( | ||
SELECT COUNT(*) AS count FROM res_company WHERE vat_check_vies | ||
), | ||
eu_countries AS ( | ||
SELECT c.code | ||
FROM res_country c | ||
JOIN res_country_res_country_group_rel g ON c.id = g.res_country_id | ||
JOIN res_country_group cg ON g.res_country_group_id = cg.id | ||
JOIN ir_model_data imd ON cg.id = imd.res_id | ||
WHERE imd.module = 'base' | ||
AND imd.name = 'europe' | ||
AND imd.model = 'res.country.group' | ||
) | ||
UPDATE res_partner p | ||
SET vies_valid = CASE | ||
WHEN (SELECT count FROM check_vies_enabled) = 0 THEN FALSE | ||
WHEN LENGTH(p.vat) > 1 | ||
AND ( | ||
-- Extract VAT prefix | ||
-- 1 or 2 characters according to the logic in _split_vat | ||
LEFT(p.vat, | ||
CASE WHEN SUBSTRING(p.vat, 2, 1) ~ '[A-Za-z]' | ||
THEN 2 ELSE 1 END | ||
) IN (SELECT code FROM eu_countries) | ||
) THEN TRUE | ||
ELSE FALSE | ||
END; | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_partner_fill_vies_valid(env) |
18 changes: 18 additions & 0 deletions
18
openupgrade_scripts/scripts/base_vat/17.0.1.0/pre-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,18 @@ | ||
# Copyright 2025 Tecnativa - Carlos Lopez | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from openupgradelib import openupgrade | ||
|
||
|
||
def _partner_create_vies_valid_column(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
ALTER TABLE res_partner | ||
ADD COLUMN IF NOT EXISTS vies_valid BOOLEAN; | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_partner_create_vies_valid_column(env) |
7 changes: 7 additions & 0 deletions
7
openupgrade_scripts/scripts/base_vat/17.0.1.0/upgrade_analysis_work.txt
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,7 @@ | ||
---Models in module 'base_vat'--- | ||
---Fields in module 'base_vat'--- | ||
base_vat / res.partner / vies_failed_message (char) : DEL | ||
# NOTHING TO DO | ||
base_vat / res.partner / vies_valid (boolean) : NEW hasdefault: compute | ||
# DONE: pre-migration: Pre-create the column for not triggering the method. post-migration: Fill the vies_valid field in res_partner. | ||
---XML records in module 'base_vat'--- |