forked from OCA/e-commerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct_template.py
48 lines (42 loc) · 1.68 KB
/
product_template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright 2020 Tecnativa - Jairo Llopis
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from odoo import api, fields, models
from odoo.addons.website.models import ir_http
class ProductTemplate(models.Model):
_inherit = "product.template"
website_attachment_ids = fields.Many2many(
string="Website attachments",
comodel_name="ir.attachment",
context={"default_public": True, "hide_attachment_products": True},
domain=lambda self, *args, **kwargs: (
self._domain_website_attachment_ids(*args, **kwargs)
),
help="Files publicly downloadable from the product eCommerce page.",
)
@api.model
def _domain_website_attachment_ids(self):
"""Get domain for website attachments."""
domain = [
# Only use public attachments
("public", "=", True),
# Exclude Odoo asset files to avoid confusing the user
"!",
("name", "=ilike", "%.assets%.js"),
"!",
("name", "=ilike", "%.assets%.css"),
"!",
("name", "=ilike", "web_editor%"),
"!",
("name", "=ilike", "/web/content/%.assets%.js"),
"!",
("name", "=ilike", "/web/content/%.assets%.css"),
"!",
("name", "=ilike", r"/web/content/%/web\_editor.summernote%.js"),
"!",
("name", "=ilike", r"/web/content/%/web\_editor.summernote%.css"),
]
# Filter by website domain in frontend
if ir_http.get_request_website():
website = self.env["website"].get_current_website()
domain += website.website_domain()
return domain