Files
odoo_source/addons/website_sale/data/data.xml
T
Jeremy Kersten 550d2935bd [IMP] website: support generic website for dynamic snippet filters
Made the website_id non mandatory on website snippet filters and adapted
the fetching route so that it interprets an unspecified website_id as
the filter being available on any website.

Before this commit website snippet filters had to be limited to one
single website.

After this commit website snippet filters can be made available on all
websites by setting their website_id to no value (this is the new
default of the pre-defined filters).

https://github.com/odoo/odoo/pull/59831
task-2355369

closes odoo/odoo#59831

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2020-10-13 13:09:45 +00:00

128 lines
5.2 KiB
XML

<?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>
</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>