Skip to content

Commit 6fd9313

Browse files
[OU-FIX] stock: convert responsible_id to company_dependent
1 parent ad672c8 commit 6fd9313

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

addons/stock/migrations/13.0.1.1/openupgrade_analysis_work.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ stock / product.putaway / name (char) : DEL re
1919
# NOTHING TO DO: model removed
2020

2121
stock / product.template / responsible_id (many2one) : not stored anymore
22-
# NOTHING TO DO: non stored
22+
# DONE: post-migration: convert to company_dependent (filling ir_property)
2323

2424
stock / res.company / stock_mail_confirmation_template_id (many2one): NEW relation: mail.template, hasdefault
2525
stock / res.company / stock_move_email_validation (boolean): NEW hasdefault

addons/stock/migrations/13.0.1.1/post-migration.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,67 @@ def _get_main_company(cr):
1111
return cr.fetchone()
1212

1313

14+
def product_template_responsible_id_to_company_dependent(env):
15+
"""Usually for such cases, openupgrade.convert_to_company_dependent() should
16+
normally be used, but that function does not seem to support converting
17+
a field to company-dependent without changing its name at the same time.
18+
moreover, it stores boolean values even when they are false (what odoo
19+
does not), and it creates values for all companies, which does not make
20+
sense when a record is linked to a particular company only.
21+
"""
22+
responsible_id_field_id = (env.ref("stock.field_product_template__responsible_id").id,)
23+
# this many2one property stores its value in the value_reference column
24+
openupgrade.logged_query(
25+
env.cr,
26+
"""
27+
insert into ir_property (
28+
company_id, fields_id, value_reference, name, res_id, type
29+
)
30+
select
31+
company_id,
32+
%(field_id)s,
33+
'res.users,' || responsible_id,
34+
'responsible_id',
35+
'product.template,' || id,
36+
'many2one'
37+
from product_template
38+
where
39+
company_id is not null
40+
and responsible_id is not null
41+
order by id
42+
""",
43+
{"field_id": responsible_id_field_id},
44+
)
45+
# for product.template records that are not linked to a company, create an
46+
# ir.property record for each company.
47+
openupgrade.logged_query(
48+
env.cr,
49+
"""
50+
insert into ir_property (
51+
company_id,
52+
fields_id,
53+
value_reference,
54+
name,
55+
res_id,
56+
type
57+
)
58+
select
59+
rc.id,
60+
%(field_id)s,
61+
'res.users,' || pt.responsible_id,
62+
'responsible_id',
63+
'product.template,' || pt.id,
64+
'many2one'
65+
from product_template as pt
66+
inner join res_company as rc on
67+
pt.company_id is null and
68+
pt.responsible_id is not null
69+
order by pt.id, rc.id
70+
""",
71+
{"field_id": responsible_id_field_id},
72+
)
73+
74+
1475
def fill_company_id(cr):
1576
# stock.move.line
1677
openupgrade.logged_query(
@@ -462,6 +523,7 @@ def update_sml_index(env):
462523
@openupgrade.migrate()
463524
def migrate(env, version):
464525
main_company = _get_main_company(env.cr)
526+
product_template_responsible_id_to_company_dependent(env)
465527
fill_company_id(env.cr)
466528
fill_stock_putaway_rule_location_in_id(env)
467529
fill_propagate_date_minimum_delta(env)

0 commit comments

Comments
 (0)