MissingError Template: web.external_layout - odoo

I am trying to create a report in Odoo 12. But I come across an issue.
<template id="applicant_contract_offering_document">
<t t-call="web.external_layout">
<div class="header tahoma underline_bold center font_size_11">
<p>OFFICIAL OFFERING LETTER</p>
</div>
</t>
</template>
<template id="applicant_contract_offering">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="fhid_recruitment.applicant_contract_offering_document" />
</t>
</t>
</template>
Odoo always gives me
Error to render compiling AST
MissingError: ('Record does not exist or has been deleted.\n\n(Records: [4], User:2)', None)
Template: web.external_layout
What am I missing? I can print without web.external_layout but it seems the CSS is not applied to the body of the report.

At the file manifest.py add web in the list of dependencies.

This error message is very misleading. I urge every developer who encounter this kind of error message to try to check their codes again.
In my case, it was caused by empty record id.

Related

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

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

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.

Inherit a qweb template (t-name) in odoo 10

I am trying to extend a qweb template view. But it's not working.
Here is my code.
my_module/static/src/xml/website.xml
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="website.homepage_editor_welcome_message" >
<t t-jquery=".lead" t-operation="replace">
<p class="lead second_head">Let's start designing.</p>
</t>
</t>
</templates>
Here is the original code from the website module.
<div t-name="website.homepage_editor_welcome_message" class="container text-center o_homepage_editor_welcome_message">
<h2 class="mt0">Welcome to your <b>Homepage</b>!</h2>
<p class="lead">Let's start designing.</p>
<div class="o_tooltip_container">Follow all the <div class="o_tooltip bottom"/> signs to get your website ready in no time.</div>
</div>
And add the XML file in __manifest__.py like below.
'qweb': ['static/src/xml/website.xml'],
But no change in website.
How can i do it?
The only way I was able to find to be able to inherit a Qweb template declared with t-name is to redefine it in your custom module, change the code directly. You will be overriding the existing one.

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

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>