How to render data from the external model in divs of a view? - odoo

I need your help, I have some divs in a view in odoo 13, I need to bring the data from an external model "maintenance.stage" render them in those divs, can someone give me an example of how to do it with a controller to bring those logs and be able to display them in those divs? every time i add a new record it should render in those divs.
enter image description here
enter image description here

I hope this helps,
This is a controller exemple:
class ControllerExemple(http.Controller):
#http.route('/path/', auth='public', type='http',
methods=["GET","POST"], website=True)
def function_exemple(self):
obj = request.env['maintenance.stage'].browse(<id>)
return request.render("module.your_view_id", {'object': obj})
There is a exemple view :
<template id="your_view_id" name="Something">
<t t-call="website.layout">
<div class="container">
<div><span t-out="object.the_field_you_need"/></div>
</div>
</t>
</template>
It seems that you have several values to display, so use the foreach in your template :
<template id="your_view_id" name="Something">
<t t-call="website.layout">
<t t-foreach="object.the_field_you_need" t-as="value">
<div class="container">
<div><span t-out="value"/></div>
</div>
</t>
</t>
</template>
https://odoo-master.readthedocs.io/en/master/reference/qweb.html

Related

extending javascript and qweb template in Odoo 15?

I am trying to tweak the odoo wysiwyg web_editor in Odoo 15, just adding a few font sizes as an example. But it does not seem to work.
What i have tried: I created a module to isolate the problem:
https://github.com/jwaes/jt_webeditor_extras
Manifest:
'assets' : {
'web.assets_qweb': [
'jt_webeditor_extras/static/src/xml/editor.xml',
],
'website.assets_wysiwyg': [
'jt_webeditor_extras/static/src/js/editor.js',
],
xml:
<!-- fiddling with https://github.com/odoo/odoo/blob/15.0/addons/web_editor/static/src/xml/editor.xml -->
<t t-extend="web_editor.toolbar">
<t t-jquery="#font-size ul li:nth-child(7)" t-operation="after">
<li>
<a class="dropdown-item" href="#" data-call="setFontSize" data-arg1="16px">16</a>
</li>
</t>
<t t-jquery="#font-size ul" t-operation="append">
<li>
<a class="dropdown-item" href="#" data-call="setFontSize" data-arg1="99px">99</a>
</li>
</t>
<!-- perhaps my jquery was wrong... so trying with a drastic one -->
<t t-jquery="#font" t-operation="replace" />
</t>
js:
odoo.define('jt_webeditor_extras.toolbar_extras', function (require) {
'use strict';
const weToolbar = require('web_editor.toolbar');
weToolbar.include({
xmlDependencies: (weToolbar.prototype.xmlDependencies || []).concat(
['/jt_webeditor_extras/static/src/xml/editor.xml']),
});
console.log(weToolbar.prototype.xmlDependencies);
});
The javascript console message was logged. so it was loaded.
There is a http call to the template xml from the frontend.
But the resulting UI is not altered.
Any idea what i am doing wrong ?
Remove the odoo tag and add web_editor to module depends entry.

How to link to other view when use oe_kanban_global_click

How to open tree view when click on kanban card when use
oe_kanban_global_click
It goes to form view but i want on click, goes to tree view. Below code i used:
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click">
<div class="o_kanban_record_bottom">
<div class="oe_kanban_bottom_left">
<span><strong>Weather: </strong><t t-esc="record.weather_type.value"/></span>
</div>
<div class="oe_kanban_bottom_right">
<span><strong>Humidity: </strong><t t-esc="record.humidity.value"/>%</span>
</div>
</div>
</div>
</t>
</templates>

Odoo check t-raw="0"

I have a template like this:
<template id="id1">
<h1>Title</h1>
<t t-raw="0"/>
</template>
And it is called like below:
<t t-call="id1">
<div>Hello<div>
</t>
Or like this:
<t t-call="id1"/>
The problem is that for the second type, there's [] in the HTML. Is there a way to check if "0" has any content?
Edit: I've tried
<t t-if="0" t-raw="0"/>
And it doesn't work.
if you have written in your template than whenever any template calls your template then body of the calling template is available as the raw value in variable '0'
for example
your template
<template id="id1">
<h1>Title</h1>
<t t-raw="0"/>
<h2> content after calling template</h2>
</template>
if you call like this
<t t-call="id1">
<div>Hello<div>
</t>
then output will be like this
<h1>Title</h1>
<div>Hello<div>
<h2> content after calling template</h2>
and if you call like this
<t t-call="id1"/>
<div>Hello<div>
then output will be like this
<h1>Title</h1>
<h2> content after calling template</h2>
<div>Hello<div>
I hope this is helpful to understand the concept

Can't remove custom Odoo snippet

I created a custom snippet on Odoo 8. Basically it is a slideshow component from uikit that I want to insert as a content inside .row bootstrap elements, that is, inside another snippet. Below is my code. However, when I try to remove the slideshow snippet via the Website builder (not the HTML Editor), it still appears after saving. The only way I can remove it is by editing it from the HTML Editor. What could be wrong?
<openerp>
<data>
<template id="snippet_blocks" inherit_id="website.snippets" name="Snippet Blocks">
<!-- Create new group called Essentials-->
<xpath expr="div[1]/ul" position="inside">
<li>
Essentials
</li>
</xpath>
<xpath expr="div/div/div[#id='snippet_effect']" position="after">
<div id="snippet_essentials" class="tab-pane">
<!-- Slideshow Snippet -->
<div class="we_snippet">
<!-- Snippet thumnail-->
<div class="oe_snippet_thumbnail">
<img class="oe_snippet_thumbnail_img"
src="/sci5_website_essentials/static/img/slideshow.png"/>
<span class="oe_snippet_thumbnail_title">Slideshow</span>
</div>
<!-- Snippet code to insert-->
<div class="oe_snippet_body we_slideshow col-md-8 mb128">
<t t-call="sci5_website_essentials.snippet_slideshow"/>
</div>
</div>
</div>
</xpath>
</template>
<template id="snippet_options" inherit_id="website.snippet_options" name="Snippet Options">
<xpath expr="." position="inside">
<div data-snippet-option-id='snippet_essentials'
data-selector=".we_slideshow"
data-selector-siblings=".row > [class*='col-md-']"
data-selector-children=".row">
</div>
</xpath>
</template>
</data>
</openerp>
This is the snippet body:
<openerp>
<data>
<template id="snippet_slideshow" name="Slideshow">
<section class="snippet_slideshow">
<ul class="uk-slideshow" data-uk-slideshow="{autoplay:true}">
<li>
<img src="/website/static/src/img/library/business_conference.jpg"/>
</li>
<li>
<img src="/website/static/src/img/library/gears.png"/>
</li>
<li>
<img src="/website/static/src/img/library/engineer.jpg"/>
</li>
</ul>
</section>
</template>
</data>
</openerp>
I recently solved it by placing the snippet block's template to the snippets template itself. Apparently there is a problem with calling the subtemplate.
When I drag the snippet inside another snippet, I'm actually dragging the <t t-call="template_name"> tag into another snippet. It means that one cannot change the template right in where it is dragged but only by editing the subtemplate itself, which means that when it is dragged into some other template, the changes is inherited, and which is very unlikely expected.
Go to Settings, and clear all those snippet things from particular view file.
Settings -> General Settings -> User Interface -> Views
Then,
Find your
view & edit it
.
Clear template code which you cant to clear.
Note : Before delete any section please correct one time it.

OpenERP - QWeb report

I'm writing a module on Odoo (OpenERP) v.8 to allow timesheet's print.
I'm using QWeb report type, but I can't use the fields that I need to use.
If I call a field from res_company module, it works correctly.
<template id="report_timesheet_document">
<t t-call="report.external_layout">
<div class="page">
<div class="row">
<div>
<span t-esc="res_company.name"/>
</div>
</div>
If I call a field from other modules, like res_partner, it doesn't work.
I can't use fields from the current object (timesheet, inherited from hr_timesheet_sheet.sheet).
If I use t-esc:
<span t-esc="o.date_from"/>
QWebException: "'NoneType' object has no attribute 'date_from'" while
evaluating 'o.date_from'
If I use t-field
<span t-field="o.date_from"/>
QWebException: 'NoneType' object has no attribute '_all_columns'
How can I resolve? Thanks.
Fixed:
<template id="report_timesheet">
<t t-call="report.html_container">
<t t-foreach="doc_ids" t-as="doc_id">
<t t-raw="translate_doc(doc_id, doc_model, 'user_id.partner_id.lang', 'hr_timesheet_print.report_timesheet_document')"/>
</t>
</t>
</template>