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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="menu_shop" model="website.menu">
<field name="name">Shop</field>
<field name="url">/shop</field>
<field name="parent_id" ref="website.main_menu"/>
<field name="sequence" type="int">20</field>
</record>
<record id="action_open_website" model="ir.actions.act_url">
<field name="name">Website Shop</field>
<field name="target">self</field>
<field name="url">/shop</field>
</record>
<record id="base.open_menu" model="ir.actions.todo">
<field name="action_id" ref="action_open_website"/>
<field name="state">open</field>
</record>
<record id="website_sale.sale_ribbon" model="product.ribbon">
<field name="html">Sale</field>
<field name="html_class">bg-success o_ribbon_left</field>
</record>
<record id="website_sale.sold_out_ribbon" model="product.ribbon">
<field name="html">Sold out</field>
<field name="html_class">bg-danger o_ribbon_left</field>
</record>
<record id="website_sale.new_ribbon" model="product.ribbon">
<field name="html">New!</field>
<field name="html_class">bg-primary o_ribbon_left</field>
</record>
<record id="sales_team.salesteam_website_sales" model="crm.team">
<field name="active" eval="True"/>
</record>
<record model="website" id="website.default_website">
<field name="salesteam_id" ref="sales_team.salesteam_website_sales"/>
</record>
<record model="product.pricelist" id="product.list0">
<field name="selectable" eval="True" />
<field name="website_id" eval="False"/>
</record>
</data>
<data>
<!-- Action Server for Dynamic Filter -->
<record id="dynamic_snippet_products_action" model="ir.actions.server">
<field name="name">Products Dynamic Snippet</field>
<field name="model_id" ref="model_product_product"/>
<field name="state">code</field>
<field name="code">
ProductProduct = model.env['product.product']
FieldMonetary = model.env['ir.qweb.field.monetary']
website = request.website.get_current_website()
dynamic_filter = model.env.context.get('dynamic_filter')
limit = model.env.context.get('limit')
search_domain = model.env.context.get('search_domain')
get_rendering_data_structure = model.env.context.get('get_rendering_data_structure')
escape = dynamic_filter.escape_falsy_as_empty
domain = [('website_published', '=', True)] + website.website_domain() + (search_domain or [])
products = ProductProduct.search(domain, limit=limit)
_ = products.mapped('name')
monetary_options = {
'display_currency': request.website.get_current_pricelist().currency_id,
}
max_nb_chars = 100
res_products = []
for product in products:
res_product = product._read_format(['id', 'name', 'website_url', 'description_sale'])[0]
res_product.update(product._get_combination_info_variant())
if res_product['description_sale'] and len(res_product['description_sale']) > max_nb_chars:
res_product['description_sale'] = "%s ..." % res_product['description_sale'][:max_nb_chars]
res_product['list_price'] = FieldMonetary.value_to_html(res_product['price'], monetary_options)
data = get_rendering_data_structure()
for field_name in dynamic_filter.field_names.split(","):
field = ProductProduct._fields.get(field_name)
if field and field.type == 'binary':
data['image_fields'][field_name] = escape(website.image_url(product, field_name))
elif field_name == 'list_price':
data['fields'][field_name] = res_product[field_name]
else:
data['fields'][field_name] = escape(res_product[field_name])
data['fields']['call_to_action_url'] = escape(product['website_url'])
res_products.append(data)
response = res_products
</field>
</record>
<!-- Dynamic Filter -->
<record id="dynamic_filter_demo_products" model="website.snippet.filter">
<field name="action_server_id" ref="website_sale.dynamic_snippet_products_action"/>
<field name="field_names">display_name,description_sale,image_512,list_price</field>
<field name="limit" eval="16"/>
<field name="name">Products</field>
<field name="website_id" ref="website.default_website"/>
</record>
<function model="ir.model.fields" name="formbuilder_whitelist">
<value>sale.order</value>
<value eval="[
'client_order_ref',
]"/>
</function>
<record id="base.model_res_partner" model="ir.model">
<field name="website_form_key">create_customer</field>
<field name="website_form_access">True</field>
<field name="website_form_label">Create a Customer</field>
</record>
<function model="ir.model.fields" name="formbuilder_whitelist">
<value>res.partner</value>
<value eval="[
'name', 'phone', 'email',
'city', 'zip', 'street', 'street2', 'state_id', 'country_id',
'vat', 'company_name'
]"/>
</function>
</data>
</odoo>
|