Skip to content

Commit 3ea78db

Browse files
committed
[IMP] product: Empty company_id
On v13, there's no default company associated with the template nor the pricelist, on contrary than on v12. We need to empty the company_id field in case of having only one company for not having problems later when creating new pricelists and not being able to select old products due to the difference on the company_id field (on a pricelist without company, you can only select templates without company, and vice versa, but not a mix of both). We need to empty the company of pricelists as well. If there are more than one company in the DB, then everything is preserved as it is. TT29732
1 parent 13551c7 commit 3ea78db

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

addons/product/migrations/13.0.1.2/post-migration.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
6590
def 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

Comments
 (0)