QWebException: "'NoneType' object is not callable" while evaluating 'has_shortage_so_lines(data)==True' - xls

I found the another question at here. But there is no answer.
I got the error
QWebException: "'NoneType' object is not callable" while evaluating 'has_shortage_so_lines(data)==True'
This is my report_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- External Consumption Report -->
<!-- Landscape Paper Format-->
<record id="paperformat_LetterLandscape" model="report.paperformat">
<field name="name">US Letter Landscape</field>
<field name="default" eval="True"/>
<field name="format">Letter</field>
<field name="page_height">0</field>
<field name="page_width">0</field>
<field name="orientation">Landscape</field>
<field name="margin_top">15</field>
<field name="margin_bottom">15</field>
<field name="margin_left">2</field>
<field name="margin_right">2</field>
<field name="header_line" eval="False"/>
<field name="header_spacing">7</field>
<field name="dpi">100</field>
</record>
<!--Report XLS-->
<report
id="action_report_shortage_xls"
model="sale.order"
string="Shortage Report"
report_type="qweb-html"
name="sale.report_shortage_xls"
file="sale.report_shortage_xls"/>
<!--Paper Format to shortage report-->
<record id="action_report_shortage_xls" model="ir.actions.report.xml">
<field name="paperformat_id" ref="stock.paperformat_LetterLandscape"/>
</record>
</data>
</openerp>
This is my report_xls.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Translatable template -->
<template id="report_shortage_xls">
<div class="workbook">
<div class="worksheet" name="Shortage Report">
<table>
<tbody>
<tr>
<td easyfx="font: height 200;align: horizontal left,vert center">Printed On :</td>
<td><span t-usertime="%d-%m-%Y %H:%M" /></td>
</tr>
<tr>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th colspan="17" easyfx="font: height 400, bold on;align: horizontal center,vert center">Shortage Report</th>
</tr>
<!--<tr>
<th>
<span t-esc="has_shortage_so_lines(o.id)"/>
</th>
</tr>-->
</thead>
</table>
<t t-if="has_shortage_so_lines(data)==True">
<table>
<thead>
<tr>
<th easyfx="font:height 200, bold on;align: horizontal center,vert center;">Date</th>
<th easyfx="font:height 200, bold on;align: horizontal center,vert center;">SO No</th>
<th easyfx="font:height 200, bold on;align: horizontal center,vert center;">Customer Ref No</th>
</tr>
</thead>
</table>
</t>
</div>
</div>
</template>
<!-- Main template -->
<template id="xls_report_shortage">
<t t-call="report.html_container">
<t t-foreach="doc_ids" t-as="doc_id">
<t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'sale.report_shortage_xls')"/>
</t>
</t>
</template>
</data>
</openerp>
This is my report.py
class ShortageReport(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(ShortageReport, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'get_date_from': self.get_date_from,
'get_date_to': self.get_date_to,
'has_shortage_so_lines': self.has_shortage_so_lines,
'get_shortage_lines': self.get_shortage_lines,
})
def has_shortage_so_lines(self, order_id):
_logger.info("sale order id >>> : %r", order_id)
lines_obj = self.get_shortage_so_lines(order_id)
if lines_obj:
return True
return False
class report_shortage_xls(osv.AbstractModel):#(models.AbstractModel):
_name = 'report.stock.report_shortage_xls'
_inherit = 'report.abstract_report'
_template = 'stock.report_shortage_xls'
_wrapped_report_class = ShortageReport
Is there any way to export the xls from odoo. Thank you so much for your helping.

Make sure here
_template = 'stock.report_shortage_xls'
it must be module name with report name, you have created report for sale.order and you have given stock module name, is it correct in your case ?
For more information you should refer our blog on Qweb Report.

Related

ODOO my header doesn't appears in my custom report

