Getting error when try to download multiple invoices - odoo-11

I modified invoice report template "account.report_invoice_document".
XML Code:
<template id="report_invoice_document_inherit" inherit_id="account.report_invoice_document">
<xpath expr="//div[#class='page']" position="inside">
<div class="row">
<div class="text-left">
<h4><u>Comments</u></h4>
</div>
<div class="text-justify" style="margin-left:10px;">
<p>Data</p>
</div>
</div>
</xpath>
</template>
No Error display on Terminal when I tried to download multiple invoices.
Invoice Report successfully downloaded when it is download from form view.An error has occurred when multiple report download from an account.invoice tree view
I got an error on odoo.
Error:
Odoo Server Error
Traceback (most recent call last):
File "/home/odoo/Documents/odoo11_community/odoo-11.0/addons/web/controllers/main.py", line 1663, in report_download
response = self.report_routes(reportname, docids=docids, converter='pdf')
File "/home/odoo/Documents/odoo11_community/odoo-11.0/odoo/http.py", line 512, in response_wrap
response = f(*args, **kw)
File "/home/odoo/Documents/odoo11_community/odoo-11.0/addons/web/controllers/main.py", line 1612, in report_routes
pdf = report.with_context(context).render_qweb_pdf(docids, data=data)[0]
File "/home/odoo/Documents/odoo11_community/odoo-11.0/odoo/addons/base/ir/ir_actions_report.py", line 641, in render_qweb_pdf
return self._post_pdf(save_in_attachment, pdf_content=pdf_content, res_ids=html_ids), 'pdf'
File "/home/odoo/Documents/odoo11_community/odoo-11.0/odoo/addons/base/ir/ir_actions_report.py", line 524, in _post_pdf
assert len(outlines_pages) == len(res_ids)
AssertionError

try to replace the line:
<h4><u>Comments</u></h4>
by:
<p><u>Comments</u></p>
The problem is th <h4> tag.
The source code in Odoo 11 (odoo/addons/base/ir/ir_actions_report.py) helps:
# In case of multiple docs, we need to split the pdf according the records.
# To do so, we split the pdf based on outlines computed by wkhtmltopdf.
# An outline is a <h?> html tag found on the document. To retrieve this table,
# we look on the pdf structure using pypdf to compute the outlines_pages that is
# an array like [0, 3, 5] that means a new document start at page 0, 3 and 5.

Related

Odoo 10 - QWeb include barcode in report

I am trying to include a QR barcode in a report.
Doing:
https://www.foo.com/report/barcode/QR/test
Generates a valid barcode in the browser.
But using in a QWeb PDF report template:
<img t-att-src="/report/barcode/QR/test"/>
Does not work:
File "/usr/lib/python2.7/dist-packages/odoo/addons/base/ir/ir_qweb/ir_qweb.py", line 300, in _compile_expr
st = ast.parse(expr.strip(), mode='eval')
File "/usr/lib/python2.7/ast.py", line 37, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 1
/report/barcode/QR/test
^
SyntaxError: invalid syntax
You should write as following :
<img t-att-src="'/report/barcode/QR/test'"/>
In QWeb reports for barcode you have to try this code...
<img t-if="o.barcode" t-att-src="'data:image/png;base64,%s' % o.barcode"/>
Also you can try this :
<img t-att-src="'/report/barcode/QR/test?
type=%s&value=%s&width=%s&height=%s' % ('EAN13', o.ean13, 600, 900)"
style="width:100%;height:100px"/>
Define height and width that you want.
In Q-web Report Include the Barcode, that have only include the image in your module,--->>> module_name-->>static-->>src-->>img--->> images.gif.
Code :
Else :
You can directly get the barcode from the report also.
Hope It will Work for you.
Add this to your report file.
<center style="margin:6px 0;">
<img t-if="o.barcode" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' %('Code128',o.barcode,250,50)"/>
</center>

Unique Key Error when exporting Scrapy data to Elasticsearch

