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>
Related
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
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.
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.
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
I want to create a new theme for odoo. I have done it by create a new module and install it. I see in this document here which said that odoo support template inheritance by using t-extend keyword. However I can't make it.
This is my customized template:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="website.homepage" name="Homepage" page="True">
<div class="header">
<h1>FOO<h1>
<div class="main">
</div>
</div>
</template>
<template id="website.contact" name="Homepage" page="True">
<t t-extend="website.homepage">
<t t-jquery="div.main" t-operation="inner">
<h1>FOO 2</h1>
</t>
</t>
</template>
</data>
</openerp>
Template website.contact should have showed FOO and FOO 2 but it only showed FOO 2.
Please help me explain it. Thanks.
You use a syntax for client side templates, but those are server side templates. You use inheritance with server side templates this:
<template id="contact" inherit_id="website.homepage">
<xpath expr="//div[#class='main']" position="inside">
<h1>FOO 2</h1>
</xpath>
</template>
You can read more in the official documentation.
You are trying to create new theme.? and are you using odoo 8.0.? I am asking this because the link you posted is for OpenERP 7.0
So for Odoo 8.0 new documentation is available see here and for QWEB you can find it here QWEB.
Now Main thing if you are trying to create new theme for CMS or Website module then you must go through these steps.
Using Xpath here you can Inherit and make changes on parent tempaltes, examples follows.
<template id="homepage_extend" inherit_id="website.homepage">
<xpath expr="//div[#class='main']" position='inside'>
<h1>FOO 2</h1>
</xpath>
</template>
or try
<template id="homepage_extend" inherit_id="website.homepage">
<xpath expr="//div[#class='header']" position='replace'>
<div class="header">
<h1>FOO<h1>
<div class="main">
<h1>FOO 2</h1>
</div>
</div>
</xpath>
</template>
You can also try these by overriding that template like:
<template id="website.homepage">
<div class="header">
<h1>FOO<h1>
<div class="main">
<h1>FOO 2<h1>
</div>
</div>
</template>
while overriding don't forget to gave the exact id followed by module name.
Cheers !
In parent template, add <t t-raw="0"/> or <t t-raw="name"/>, template: ...code html...
https://www.odoo.com/documentation/9.0/reference/qweb.html
Hello Minh-Hung Nguyen,
Try this code,
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="website.homepage" name="Homepage" page="True">
<div class="header">
<h1>FOO<h1>
<div class="main">
</div>
</div>
</template>
<template id="website.contact" name="Homepage" page="True">
<t t-extend="website.homepage">
<!-- Use 'append' to add the h1 tag inside main div -->
<t t-jquery="main" t-operation="append">
<h1>FOO 2</h1>
</t>
</t>
</template>
</data>
</openerp>
I hope my answer is helpfull for you.