Skip to content

Commit 6383301

Browse files
committed
[OU-ADD] website_sale_product_attachment: Merged into website_sale
Related to OCA/e-commerce#1060 (comment) TT57005
1 parent a0ad418 commit 6383301

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

openupgrade_scripts/apriori.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
"stock_landed_costs_company": "stock_landed_costs",
6262
"website_sale_product_configurator": "website_sale",
6363
# odoo/enterprise
64+
# OCA/e-commerce
65+
"website_sale_product_attachment": "website_sale",
6466
# OCA/knowledge
6567
"document_page_group": "document_page_access_group",
6668
# OCA/l10n-france

openupgrade_scripts/scripts/website_sale/18.0.1.1/post-migration.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2025 Tecnativa - Pedro M. Baeza
2+
# Copyright 2025 Tecnativa - Víctor Martínez
23
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
34

45
import json
@@ -18,9 +19,86 @@ def _convert_product_ribbon_html_to_name(env):
1819
env.cr.execute(query, (json.dumps(translations), record_id))
1920

2021

22+
def _website_sale_product_attachment(env):
23+
"""Compatibility with website_sale_product_attachment to create the necessary
24+
product_document records and display those attachments in the e-commerce
25+
product file.
26+
"""
27+
if not openupgrade.table_exists(env.cr, "ir_attachment_product_template_rel"):
28+
return
29+
openupgrade.logged_query(
30+
env.cr,
31+
"""
32+
INSERT INTO ir_attachment (
33+
name,
34+
res_id,
35+
res_model,
36+
company_id,
37+
file_size,
38+
type,
39+
store_fname,
40+
checksum,
41+
mimetype,
42+
index_content,
43+
create_uid,
44+
create_date,
45+
write_uid,
46+
write_date
47+
)
48+
SELECT
49+
a.name,
50+
rel.product_template_id,
51+
'product.template',
52+
a.company_id,
53+
a.file_size,
54+
a.type,
55+
a.store_fname,
56+
a.checksum,
57+
a.mimetype,
58+
a.index_content,
59+
a.create_uid,
60+
a.create_date,
61+
a.write_uid,
62+
a.write_date
63+
FROM ir_attachment_product_template_rel AS rel
64+
JOIN ir_attachment AS a ON rel.ir_attachment_id = a.id
65+
RETURNING id
66+
""",
67+
)
68+
new_attachment_ids = [x[0] for x in env.cr.fetchall()]
69+
openupgrade.logged_query(
70+
env.cr,
71+
"""
72+
INSERT INTO product_document (
73+
ir_attachment_id,
74+
sequence,
75+
active,
76+
shown_on_product_page,
77+
create_uid,
78+
create_date,
79+
write_uid,
80+
write_date
81+
)
82+
SELECT
83+
a.id,
84+
10,
85+
true,
86+
true,
87+
a.create_uid,
88+
a.create_date,
89+
a.write_uid,
90+
a.write_date
91+
FROM ir_attachment a
92+
WHERE a.id IN %s
93+
""",
94+
(tuple(new_attachment_ids),),
95+
)
96+
97+
2198
@openupgrade.migrate()
2299
def migrate(env, version):
23100
_convert_product_ribbon_html_to_name(env)
101+
_website_sale_product_attachment(env)
24102
openupgrade.logged_query(
25103
env.cr,
26104
"""

0 commit comments

Comments
 (0)