@@ -61,6 +61,31 @@ def convert_image_attachments(env):
6161 Model .browse (attachment .res_id ).image_1920 = attachment .datas
6262
6363
64+ @openupgrade .logging ()
65+ def empty_template_pricelist_company (env ):
66+ """On v13, there's no default company associated with the template nor the
67+ pricelist, on contrary than on v12. We need to empty the company_id field in
68+ case of having only one company for not having problems later when creating
69+ new pricelists and not being able to select old products due to the
70+ difference on the company_id field (on a pricelist without company, you can
71+ only select templates without company, and vice versa, but not a mix of
72+ both).
73+
74+ We need to empty the company of pricelists as well.
75+
76+ If there are more than one company in the DB, then everything is
77+ preserved as it is.
78+ """
79+ env .cr .execute ("SELECT COUNT(*) FROM res_company" )
80+ if env .cr .fetchone ()[0 ] == 1 :
81+ openupgrade .logged_query (
82+ env .cr , "UPDATE product_template SET company_id = NULL WHERE company_id is NOT NULL" ,
83+ )
84+ openupgrade .logged_query (
85+ env .cr , "UPDATE product_pricelist SET company_id = NULL WHERE company_id is NOT NULL" ,
86+ )
87+
88+
6489@openupgrade .migrate ()
6590def migrate (env , version ):
6691 fill_product_template_attribute_value_attribute_line_id (env )
@@ -69,3 +94,4 @@ def migrate(env, version):
6994 openupgrade .load_data (
7095 env .cr , "product" , "migrations/13.0.1.2/noupdate_changes.xml" )
7196 convert_image_attachments (env )
97+ empty_template_pricelist_company (env )
0 commit comments