Skip to content

Commit 6da519a

Browse files
committed
Add dynamic content snippet
1 parent 0644d2b commit 6da519a

File tree

8 files changed

+143
-0
lines changed

8 files changed

+143
-0
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.languageServer": "None"
3+
}

website_dynamic_snippet/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import controllers
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
'name': 'Website Dynamic Snippet',
3+
'version': '18.0.1.0.0',
4+
'category': 'Website',
5+
'depends': ['website_sale'],
6+
'data': [
7+
'views/snippets/snippet_templates.xml',
8+
],
9+
'assets': {
10+
'web.assets_frontend': [
11+
'/website_dynamic_snippet/static/src/xml/sale_order_snippets.xml',
12+
'/website_dynamic_snippet/static/src/js/dynamic_snippet_sale_orders.js',
13+
],
14+
},
15+
'installable': True,
16+
'application': True,
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from odoo import http
2+
from odoo.http import request
3+
4+
class WebsiteProduct(http.Controller):
5+
@http.route('/get_product_categories', auth="public", type='json', website=True)
6+
def get_product_category(self, offset=0, limit=10):
7+
"""Get the website categories (or sale orders) for the snippet."""
8+
sale_orders = request.env['sale.order'].sudo().search_read(
9+
[],
10+
fields=['id', 'partner_id', 'state'],
11+
offset=offset,
12+
limit=limit,
13+
order='id asc',
14+
)
15+
return sale_orders
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { renderToElement } from "@web/core/utils/render";
2+
import publicWidget from "@web/legacy/js/public/public_widget";
3+
import { rpc } from "@web/core/network/rpc";
4+
5+
publicWidget.registry.get_product_tab = publicWidget.Widget.extend({
6+
selector: '.categories_section',
7+
8+
async willStart() {
9+
this.offset = 0;
10+
this.limit = 10;
11+
await this.loadCategories();
12+
},
13+
14+
async loadCategories() {
15+
const result = await rpc('/get_product_categories', {
16+
offset: this.offset,
17+
limit: this.limit,
18+
});
19+
if (result && result.length) {
20+
const newContent = renderToElement('website_dynamic_snippet.sale_order_snippet', { result: result });
21+
if(this.offset === 0) {
22+
this.$target.empty().append(newContent);
23+
} else {
24+
const $newRows = $(newContent).find('tbody').children('tr');
25+
this.$target.find('tbody').append($newRows);
26+
}
27+
this.offset += result.length;
28+
} else {
29+
this.$target.find('.load-more-button').hide();
30+
}
31+
},
32+
33+
events: {
34+
'click .load-more-button': '_onLoadMoreClick',
35+
},
36+
37+
async _onLoadMoreClick(ev) {
38+
ev.preventDefault();
39+
await this.loadCategories();
40+
},
41+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Sale Order tab content template -->
3+
<templates xml:space="preserve">
4+
<t t-name="website_dynamic_snippet.sale_order_snippet">
5+
<section class="categories_section">
6+
<div class="container">
7+
<h3 class="section_heading">Sale Order Details</h3>
8+
<div class="categories_wrapper">
9+
<div class="categories">
10+
<table class="table">
11+
<thead>
12+
<tr>
13+
<th scope="col">Number</th>
14+
<th scope="col">Customer Name</th>
15+
<th scope="col">Status</th>
16+
</tr>
17+
</thead>
18+
<tbody>
19+
<t t-foreach="result" t-as="sale_order" t-key="sale_order.id">
20+
<tr>
21+
<th scope="row">
22+
<t t-esc="sale_order.id"/>
23+
</th>
24+
<td><t t-esc="sale_order.partner_id[1]"/></td>
25+
<td><t t-esc="sale_order.state"/></td>
26+
</tr>
27+
</t>
28+
</tbody>
29+
</table>
30+
31+
<div class="text-center mt-3">
32+
<button type="button" class="btn btn-primary load-more-button">
33+
Load More
34+
</button>
35+
</div>
36+
37+
</div>
38+
</div>
39+
</div>
40+
</section>
41+
</t>
42+
</templates>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
4+
<template id="sale_order_highlight" name="Category Highlight">
5+
<section class="categories_section">
6+
<div class="container">
7+
<div class="alert alert-info">
8+
<h4>Your Category Highlight Tab snippet will be displayed here...
9+
Please save to view the snippet
10+
</h4>
11+
</div>
12+
</div>
13+
</section>
14+
</template>
15+
16+
<template id="category_highlight_snippet" inherit_id="website.snippets"
17+
name="Category Highlight Snippet">
18+
<xpath expr="//snippets[@id='snippet_groups']" position="inside">
19+
<t t-snippet="website_dynamic_snippet.sale_order_highlight"/>
20+
</xpath>
21+
</template>
22+
23+
</odoo>

0 commit comments

Comments
 (0)