I have some trouble with my report header in odoo.
I can't make it appears correctly.
I've made a custom report here's the code:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="report_timesheet">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="doc">
<div class="page">
<t t-call="report.external_layout">
#SOMESTUFF
</t>
</div>
</t>
</t>
</template>
</data>
</odoo>
The thing is my header appears twice when I run this code, I've seen from standard module example that the line
<t t-call="report.external_layout">
should be before
<div class="page">
but when I do that the header doesn't appear at all. Does anyone have any idea about what's going wrong with this?
You can create your report as following:
<template id="report_invoice_document">
<t t-call="report.external_layout">
....
</t>
</template>
<template id="report_invoice">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="account.report_invoice_document" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>

Generate report from wizard in odoo 9

I need help about generate report from wizard in odoo 9. On internet I'm find one unfinished example. I want get all user is res.user where create_date (field in res.users) >= date_from and =< date_to from my wizzard.
My source:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_my_wiz_form" model="ir.ui.view">
<field name="name">print.report.form</field>
<field name="model">my.test.report</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Print Report">
<group colspan="4" >
<field name="date_from"/>
<field name="date_to" />
</group>
<group colspan="4" col="6">
<button name="print_report" string="Print Users" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_my_wiz_form" model="ir.actions.act_window">
<field name="name">Print Report</field>
<field name="res_model">my.test.report</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_my_wiz_form"/>
<field name="target">new</field>
</record>
<menuitem name="REPORT" id="menu_my_test_report" action="action_my_wiz_form" sequence="19"/>
</data>
</openerp>
.py file
class my_test_report(models.Model):
_name = 'my.test.report'
_description = 'Test Report'
date_from = fields.Date(string = 'From')
date_to = fields.Date(string = 'To')
def print_report(self, cr, uid, ids, context=None):
datas = {}
if context is None:
context = {}
data = self.read(cr, uid, ids,['date_from', 'date_to'], context=context)
date_from = data[0]['date_from']
date_to = data[0]['date_to']
obj = self.pool.get('res.users')
ids = obj.search(cr, uid, [('create_date','>=',date_from),('create_date','<=',date_to)])
print(ids)
datas = {
'ids': ids,
'model': 'res.users',
'form': data
}
return {
'type': 'ir.actions.report.xml',
'report_name': "XXXXXXX,
'datas': datas,
}
Hw create report_name in .py, I'm put XXXXXXXX with several fields from res.users?
After run code without
return {
'type': 'ir.actions.report.xml',
'report_name': "XXXXXXX,
'datas': datas,
}
in console get [3, 4]
I'm try with this xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_sasa_test">
<t t-call="report.html_container">
<t t-set="data_report_margin_top" t-value="12"/>
<t t-set="data_report_header_spacing" t-value="9"/>
<t t-set="data_report_dpi" t-value="110"/>
<t t-foreach="docs" t-as="o">
<div class="page">
<table class="table table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Test</th>
</tr>
</thead>
<tbody>
<tr>
<td><t t-esc="o.name"/></td>
<td><t t-esc="o.name"/></td>
</tr>
</tbody>
</table>
</div>
</t>
</t>
</template>
</odoo>
But after generate pdf i get two pdf page with one row i need all data on one page ---> https://postimg.org/image/gbdadtrm5/
Any solution how define this report?
etc.
id | login | signature
3 | 25.01.17 | ---
4 | 25.01.17 | ---
docs variable represents a record on your model by default unless you define it otherwise. I do not see you define it somewhere else here so your problem is that you have the t-foreach="docs" and then you create a page. The t-foreach="docs" should enclose the whole report view and not the page. Take a look at addons/account/views/report_invoince.xml as to how this loops works.
<template id="report_report_sasa_test">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="your_module.report_sasa_test" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>

Change flow of sequence of policies using Java Script in apigee?

