@@ -11,6 +11,67 @@ def _get_main_company(cr):
11
11
return cr .fetchone ()
12
12
13
13
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
+
14
75
def fill_company_id (cr ):
15
76
# stock.move.line
16
77
openupgrade .logged_query (
@@ -462,6 +523,7 @@ def update_sml_index(env):
462
523
@openupgrade .migrate ()
463
524
def migrate (env , version ):
464
525
main_company = _get_main_company (env .cr )
526
+ product_template_responsible_id_to_company_dependent (env )
465
527
fill_company_id (env .cr )
466
528
fill_stock_putaway_rule_location_in_id (env )
467
529
fill_propagate_date_minimum_delta (env )
0 commit comments