How to do a report in odoo 11 - report

I'm a beginner on Odoo and I want to customize the report that already exists in sale and so I made an inherit of sale But my code shows me an error that is:
Error while validating the constraint .... cannot be located in the parent view
In addition to that if I execute just the first part it works but it directly modifies the report of dirty but the report in my module is remain empty.
Here is the code:
<template id="report_real_estate_rental_in" inherit_id="sale.report_saleorder_document">
<xpath expr="//span[#t-field='doc.name']" position="after">
<p>JE SUIS LA</p>
</xpath>
</template>
<template id="report_real_estate_rental">
<t t-call = "web.html_container" >
<t t-foreach = "docs" t-as = "o" >
<t t-call = "web.external_layout" >
<div class = "page" >
<t t-call="report_real_estate_rental_in"/>
</div>
</t>
</t>
</t>
</template>

This error usually occurs when xpath expression cannot be located in parent view. Please make sure the xpath expression is correct and template id you're inheriting is correct. Check out this link for inheriting and modifying existing report in Odoo.

If i got the question as you meant , when you use t-call you have to include the module name also , so it will be module_name.template_id.
In your case , change it as <t t-call="your_module_name.report_real_estate_rental_in"/>

Related

I am having trouble creating and updating a dictionary by using the below code

For creating a dict, i used the following code:
<t t-set="count" t-value="dict()"/>
<t t-foreach="count_obj" t-as="ob">
<t t-set="count" t-esc="count.update({ob.id: ob.name})"/>
</t>
But i am getting a none value.Why?
Can anyone help me?Thanks in advance..
shahinsha ummer
You have to specify the value in dict form when you try setting the value
[<t t-set="variable" t-value=""/>].
In your example, there is no need to set the variable before the loop with dictionary form it will do nothing.
<t t-foreach="count_obj" t-as="ob">
<t t-set="count" t-value="{ob.id: ob.name}"/> <!-- Set the Value in form of dictionar -->
<span t-esc="count"/>
</t>

How to print invoice reference in each invoice page for only invoices report?

I need the show invoice reference on invoice report in header. which is just like that "Draft Invoice: ~ AR-2018/0303". It is on the first page only and i need to display on every page.
I try to that: ~
<template id="external_layout_header_inherited" inherit_id="report.external_layout_header">
<xpath expr="//div[#class='header']" position="inside">
<div t-if="o.number">Ref.: <span t-field="o.number"/></div>
</xpath>
</template>
But when I print the other Report Just like Sale or Purchase It effect all the report.
So, My Question is that how to print invoice reference on Invoice report starting of Second page also?
You are in the right way, but in your invoice report, you need call a custom external_layout that call a custom header like this
<t t-call="report.external_layout_custom">
<t t-call="report.external_layout_header_custom" />
<t t-raw="0" />
<t t-call="report.external_layout_footer_custom" />
</t>
</t>

How Can I parse and convert Dates & Times?

I met Odoo for first time a little less than a month ago, and, a DOS Systems Analyst from the 90's, am helping to implement it for a small but fast growing local manufacturer. Largely out of the industry the last 15 years, I'm not pro, but fast learning Python, HTML (some past exper) and Java...
I've been through the Developer Docs, as well as the Developer's Cookbook & Essentials, and a variety of online tutorials (just about everything Google could come up with from several search word combinations).
I read the closed post asking about this and get that there's apparently no actual Odoo reference...
Can someone please tell me where I might find 'date/time' parse and conversion functions that I can access from a report that is using the 'canned' 'hr.employee' model?
<?xml version="1.0"?>
<t t-name="hr_attendance.report_attendancelog">
<t t-call="report.html_container">
<t t-call="report.external_layout">
<div class="page">
<div class="oe_structure"/>
<div class="row">
<div class="col-xs-6">
<h2><br/>Attendance Log: </h2>
</div>
</div>
<table class="table table-condensed mt32">
<thead>
<th><strong>Date / Time</strong></th>
<th><strong> Operation</strong></th>
</thead>
<tbody>
<t t-foreach="docs" t-as="o">
<t t-set="DspDate" t-value="o.name"/>
<t t-set="DspTime" t-value="o.name"/>
<!-- I want to parse 'o.name', which is 'date time' format (from
Attendance record) to separate 'Date' and 'Time' fields... -->
<!-- t t-set="DspDate" t-value="FUNC?(o.name)"/ -->
<!-- t t-set="DspTime" t-value="FUNC?(o.name)"/ -->
<!-- and do calcs with date & time...) -->
<!-- t t-set="ClcDt1" t-value="FUNC?('PrvDt')"/ -->
<!-- t t-set="ClcDt2" t-value="FUNC?(DspDate)"/ -->
<!-- t t-set="ClcTm1" t-value="FUNC?('PrvTm')"/ -->
<!-- t t-set="ClcTm2" t-value="FUNC?(DspTime)"/ -->
<tr>
<t t-if="ClcDt1 == ClcDt2">
<td><span t-esc="DspDate"/></td>
<td><span t-esc="DspTime"/></td>
<td><span t-esc="o.action"/></td>
</t
</tr>
</t>
<tr class="border-black">
<td colspan="3"><strong>Total period</strong></td>
<td><strong t-esc="o.worked_hours"/></td -->
</tr>
</tbody>
</table>
</div>
</t>
</t>
</t>
I prefixed 'br/' to H2 to keep the it properly positioned (only shows on the first page), but subsequent pages obscure the col headers behind the layout header... this is probably obvious and I'm oblivious, but how can I adjust the 'H2' position to be below the 'header' setup by 'report.external_layout'??
On QWeb rendering you can use the python libs time, datetime and relativedelta. They are included in the so called QWeb context which is used for the evaluation (python eval) of the code in reports. You can see this in Odoo code here.
That means you do something like this:
<t t-set="DspDate" t-value="datetime.datetime.strptime(o.name, '%Y-%m-%d %H:%M:%S').strftime('%d/%m/%Y')" />
I prefer parser classes for reports to define some common functions. For example: you can define the function getDate doing your parsing or transforming stuff. The report code will be much better with parser functions:
<t t-set="DspDate" t-value="getDate(o.name)" />