If i want XSLTransform-1 policy to get executed only when the URL has "tennis" keyword in it,how can i do it using Java Script policy in apigee?
URL: http://shaleen-test.apigee.net/v1/espn--api/tennis/athletes/296? apikey=rgnmd3naaw2qwv79fdtjgz77
Policy:XSLTransform-1
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XSL async="false" continueOnError="false" enabled="true" name="xsltransform-1">
<DisplayName>XSLTransform-1</DisplayName>
<FaultRules/>
<Properties/>
<Source>response</Source>
<ResourceURL>xsl://xsltransform-1</ResourceURL>
<Parameters ignoreUnresolvedVariables="true"/>
<OutputVariable>abc</OutputVariable>
</XSL>
XSL File:xsltransform-1
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<xsl:template match="/">
<html>
<body>
<h1>PROFILE OF PLAYERS</h1>
<h2> <xsl:value-of select="Root/sports/name" /> </h2>
<h3>Report Details</h3>
<table border="1">
<tr bgcolor="#9acd32">
<th>PLAYER ID</th>
<th>FIRST NAME</th>
<th>LAST NAME</th>
<th>FULL NAME</th>
<th>SHORT NAME</th>
</tr>
<xsl:for-each select="Root/sports/leagues/athletes">
<tr>
<td><xsl:value-of select="id" /></td>
<td><xsl:value-of select="firstName" /></td>
<td><xsl:value-of select="lastName" /></td>
<td><xsl:value-of select="fullName" /></td>
<td><xsl:value-of select="shortName" /></td>
<!--<td><xsl:value-of select="Root/sports/leagues/athletes/id" /></td>
<td><xsl:value-of select="Root/sports/leagues/athletes/firstName" /></td>
<td><xsl:value-of select="Root/sports/leagues/athletes/lastName" /></td>
<td><xsl:value-of select="Root/sports/leagues/athletes/fullName" /></td>
<td><xsl:value-of select="Root/sports/leagues/athletes/shortName" /></td>-->
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
This can be achieved by have a conditional execution of the XSLT.You can use extract variables to extract a particular value from the request path.And if that variable's value is 'tennis' you can execute the XSLT Policy.
Is there any specific reason why you want to control the flow from Javascript?

Generating XSLT for the given XML. Error: Mismatch

I Have an XML something like this
<NavigatorItems>
<Navigator Name="Product">
<ModifierName>Product1</ModifierName>
<ModifierLink>www.Product1.com</ModifierLink>
<ModifierName>Product2</ModifierName>
<ModifierLink>www.Product2.com</ModifierLink>
<ShowAll>www.ProductMain.com</ShowAll>
</Navigator>
<Navigator Name="Article">
<ModifierName>Article1</ModifierName>
<ModifierLink>www.Article1.com</ModifierLink>
<ModifierName>Article2</ModifierName>
<ModifierLink>www.Article2.com</ModifierLink>
<ShowAll>www.ArticleMain.com</ShowAll>
</Navigator>
</NavigatorItems>
I Need to show something like this:
I tried the following XSLT but it throws some error (mismatch):
XML Parsing Error: mismatched tag. Expected: </ModifierName>
My Code:
<xsl:for-each select="NavigatorItems/Navigator">
<xsl:variable name="link" select="ModifierLink"/>
<tr>
<td><a href ="{$link}"><xsl:value-of select="ModifierName"/></td>
</tr>
<xsl:test select="ShowAll">
<xsl:variable name="linkShowAll" select="ShowAll"/>
<tr> <td> <a href="{$linkShowAll}"> View More Results <td> </tr>
</xsl:test>
</xsl:for-each>
Where Am I going wrong ? Please Suggest...
There were a number of problems with your code. I think I've fixed them all, but let me know if you have any problems with this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xsl:for-each select="NavigatorItems/Navigator">
<xsl:variable name="link" select="ModifierLink"/>
<tr>
<td>
<a><xsl:attribute name="href"><xsl:value-of select="ModifierLink"/></xsl:attribute><xsl:value-of select="ModifierName" /></a>
</td>
</tr>
<xsl:if test select="ShowAll != ''">
<tr>
<td>
<a><xsl:attribute name="href"><xsl:value-of select="ShowAll"/>View More Results</a>
</td>
</tr>
</xsl:test>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

How to reverse date format in XSLT?

