Odoo 10 - QWeb include barcode in report - odoo-10

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>

Related

Cypress file upload

I have a "problem"
I'm trying to upload a file in my cypress test, however my test runs with sucess but it doesn't upload.
I using the library cypress-file-upload;
my code:
const filePath = 'teste.pdf'
cy.get(':nth-child(1) > .backgroundColor > :nth-child(2) > :nth-child(1) > .col-auto > .input-group.mb-0 > .custom-file > .row > .form-group > .input-group > .input-group-text').attachFile(filePath)
result:
enter image description here
my html/css:
enter image description here
button:
enter image description here
ps: sorry for my bad english
I'm trying many css selector until xpath, but doesn't sucess
I think your target element in this case should be the input one.
Make sure teste.pdf is located at fixtures folder and try something like:
const filePath = 'teste.pdf'
cy.get('.custom-file-input.form-control-sm.file-input').attachFile(filePath)

Parse quoted-printable encoding content from .mht file

I am trying to get all the images from .mht file by using Nokogiri gem. But since the .mht file has quoted-printable encoding, all the images that I received, has weird characters in it:
<img alt='3D"AFC-Logo' src="3D%22https://upload.=" width='3D"75"' height='3D"75"'>
<img src="3D%22https://en.wikipedia.org/static/images/footer/wikimedia-butto=" width='3D"88"' height='3D"31"' alt='3D"Wikimedia'>
<img src="3D%22https://en.wikipedia.org/static/images/footer/poweredby_mediawiki_8=" alt='3D"Powered' width='3D"88"' height='3D"31"'>
This is the link to that .mht file: https://drive.google.com/file/d/1DtbgrFyCEcggAk1nqpZSluNhRt-k3t95/view?usp=sharing
And below is the code that I am using to get all the images from the .mht file:
html = File.open("1646037951.mht").read
image_links = get_image_links(html)
def get_image_links(html)
html_doc = Nokogiri::HTML(html)
nodes = html_doc.xpath("//img[#src]")
raise "No <img .../> tags!" if nodes.empty?
nodes.inject([]) do |uris, node|
puts node.to_s
uris << node.attr('src').strip
end.uniq
end
I have tried to parse it by using .unpack('M').first but it's still not working as it just returns the same result as above.
Or maybe Rails have something for this?

How to test if an alert message is showing what I wanted it to show using Cypress?

I have password reset page I'd like to perform some tests on. If my current password won't match with my typed current password area it shows a "Password don't match" alert. Here is my alert:
<p-message *ngIf="error" severity="error" id="alert-danger" class="alert alert-danger" text="{{'password.messages.error' | translate}}" >
<ng-template pTemplate>
<div jhiTranslate="password.messages.error" ></div>
</ng-template>
</p-message>
What I've tried so far:
cy.get('[severity="error"] > .p-inline-message > .p-inline-message-text')
.should("have.text","password.messages.error")
But I get an error in cypress saying "expected password.messages.error but the text was Passwords don't match!. Which is understandable it takes directly whatever text was inside my element. Then I've tried:
cy.get('[severity="error"] > .p-inline-message > .p-inline-message-text')
.invoke('attr','jhiTranslate')
.should('eq','password.messages.error')
this gives me "expected undefined to equal password.messages.error"
What I'm doing wrong and what else should I try here?
Just change the text Cypress is checking,
cy.get('[severity="error"] > .p-inline-message > .p-inline-message-text')
.should("have.text", "Passwords don't match!")
The HTML you show above is the source code, but AngularJS has looked up the variable password.messages.error and output the string contained in that variable.
It then removes jhiTranslate from the element, so you cannot test it at runtime (in the browser).
You can see what the runtime HTML is by right-clicking on an element and inspecting it in the dev-tools.
You can do something like:
cy.get('p-message#alert-danger').within(() => {
cy.get('div').should('have.attr', 'jhiTranslate', 'password.messages.error')
})

Getting error when try to download multiple invoices

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.

Replace image src in vml markup with globally available images using Nokogiri

Is it possible to find outlook specific markup via Capybara/Nokogiri ?
Given the following markup (erb <% %> tags are processed into regular HTML)
...
<div>
<!--[if gte mso 9]>
<v:rect
xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false"
style="width:<%= card_width %>px;height:<%= card_header_height %>px;"
>
<v:fill type="tile"
src="<%= avatar_background_url.split('?')[0] %>"
color="<%= background_color %>" />
<v:textbox inset="0,0,0,0">
<![endif]-->
<div>
How can I get the list of <v:fill ../> tags ? (or eventually how can I get the whole comment if finding the tag inside a conditional comment is a problem)
I have tried the following
doc.xpath('//v:fill')
*** Nokogiri::XML::XPath::SyntaxError Exception: ERROR: Undefined namespace prefix: //v:fill
DO I need to somehow register the vml namespace ?
EDIT - following #ThomasWalpole approach
doc.xpath('//comment()').each do |comment_node|
vml_node_match = /<v\:fill.*src=\"(?<url>http\:[^"]*)"[^>]*\/>/.match(comment_node)
if vml_node_match
original_image_uri = URI.parse(vml_node_match['url'])
vml_tag = vml_node_match[0]
handle_vml_image_replacement(original_image_uri, comment_node, vml_tag)
end
My handle_vml_image_replacement then ends up calling the following replace_comment_image_src
def self.replace_comment_image_src(node:, comment:, old_url:, new_url:)
new_url = new_url.split('?').first # VML does not support URL with query params
puts "Replacing comment src URL in #{comment} by #{new_url}"
node.content = node.content.gsub(old_url, new_url)
end
But then it feels like the comment is actually no longer a "comment" and I can sometimes see the HTML as if it was escaped... I am most likely using the wrong method to change the comment text with Nokogiri ?
Here's the final code that I used for my email interceptor, thanks to #Thomas Walpole and #sschmeck for help along the way.
My goal was to replace images (linking to localhost) in VML markup with globally available images for testing with services like MOA or Litmus
doc.xpath('//comment()').each do |comment_node|
# Note : cannot capture beginning of tag, since it might span across several lines
src_attr_match = /.*src=\"(?<url>http\:[^"]*)"[^>]*\/>/.match(comment_node)
next unless src_attr_match
original_image_uri = URI.parse(src_attr_match['url'])
handle_comment_image_replacement(original_image_uri, comment_node)
end
WHich is later calling (after picking an url replacement strategy depending on source image type) :
def self.replace_comment_image_src(node:, old_url:, new_url:)
new_url = new_url.split('?').first
node.native_content = node.content.gsub(old_url, new_url)
end

Resources