I'm attempting to use the scrapy elasticsearch pipeline (here: https://github.com/knockrentals/scrapy-elasticsearch) to put data into elasticsearch. however i get the following error, i'm aware that it's related to the ELASTICSEARCH_UNIQ_KEY value that is currently set at 'url' but i have no idea what it should be set to.
Similar posts on here recommend solutions that involve creating a field for the unique key but i don't understand what this means.
Here's my error message:
2015-08-05 11:34:40 [scrapy] ERROR: Error processing {'link': [u'http://www.meetup.com/Search-Meetup-Karlsruhe/events/192357732/'],
'title': [u'Suchen in der vernetzten Welt']}
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twisted/internet/defer.py", line 588, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scrapyelasticsearch/scrapyelasticsearch.py", line 70, in process_item
self.index_item(item)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scrapyelasticsearch/scrapyelasticsearch.py", line 52, in index_item
local_id = hashlib.sha1(item[uniq_key]).hexdigest()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scrapy/item.py", line 56, in __getitem__
return self._values[key]
KeyError: 'url'
Similar posts on here recommend solutions that involve creating a
field for the unique key but i don't understand what this means.
Declare a field in your Item with the name you configured in the ELASTICSEARCH_UNIQ_KEY.
import scrapy
class DemoItem(scrapy.Item):
url = scrapy.Field() # ELASTICSEARCH_UNIQ_KEY
class DemoSpider(scrapy.Spider):
name = 'demo'
start_urls = ['http://www.example.com']
def parse(self, response):
demoItem = DemoItem()
demoItem['url'] = response.url
yield demoItem

Accessing portal_registry via plone.app.theming

I'm trying to use a parameter expression in the plone.app.theming theming-controlpanel that gets a value from the portal_registry to use within the rules.xml file of the theme.
The goal is that if a boolean is set in the registry, the theme can allow/disallow certain content.
So my parameter expression (in theming-controlpanel) is
enable_ad_tags = python:context.portal_registry['lw.portal.enableadtags']
There is a corresponding boolean field in the portal_registry.
The rules.xml file has this rule:
<!-- Global Ad Tags -->
<drop css:theme="#globalAdTags" if="not($enable_ad_tags)" />
The problem is that on my local machine i get this error in the console all the time:
c2014-08-08 09:49:19 ERROR plone.transformchain Unexpected error whilst trying to apply transform chain
Traceback (most recent call last):
File "/Users/aaronwilliams/.buildout/eggs/plone.transformchain-1.0.3-py2.7.egg/plone/transformchain/transformer.py", line 48, in __call__
newResult = handler.transformIterable(result, encoding)
File "/Users/aaronwilliams/.buildout/eggs/plone.app.theming-1.1.1-py2.7.egg/plone/app/theming/transform.py", line 179, in transformIterable
params = prepareThemeParameters(findContext(self.request), self.request, parameterExpressions, cache)
File "/Users/aaronwilliams/.buildout/eggs/plone.app.theming-1.1.1-py2.7.egg/plone/app/theming/utils.py", line 630, in prepareThemeParameters
params[name] = quote_param(expression(expressionContext))
File "/Users/aaronwilliams/.buildout/eggs/Zope2-2.13.20-py2.7.egg/Products/PageTemplates/ZRPythonExpr.py", line 48, in __call__
return eval(self._code, vars, {})
File "PythonExpr", line 1, in <expression>
File "/Users/aaronwilliams/.buildout/eggs/AccessControl-3.0.6-py2.7-macosx-10.8-x86_64.egg/AccessControl/ImplPython.py", line 675, in guarded_getattr
v = getattr(inst, name)
AttributeError: 'DirectoryResource' object has no attribute 'portal_registry'
Is there a problem with the pattern I am trying to use here?
Is there a better/safer way to achieve this?
Using portal instead of context works:
enable_ad_tags = python:portal.portal_registry['lw.portal.enableadtags']
IMHO context should also work, or context does not behave like it does, or the naming is wrong.

Remove cell from table