I’m working on a site In that site some pages gets data from XML through XSLT. But the date is displayed as YYYY-MM-DD which ideally is taken from the XML which was in this format. I would like to convert this format to DD-MM-YYYY through XSLT or some other possible way.
Please suggest me an idea to go ahead or provide me the code to achieve this ASAP.
This is the format of xml giving
<published date="2009-09-28T07:06:00 CET" />
and i want to convert this into
<published date="28-09-2009T07:06:00 CET" />
and this is xsl file
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table class="bdr-bot" width="100%" border="0" cellspacing="0" cellpadding="0" style="clear:both">
<tr>
<th width="15%" class="bdr">Date</th>
<th class="bdr">Title</th>
</tr>
<xsl:for-each select="hexML/body/press_releases/press_release">
<xsl:if test="contains(published/#date, '2009')">
<tr>
<td valign="top">
<xsl:value-of select="substring-before(published/#date, 'T')"/>
</td>
<td valign="top">
<xsl:value-of select="headline"/>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
Now tell me the solution? is this possible with fn:reverse?
If the XML is in the format YYYY-MM-DD, you should be able to use Xpath's tokenize function to split up your string where - occurs, and then reorder it. Something akin to:
<xsl:variable name="dt" value="tokenize(Date, '-')"/>
<xsl:value-of select="concat(dt[3],'-',dt[2],'-',dt[1])"/>
This is just off the top of my head (and untested), but you get the general idea. You should be able to split up the date and reorder the pieces.
Assuming
<xml>
<date>2009-11-18</date>
</xml>
This XSLT 1.0 solution would do it:
<xsl:template match="date">
<xsl:copy>
<xsl:value-of select="
concat(
substring(., 9, 2),
'-',
substring(., 6, 2),
'-',
substring(., 1, 4)
)
" />
</xsl:copy>
</xsl:template>
If your date can be
<xml>
<date>2009-11-1</date>
</xml>
you would have to use the slightly more complicated
<xsl:template match="date">
<xsl:copy>
<xsl:value-of select="
concat(
substring-after(substring-after(., '-'), '-'),
'-',
substring-before(substring-after(., '-'), '-'),
'-',
substring-before(., '-')
)
" />
</xsl:copy>
</xsl:template>
you could also use a template.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:template match="/">
<html>
<body>
<table class="bdr-bot" width="100%" border="0" cellspacing="0" cellpadding="0" style="clear:both">
<tr>
<th width="15%" class="bdr">Date</th>
<th class="bdr">Title</th>
</tr>
<!-- <xsl:for-each select="hexML/body/press_releases/press_release">-->
<xsl:if test="contains(published/#date, '2009')">
<tr>
<td valign="top">
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="published/#date"/>
</xsl:call-template>
</td>
<td valign="top">
<a href="result-page.aspx?ResultPageURL={location/#href}">
<xsl:value-of select="headline"/>
</a>
</td>
</tr>
</xsl:if>
<!--</xsl:for-each>-->
</table>
</body>
</html>
</xsl:template>
<xsl:template name="FormatDate">
<xsl:param name="DateTime"/>
<xsl:value-of select="substring($DateTime,9,2)"/>-<xsl:value-of select="substring($DateTime,6,2)"/>-<xsl:value-of select="substring($DateTime,1,4)"/><xsl:text> CET</xsl:text>
</xsl:template>
</xsl:stylesheet>
It appears that you need to use an XSLT 2.0 schema aware processor to get built-in support for what you want to do with the xs:dateTime data type and the format-date function.
See http://www.w3.org/TR/xmlschema-2/#dateTime for the requirements for XSLT 2.0 being able to parse the string you have.
The ·lexical space· of dateTime
consists of finite-length sequences of
characters of the form: '-'? yyyy '-'
mm '-' dd 'T' hh ':' mm ':' ss ('.'
s+)? (zzzzzz)?
See http://www.dpawson.co.uk/xsl/rev2/dates.html#d16685e16 for generating output.
format-date( xs:date(
concat(
substring($d,1,4),
'-',
substring($d,7,2),
'-',
substring($d,5,2))),
'[D01] [MNn] [Y0001]')

Resources