Data available ("this") from a template event handler

projects.html
{{#if projects}}
{{#each projects}}
<div class="project-item">
<div class="project-name">
{{name}}
</div>
<div class="project-settings">
<span class="rename">Rename</span>
<span class="edit">Edit</span>
<span class="delete">
<!-- Here -->
</span>
</div>
</div>
{{/each}}
{{/if}}
projects.js
Template.Projects.events({
"click .project-item .delete": function (e, template) {
e.preventDefault();
debugger
// "this" refers to the specific project
}
});
In an event handler, I noticed "this" conveniently refers to a specific object inside the template where the event is related to. For example, in this case, the delete button is inside each projects block, and the handler for the delete button has this = some project. This is convenient, but I'd like to know the scopes and rules more completely. Can someone explain in briefly and point me to the right document?
This is a data context sensitive feature. Basically, there is a lexical scope in spacebars helpers. Have a look at this: http://devblog.me/no-data-context.html
The original pull request is here: https://github.com/meteor/meteor/pull/3560

how to add a user defined header in a rml report in openerp?

How can I add a new header/footer for a report(for example picking list report in delivery order) other than the header/ footer defined in the company?
In report tag put header='False',
eg.
<report header='False' auto="False" id="report_product_history"
model="product.product" name="stock.product.history"
string="Stock Level Forecast"/>
it will not print the default header define in the company.
then in rml file find <pageTemplate> tag, and replace it with your rml code.
eg.
<template pageSize="(595.0,842.0)" title="Test"
author="Atul Makwana" allowSplitting="20">
<pageTemplate id="first">
***Your rml header & footer***
</pageTemplate>
</template>
This way you can put new header and footer.
One way to remove the header is what Atul suggested, declare it in the report tag.
<report
header="False"
auto="False"
id="report_product_history"
model="product.product"
name="stock.product.history"
string="Stock Level Forecast"/>
In some situations there is no report tag. For example, a report might only be generated by a wizard. In that case, you can declare it as a parameter when you register the parser. See the mrp_operations module's barcode report for an example.
class code_barcode(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(code_barcode, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
})
report_sxw.report_sxw('report.mrp.code.barcode',
'mrp_operations.operation.code',
'addons/mrp_operations/report/mrp_code_barcode.rml',
parser=code_barcode,
header=False)
You can also specify a specific header using that parameter. It defaults to 'external', but it can be 'internal' or 'internal landscape' to use one of the other headers from the company configuration.
In report set header = 'False'
Now you can add your own header footer on page
<template title="Test" author="Sagar" allowSplitting="20">
<pageTemplate id="first">
<frame id="first" x1="15.0" y1="42.0" width="539" height="758"/>
<pageGraphics>
<!-- ================== Header =============== -->
<image x="14cm" y="25.6cm" height="40.0">[[ company.logo or removeParentNode('image') ]]</image>
<setFont name="Helvetica" size="10.0"/>
<drawString x="1cm" y="27.2cm">Main Header</drawString>
<!-- Order Details -->
<place x="33" y="18cm" width="530.0" height="205.0">
<blockTable colWidths="265,265" style="Table1">
<tr>
<td>Header Value 1</td>
<td><para style="normal2-center">Header Value 2</para></td>
</tr>
</blockTable>
</place>
<!-- ======================== footer =========================== -->
<place x="33" y="55cm" width="530.0" height="205.0">
<blockTable colWidths="265" style="Table1">
<tr><td><para style="normal2-center">Footer Value</para></td></tr>
</blockTable>
</place>
</pageGraphics>
</pageTemplate>
</template>
You can customize report header in your report.rml file like this,
<pageTemplate id="first">
<frame id="first" x1="57.0" y1="115.0" width="481" height="615"/>
<header>
<pageGraphics>
<image x="1.3cm" y="26.0cm" height="90.0">[[company.logo or removeParentNode('image')]]</image>
<drawString x="10.9cm" y="2.9cm">Signature:</drawString>
<drawString x="12.7cm" y="2.9cm">___________________________________</drawString>
</pageGraphics>
</header>
</pageTemplate>

Resources