I have created my own Sales / Quotation report caleed sale_order.sxw using OpenOffice Write. From there I generate the sale_order.rml file.
I have two installation of OpenERP, one on Windows and one on Ubuntu.
In OOWriter, I have a 4 columns table that prints out each single order line along with Quantity, "Print this" text and Subtotal.
The third column is printed out only if a specific condition is met, based on the price list name containing "final":
So I expect:
If "final" is not located within the price list
Product A|2|Print this |20
If "final" is located within the price list:
Product A|2|20
To solve this, I have the following code:
(so.partner_id.property_product_pricelist.name.find('final') > 0) and "Print this" or removeParentNode('td')
It works fine from the windows installation.
But when I run the same file from the Ubuntu installation I get an AssertionError message and I can't print out my Sales / Quotation pdf report.
I did some testing specifically with the removeParentNode('td') and the error seems to come from there, but I can't work out why as it works under windows!
Here is the log from the Ubuntu server:
2013-04-15 13:09:07,822 1621 ERROR ? openerp.service.web_services: Exception:
Traceback (most recent call last):
File "/home/download/openerp-6.1-20121008-233119/openerp/service/web_services.py", line 727, in go
(result, format) = obj.create(cr, uid, ids, datas, context)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/report_sxw.py", line 442, in create
fnct_ret = fnct(cr, uid, ids, data, report_xml, context)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/report_sxw.py", line 511, in create_source_pdf
return self.create_single_pdf(cr, uid, ids, data, report_xml, context)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/report_sxw.py", line 533, in create_single_pdf
pdf = create_doc(etree.tostring(processed_rml),rml_parser.localcontext,logo,title.encode('utf8'))
File "/home/download/openerp-6.1-20121008-233119/openerp/report/interface.py", line 207, in create_pdf
obj.render()
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/render.py", line 59, in render
self._result = self._render()
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml.py", line 41, in _render
return rml2pdf.parseNode(self.rml, self.localcontext, images=self.bin_datas, path=self.path,title=self.title)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 1007, in parseNode
r.render(fp)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 314, in render
pt_obj.render(el)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 983, in render
fis += r.render(node_story)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 877, in render
return process_story(node_story)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 870, in process_story
flow = self._flowable(node)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 834, in _flowable
return self.render(node)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 877, in render
return process_story(node_story)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 870, in process_story
flow = self._flowable(node)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 793, in _flowable
return self._table(node)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 697, in _table
assert length == len(node.get('colWidths').split(','))
AssertionError
2013-04-15 13:09:07,951 1621 ERROR ? openerp.netsvc:
(<type 'exceptions.AssertionError'>, AssertionError(), <traceback object at 0x7ff558e54b00>)
2013-04-15 13:09:07,953 1621 INFO ? werkzeug: 192.168.2.4 - - [15/Apr/2013 13:09:07] "POST /web/report HTTP/1.1" 500 -
I did a comparison between the trml2pdf.py files used on the server and the one used by windows and they are identical.
This is because of un matching original column.

How to use rake to insert/replace html section in each file?

I'm using rake to create a Table of contents from a bunch of static HTML files.
The question is how do I insert it into all files from within rake?
I have a <ul id="toc"> in each file to aim for. The entire content of that I want to replace.
I was thinking about using Nokogiri or similar to parse the document and replace the DOM node ul#toc. However, I don't like the idea that I have to write the parser's DOM to the HTML file. What if it changes my layouts/indents etc.??
Any thoughts/ideas? Or perhaps links to working examples?
Could you rework the files to .rhtml, where
<ul id="toc">
is replaced with an erb directive, such as
<%= get_toc() %>
where get_toc() is defined in some library module. Write the transformed files as .html (to another directory if you like) and you're in business and the process is repeatable.
Or, come to that, why not just use gsub? Something like:
File.open(out_filename,'w+') do |output_file|
output_file.puts File.read(filename).gsub(/\<ul id="toc"\>/, get_toc())
end
I ended up with an idea similar to what Mike Woodhouse suggested. Only not using erb templates (as I wanted the source files to be freely editable also by non ruby-lovers)
def update_toc(filename)
raise "FATAL: Requires self.toc= ... before replacing TOC in files!" if #toc.nil?
content = File.read(filename)
content.gsub(/<h2 class="toc">.+?<\/ul>/, #toc)
end
def replace_toc_in_all_files
#file_names.each do |name|
content = update_toc(name)
File.open(name, "w") do |io|
io.write content
end
end
end
You can manipulate the document directly and save the resulting output. If you confine your manipulations to a particular element, you won't alter the overall structure and should be fine.
A library like Nokogiri or Hpricot will only adjust your document if it's malformed. I know that Hpricot can be coached to have a more relaxed parsing method, or can operate in a more strict XML/XHTML manner.
Simple example:
require 'rubygems'
require 'hpricot'
document = <<END
<html>
<body>
<ul id="tag">
</ul>
<h1 class="indexed">Item 1</h1>
<h2 class="indexed">Item 1.1</h2>
<h1 class="indexed">Item 2</h1>
<h2 class="indexed">Item 2.1</h2>
<h2 class="indexed">Item 2.2</h2>
<h1>Remarks</h1>
<!-- Test Comment -->
</body>
</html>
END
parsed = Hpricot(document)
ul_tag = (parsed / 'ul#tag').first
sections = (parsed / '.indexed')
ul_tag.inner_html = sections.collect { |i| "<li>#{i.inner_html}</li>" }.to_s
puts parsed.to_html
This will yield:
<html>
<body>
<ul id="tag"><li>Item 1</li><li>Item 1.1</li><li>Item 2</li><li>Item 2.1</li><li>Item 2.2</li></ul>
<h1 class="indexed">Item 1</h1>
<h2 class="indexed">Item 1.1</h2>
<h1 class="indexed">Item 2</h1>
<h2 class="indexed">Item 2.1</h2>
<h2 class="indexed">Item 2.2</h2>
<h1>Remarks</h1>
<!-- Test Comment -->
</body>
</html>

Resources