Skip to content

Commit 3240809

Browse files
committed
[REF] split migration into different modules
1 parent cede8f0 commit 3240809

File tree

7 files changed

+138
-82
lines changed

7 files changed

+138
-82
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from openupgradelib import openupgrade
2+
import logging
3+
_logger = logging.getLogger(__name__)
4+
5+
6+
def migrate_payment_grup_data(env):
7+
8+
# mover campos (excepto m2m)
9+
query = """
10+
update account_payment ap set
11+
unreconciled_amount = apg.unreconciled_amount
12+
from account_payment_group_bu as apg
13+
where
14+
ap.payment_group_id_bu = apg.id
15+
"""
16+
openupgrade.logged_query(env.cr, query)
17+
18+
# popular to_pay_move_lines (m2m field, en post)
19+
query = """
20+
insert into account_move_line_payment_to_pay_rel (to_pay_line_id, payment_id)
21+
select
22+
rel.to_pay_line_id, ap.id as payment_id
23+
from
24+
account_move_line_payment_group_to_pay_rel_bu rel
25+
join
26+
account_payment ap on ap.payment_group_id_bu = rel.payment_group_id
27+
"""
28+
openupgrade.logged_query(env.cr, query)
29+
30+
openupgrade.merge_models(env.cr, 'account.payment.group', 'account.payment', 'payment_group_id_bu')
31+
32+
33+
@openupgrade.migrate()
34+
def migrate(env, version):
35+
_logger.debug('Running migrate script for l10n_ar_withholding')
36+
migrate_payment_grup_data(env)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from openupgradelib import openupgrade
2+
3+
4+
_column_copy = {
5+
'account_payment': [
6+
('payment_group_id', 'payment_group_id_bu', None),
7+
],
8+
}
9+
10+
11+
_table_renames = [
12+
('account_payment_group', 'account_payment_group_bu'),
13+
('account_payment_receiptbook', 'account_payment_receiptbook_bu'),
14+
('account_move_line_payment_group_to_pay_rel', 'account_move_line_payment_group_to_pay_rel_bu'),
15+
]
16+
17+
18+
@openupgrade.migrate()
19+
def migrate(env, version):
20+
# backup de columnas que nos interesan antes de que se borren
21+
openupgrade.copy_columns(env.cr, _column_copy)
22+
# backup de tables y checkbooks
23+
for old_table, new_table in _table_renames:
24+
if openupgrade.table_exists(env.cr, old_table):
25+
openupgrade.rename_tables(env.cr, [(old_table, new_table)])
26+
27+
# Add temporary table for avoiding the automatic launch of the compute method
28+
openupgrade.logged_query(
29+
env.cr, "CREATE TABLE account_move_line_payment_to_pay_rel (payment_id integer, to_pay_line_id integer)",
30+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from openupgradelib import openupgrade
2+
import logging
3+
_logger = logging.getLogger(__name__)
4+
5+
6+
def migrate_taxes_config(env):
7+
query = """update account_tax set
8+
type_tax_use = 'none',
9+
l10n_ar_withholding_payment_type = type_tax_use
10+
where
11+
type_tax_use in ('customer', 'supplier')
12+
"""
13+
openupgrade.logged_query(env.cr, query)
14+
15+
16+
@openupgrade.migrate()
17+
def migrate(env, version):
18+
_logger.debug('Running migrate script for l10n_ar_withholding')
19+
migrate_taxes_config(env)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from openupgradelib import openupgrade
2+
3+
4+
_column_copy = {
5+
'account_tax': [('withholding_sequence_id', 'withholding_sequence_id_bu', None)],
6+
'account_payment': [
7+
('tax_withholding_id', 'tax_withholding_id_bu', None),
8+
('withholding_number', 'withholding_number_bu', None),
9+
('withholding_base_amount', 'withholding_base_amount_bu', None),
10+
],
11+
}
12+
13+
14+
_field_renames = [
15+
('account.tax', 'account_tax', 'withholding_sequence_id', 'l10n_ar_withholding_sequence_id'),
16+
]
17+
18+
19+
@openupgrade.migrate()
20+
def migrate(env, version):
21+
# backup de columnas que nos interesan antes de que se borren
22+
openupgrade.copy_columns(env.cr, _column_copy)
23+
openupgrade.rename_fields(env, _field_renames)

l10n_ar_withholding/pre-migration.py

-54
This file was deleted.

l10n_ar_withholding/post-migration.py l10n_ar_withholding_ux/17.0.0.0/end-migration.py

+4-28
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,18 @@ def migrate_payment_grup_data(env):
99
queremos pasar alguna especie de domain porque solo queremos pasarlo al pamynet que era retencion
1010
"""
1111
# mover campos (excepto m2m)
12+
# retencion_ganancias y regimen_ganancias_id en realidad los crea l10n_ar_account_wihhtolding pero todo
13+
# el que tiene este modulo tiene account_withholding_automatic
1214
query = """
1315
update account_payment ap set
14-
unreconciled_amount = apg.unreconciled_amount,
1516
withholdable_advanced_amount = apg.withholdable_advanced_amount,
1617
retencion_ganancias = apg.retencion_ganancias,
1718
regimen_ganancias_id = apg.regimen_ganancias_id
1819
from account_payment_group_bu as apg
1920
where
2021
ap.payment_group_id_bu = apg.id
2122
"""
22-
res = openupgrade.logged_query(env.cr, query)
23-
24-
# popular to_pay_move_lines (m2m field, en post)
25-
query = """
26-
insert into account_move_line_payment_to_pay_rel (to_pay_line_id, payment_id)
27-
select
28-
rel.to_pay_line_id, ap.id as payment_id
29-
from
30-
account_move_line_payment_group_to_pay_rel_bu rel
31-
join
32-
account_payment ap on ap.payment_group_id_bu = rel.payment_group_id
33-
"""
34-
res = openupgrade.logged_query(env.cr, query)
35-
36-
openupgrade.merge_models(env.cr, 'account.payment.group', 'account.payment', 'payment_group_id_bu')
37-
38-
39-
def migrate_taxes_config(env):
40-
query = """update account_tax set
41-
type_tax_use = 'none',
42-
l10n_ar_withholding_payment_type = type_tax_use
43-
where
44-
type_tax_use in ('customer', 'supplier')
45-
"""
46-
res = openupgrade.logged_query(env.cr, query)
23+
openupgrade.logged_query(env.cr, query)
4724

4825

4926
def migrate_withholdings(env):
@@ -103,12 +80,11 @@ def migrate_withholdings(env):
10380
where
10481
apm.code = 'withholding'
10582
"""
106-
res = openupgrade.logged_query(env.cr, query)
83+
openupgrade.logged_query(env.cr, query)
10784

10885

10986
@openupgrade.migrate()
11087
def migrate(env, version):
11188
_logger.debug('Running migrate script for l10n_ar_withholding')
11289
migrate_payment_grup_data(env)
11390
migrate_withholdings(env)
114-
migrate_taxes_config(env)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from openupgradelib import openupgrade
2+
import logging
3+
_logger = logging.getLogger(__name__)
4+
5+
6+
_column_copy = {
7+
'account_payment': [
8+
('automatic', 'automatic_bu', None),
9+
('withholdable_invoiced_amount', 'withholdable_invoiced_amount_bu', None),
10+
('withholdable_advanced_amount', 'withholdable_advanced_amount_bu', None),
11+
('accumulated_amount', 'accumulated_amount_bu', None),
12+
('total_amount', 'total_amount_bu', None),
13+
('withholding_non_taxable_minimum', 'withholding_non_taxable_minimum_bu', None),
14+
('withholding_non_taxable_amount', 'withholding_non_taxable_amount_bu', None),
15+
('withholdable_base_amount', 'withholdable_base_amount_bu', None),
16+
('period_withholding_amount', 'period_withholding_amount_bu', None),
17+
('previous_withholding_amount', 'previous_withholding_amount_bu', None),
18+
('computed_withholding_amount', 'computed_withholding_amount_bu', None),
19+
],
20+
}
21+
22+
23+
@openupgrade.migrate()
24+
def migrate(env, version):
25+
# backup de columnas que nos interesan antes de que se borren
26+
openupgrade.copy_columns(env.cr, _column_copy)

0 commit comments

Comments
 (0)